Fórum exportar dados delphi/excel #426587
18/10/2012
0
sendo que tem os mesmos componentes e a mesma quantidade de forms.
Var
planilha : variant;
i, linha : Integer;
valorcampo : String;
begin
planilha := CreateoleObject('Excel.Application');
planilha.WorkBooks.Add(1);
planilha.caption := 'Exportando dados do dbGrid para o Excel';
planilha.visible := True;
linha := -1;
if not Query1.IsEmpty then
for i := 0 to Query1.FieldCount - 1 do
begin
if Query1.Fields[i].FieldName <> 'nome_do_campo' then
planilha.cells[1,i+1] := Query1.Fields[i].FieldName;
end;
Query1.First;
while not Query1.Eof do
begin
Inc(linha);
for i := 0 to Query1.FieldCount -1 do
begin
if Query1.Fields[i].FieldName <> 'nome_do_campo' then
planilha.cells[linha + 2,i+1] := Query1.Fields[i].AsString;
end;
Query1.Next;
end;
planilha.columns.Autofit;
Voltar ao topo
Paulo
Curtir tópico
+ 0Posts
18/10/2012
Gilvanio Gonçalves
sendo que tem os mesmos componentes e a mesma quantidade de forms.
Var
planilha : variant;
i, linha : Integer;
valorcampo : String;
begin
planilha := CreateoleObject('Excel.Application');
planilha.WorkBooks.Add(1);
planilha.caption := 'Exportando dados do dbGrid para o Excel';
planilha.visible := True;
linha := -1;
if not Query1.IsEmpty then
for i := 0 to Query1.FieldCount - 1 do
begin
if Query1.Fields[i].FieldName <> 'nome_do_campo' then
planilha.cells[1,i+1] := Query1.Fields[i].FieldName;
end;
Query1.First;
while not Query1.Eof do
begin
Inc(linha);
for i := 0 to Query1.FieldCount -1 do
begin
if Query1.Fields[i].FieldName <> 'nome_do_campo' then
planilha.cells[linha + 2,i+1] := Query1.Fields[i].AsString;
end;
Query1.Next;
end;
planilha.columns.Autofit;
Voltar ao topo
Fiz um teste aqui com o seu codigo e carregou normal para a planilha?
qual erro que esta dando?
vc declarou na uses o ComObj?
Gostei + 0
18/10/2012
Gilvanio Gonçalves
Gostei + 0
19/10/2012
Alisson Santos
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)