exportar dados delphi/excel
Eu gostaria de saber pq o codigo abaixo, funciona no delphi 2010 e não funciona no delphi 7?
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
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
Curtidas 0
Respostas
Gilvanio Gonçalves
18/10/2012
Eu gostaria de saber pq o codigo abaixo, funciona no delphi 2010 e não funciona no delphi 7?
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
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
Gilvanio Gonçalves
18/10/2012
esqueci de dizer, usei o Delphi 7.
GOSTEI 0
Alisson Santos
18/10/2012
Amigo conseguiu resolver o seu problema com a orientação do nosso colega??
GOSTEI 0