Fórum sera que ninguem aqui nesse forum sabe???????????? poxa!!!!! #146221
16/03/2003
0
por favor... se alguma alma generosa puder me ajudar eu agradeceria bastante. eu estou precisando exportar uma query para um arquivo excel. como eu faço isso????????????
olha, eu já vi um programa que faz isso... quando a query eh executada, automaticamente se abre um arquivo excel e os campos retornados pela consulta vão sendo incluidos lá. se eu vi é pq tem como fazer, só que eu não sei como......... alguem sabe??????
poxa, respondam!! pelo menos digam: poxa eu nao sei! ou entao digam outras opções...
valeu :cry:
Anonymous
Curtir tópico
+ 0Posts
16/03/2003
Anonymous
Gostei + 0
16/03/2003
Anonymous
http://www.clubedelphi.com.br/exemplos/TblExcel.zip
baixe e olhe...
espero ter ajudado.
qualquer coisa, mande um e-mail para davicdc@yahoo.com.br
Gostei + 0
16/03/2003
Adilsond
http://www.torry.net/samples/samples/db/ibsb.zip
Ibsb v.1.0 FWS 16 Kb 21.06.01
By Umit Bakar. Open source project. Contains:
Graphic Query design sample (MS Access-like)
LineDDA using Sample
Drawing something (lines, images etc.) over the MDI form´s ClientHandle
Convert the query results to CSV (comma delimited) format
Convert the query results to XLS format
Convert the query results to RTF format
Drag and Drop sample between TCheckListBoxes (Tables).
Gostei + 0
16/03/2003
Adilsond
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20444539.html
Gostei + 0
16/03/2003
Anderson Silva
te aconselho a fazer isso caso noa te ajudem.
Exemplo
codigo;nome;telefone;fax
cada semapador desse faz com que o excel abra uma coluna pra vc
Gostei + 0
16/03/2003
Jeancamila
Na clausula uses, acrescente a unit QRExport
Exportando para HTML:
QuickReport.ExportToFilter(TQRHTMLDocumentFilter.Create(´c:\teste.html´));
Exportando para DOC ou TXT:
QuickReport.ExportToFilter(TQRAsciiExportFilter.Create(´c:\teste.doc´));
Exportando para XLS:
QuickReport.ExportToFilter(TQRXLSFilter.Create(´c:\teste.xls´));
Atenção : Esta dica foi testada utilizando o Delphi 4 com o QuickReport 3.05, pode ser que em outras versões do Delphi ou do QuickReport, possa vir a não funcionar
OBS: A dica não funciona em todas as versões do Quickreport
Dica tirada da 700 dicas de delphi conhecem?
Jean
Gostei + 0
17/03/2003
Mcdir
Olha quanta resposta!!. :D Baum nehnaum?
Todas saum boas ... mas acredito que a sugestaum do Anderson Silva eh a mais tranquila. Definindo, no código, o formato do retorno como ele disse e a abertura da planilha, tah resolvido!!
Caso tenha dificuldade na implementação disso poste aki.
:wink:
Gostei + 0
17/03/2003
Fabio Colli
me manda seu e-mail
Gostei + 0
17/03/2003
Anonymous
vou testar essas dicas! essa do quick report não funciona com a versão 5 do Delphi. Eu já tinha testado!
vcs são 10!!!
brigada!
Gostei + 0
17/03/2003
Anonymous
Gostei + 0
17/03/2003
Aroldo Zanela
Raquel,
Desculpe em não ter respondido antes, mas eu fiz isso há muito tempo e não achava o fontes. Ele faz da forma que mencionou e em seguida aplica um autoformato (perfumaria).
Onde você ler EA, refere-se ao Componente ExcelApplication.
Se enrroscar, mp.
var RangeE: Excel2000.range; // Excel97 qdo for o caso - Não é flexivel I, Linha: Integer; Faixa: String; begin EA.Visible[0] := true; EA.Workbooks.Add(Null,0); RangeE:= EA.ActiveCell; // Montar a primeira linha com o nome das colunas da query. for i := 0 to Query1.FieldCount-1 do begin RangeE.Value:= Query1.Fields[I].DisplayName; RangeE:= RangeE.Next; end; Query1.DisableControls; Query1.First; Linha:= 2; while not Query1.Eof do begin RangeE:= EA.Range [´A´ + IntToStr(Linha), ´A´ + IntToStr(Linha)]; For I := 0 to Query1.FieldCount-1 do begin if I <= 26 then begin // A .. Z Faixa:= Chr( 64 + I ); end else begin // A .. Z [AA .. AZ] Faixa:= ´A´ + Chr( 64 + (I-25) ); end; RangeE.Value:= Query1.Fields[I].Value; RangeE:= RangeE.Next; end; Query1.Next; Inc(Linha); end; Query1.EnableControls; EA.Visible[0] := true; RangeE:= EA.Range[´A1´,Faixa + IntToStr(Linha-1) ]; //Chr(65 + (Query1.FieldCount-1)) + IntToStr(Linha-1)] RangeE.AutoFormat(8,Null,Null,Null,Null,Null,Null); Application.Terminate; end;
Gostei + 0
17/03/2003
Marcos
DeleteFile(´c:\Meus Documentos\Pasta1.xls´);
DmTabelas.´Nome do Banco´.Execute(´SELECT ´nome do campo´
INTO Plan1 IN ´Pasta1.xls´ ´Excel 8.0;´ ´FROM ´Nome da Tabela´ );
excel := CreateOleObject(´Excel.Application´);
excel.visible := true;
docs := excel.workbooks;
doc := docs.open(´c:\Meus Documentos\Pasta1.xls´);
end;
Gostei + 0
25/03/2003
Anonymous
da uma olhada no codigo abaixo
uses
Excel97;
var
FRelatorio: TFRelatorio;
Excel:Variant;
Worksheet:Variant;
HeaderLine,DataLine,H,I,J,k,Done,Detail,VisibleFields:Integer;
Cell,ToCell,strI,QuebraResultado,QuebraLinha,QuebraFonte:String;
procedure TFRelatorio.MovimentoMensalSubprojeto();
begin
try
Excel:=CreateOleObject(´Excel.Application´); ///Open excel
Excel.Visible:=False;
Excel.WorkBooks.Add(-4167);
Excel.WorkBooks[1].Worksheets[1].Name:=´Lançamentos´;
Worksheet:=Excel.Workbooks[1].Worksheets[´Lançamentos´];
Worksheet.PageSetup.LeftMargin := Excel.CentimetersToPoints(0.5);
Worksheet.PageSetup.RightMargin := Excel.CentimetersToPoints(0.5);
Worksheet.PageSetup.TopMargin := Excel.CentimetersToPoints(0.5);
Worksheet.PageSetup.BottomMargin := Excel.CentimetersToPoints(0.5);
Worksheet.PageSetup.PrintHeadings := False;
Worksheet.PageSetup.PrintGridlines := False;
Worksheet.PageSetup.PrintComments := XlPrintNoComments;
Worksheet.PageSetup.CenterHorizontally := True;
Worksheet.PageSetup.CenterVertically := False;
// Orientation = xlLandscape
Worksheet.PageSetup.PaperSize := XlPaperA4;
except
MessageBox(handle,´Can´´t Open Excel´,´Error´,MB_IconError);
Exit;
end;
HeaderLine:=2;
DataLine:=3;
Done:=0;
VisibleFields:=0;
// MasterTable.First; // Put master table at the begining
Screen.Cursor := crHourglass;
// Worksheet.Range[´C1´,´C1´].Value:=ReportTitle;
{headers for master data}
WorkSheet.Cells[1,1].ColumnWidth := 10;
WorkSheet.Cells[1,2].ColumnWidth := 7;
WorkSheet.Cells[1,3].ColumnWidth := 7;
WorkSheet.Cells[1,4].ColumnWidth := 7;
WorkSheet.Cells[1,5].ColumnWidth := 50;
WorkSheet.Cells[1,6].ColumnWidth := 5;
WorkSheet.Cells[1,7].ColumnWidth := 10;
Worksheet.Range[´A1´,´G1´].Merge;
Worksheet.Range[´A1´,´A1´].Value := ´Movimento Financeiro Mensal por Subprojeto´;
WorkSheet.Range[´A1´,´G1´].Font.FontStyle:=´Bold´;
WorkSheet.Range[´A1´,´G1´].Font.Size:= 15;
WorkSheet.Range[´A1´,´A1´].HorizontalAlignment:=XlCenter;
I := I + 2;
Cell := ´A´ + TRIM(IntToStr(I));
Worksheet.Range[´A´+IntToStr(I),´D´+IntToStr(I)].Merge;
Worksheet.Range[Cell,Cell].Value := ´Mês: ´ + cbMes.Text;
Cell := ´D´ + TRIM(IntToStr(I));
Worksheet.Range[Cell,Cell].Value := ´Ano: ´ + sano.Text;
I := I + 1;
Cell := ´A´ + TRIM(IntToStr(I));
Worksheet.Range[Cell,Cell].Value := ´Projeto: ´ + DBLookupComboBox1.Text;
I := I + 1;
Cell := ´A´ + TRIM(IntToStr(I));
Worksheet.Range[Cell,Cell].Value := ´Subprojeto: ´ + DBLookupComboBox2.Text;
with DmRelatorio.QryMovimentoMensalSubprojeto do
begin
while not Eof do
begin
if QuebraFonte <> DmRelatorio.QryMovimentoMensalSubprojetoSiglaFonte.Value then
begin
QuebraFonte := DmRelatorio.QryMovimentoMensalSubprojetoSiglaFonte.Value;
QuebraResultado := DmRelatorio.QryMovimentoMensalSubprojetoNumeroObjetivo.Value +
DmRelatorio.QryMovimentoMensalSubprojetoNumeroResultado.Value;
QuebraLinha := DmRelatorio.QryMovimentoMensalSubprojetoLinhaOrcamentaria.Value;
i := cabecalho(i);
end;
if QuebraResultado <> DmRelatorio.QryMovimentoMensalSubprojetoNumeroObjetivo.Value +
DmRelatorio.QryMovimentoMensalSubprojetoNumeroResultado.Value then
begin
QuebraResultado := DmRelatorio.QryMovimentoMensalSubprojetoNumeroObjetivo.Value +
DmRelatorio.QryMovimentoMensalSubprojetoNumeroResultado.Value;
i := cabecalho(i);
end;
if QuebraLinha <> DmRelatorio.QryMovimentoMensalSubprojetoLinhaOrcamentaria.Value then
begin
QuebraLinha := DmRelatorio.QryMovimentoMensalSubprojetoLinhaOrcamentaria.Value;
i := cabecalho(i);
end;
I := I + 1;
WorkSheet.Range[´A´+IntToStr(I),´D´+IntToStr(I)].HorizontalAlignment:=XlCenter;
WorkSheet.Range[´F´+IntToStr(I),´F´+IntToStr(I)].HorizontalAlignment:=XlCenter;
Worksheet.Range[´A´+IntToStr(I),´A´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoDataPagamento.Value;
Worksheet.Range[´B´+IntToStr(I),´B´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoSiglaDocumento.Value;
Worksheet.Range[´C´+IntToStr(I),´C´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoNumeroDocumento.Value;
Worksheet.Range[´D´+IntToStr(I),´D´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoParcelaDocumento.Value;
Worksheet.Range[´E´+IntToStr(I),´E´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoNomeCompleto.Value;
Worksheet.Range[´F´+IntToStr(I),´F´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoDebitoCredito.Value;
Worksheet.Range[´G´+IntToStr(I),´G´+IntToStr(I)].Value := DmRelatorio.QryMovimentoMensalSubprojetoValorLocalObjetivoResultado.Value;
WorkSheet.Range[´A´+IntToStr(I),´G´+IntToStr(I)].Borders.LineStyle := XlContinuous;
next;
end;
end;
end;
function TFRelatorio.Cabecalho(pI: Integer): Integer;
begin
pI := pI + 2;
Cell := ´A´ + TRIM(IntToStr(pI));
WorkSheet.Range[Cell,Cell].Font.FontStyle:=´Bold´;
Worksheet.Range[Cell,Cell].Value := ´Fonte: ´ + DmRelatorio.QryMovimentoMensalSubprojetoSiglaFonte.Value +
´ ´ + ´Resultado: ´ + DmRelatorio.QryMovimentoMensalSubprojetoNumeroObjetivo.Value + ´.´ +
DmRelatorio.QryMovimentoMensalSubprojetoNumeroResultado.Value +
´ ´ + ´Linha: ´ + DmRelatorio.QryMovimentoMensalSubprojetoLinhaOrcamentaria.Value; ;
pI := pI + 1;
cell := ´A´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´Data´;
cell := ´B´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´Sigla´;
cell := ´C´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´Número´;
cell := ´D´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´Parcela´;
cell := ´E´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´Beneficiário´;
cell := ´F´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´D/C´;
cell := ´G´ + TRIM(IntToStr(pI));
Worksheet.Range[cell,cell].Value := ´Valor R$´;
WorkSheet.Range[´A´+IntToStr(pI),´G´+IntToStr(pI)].Font.FontStyle:=´Bold´;
WorkSheet.Range[´A´+IntToStr(pI),´G´+IntToStr(pI)].HorizontalAlignment:=XlCenter;
WorkSheet.Range[´A´+IntToStr(pI),´G´+IntToStr(pI)].Borders.LineStyle := XlContinuous;
result := pI;
end;
Gostei + 0
25/03/2003
Jeancamila
desculpe não ter respondido novamente pois meu ruindows deu problema e como estudo de 7:00 as 11:00 e trabalho de 12:00 as 23:00 fiquei impossibilitado de reponder.
Porém já usei a resposta que te passei sobre o quick report para exporta no delphi 5 e funcionou.
Não entendi pq não funcionou com vc.
Gostei + 0
25/03/2003
Marcelo
Gente pare de sofrer....
[b:2b3032a8fa]GERA RELATORIOS NO EXCEL[/b:2b3032a8fa]
procedure TForm1.GerarExcel(Consulta:TQuery);
var
coluna, linha: integer;
excel: variant;
valor: string;
begin
try
excel:=CreateOleObject(´Excel.Application´);
excel.Workbooks.add(1);
except
Application.MessageBox (´Versão do Ms-Excel´+
´Incompatível´,´Erro´,MB_OK+MB_ICONEXCLAMATION);
end;
Consulta.First;
try
for linha:=0 to Consulta.RecordCount-1 do
begin
for coluna:=1 to Consulta.FieldCount do
begin
valor:= Consulta.Fields[coluna-1].AsString; excel.cells [linha+2,coluna]:=valor;
end;
Consulta.Next;
end;
for coluna:=1 to Consulta.FieldCount do
begin
valor:= Consulta.Fields[coluna-1].DisplayLabel;
excel.cells[1,coluna]:=valor;
end;
excel.columns.AutoFit;
excel.visible:=true;
except
Application.MessageBox (´Aconteceu um erro desconhecido durante a conversão´+
´da tabela para o Ms-Excel´,´Erro´,MB_OK+MB_ICONEXCLAMATION);
end;
end;
Valeu?
at+...
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)