Fórum exportar dados ado #424540
24/09/2012
0
FOI USADO:
ADOCONNECTION
ADOQUERY
DATASOURCE
BD: ACCESS.
lembrando que os codigos abaixo não deram certo
var linha, coluna : integer;
var planilha : variant;
var valorcampo : string;
begin
Query1.CachedUpdates := true;
planilha:= CreateoleObject('Excel.Application');
planilha.WorkBooks.add(1);
planilha.caption := Exportando dados do dbGrid para o Excel';
planilha.visible := true;
Query1.ApplyUpdates;
Query1.First;
for linha := 0 to Query1.RecordCount - 1 do
begin
for coluna := 1 to Query1.FieldCount do
begin
valorcampo := Query1.Fields[coluna - 1].AsString;
planilha.cells[linha + 2,coluna] := valorCampo;
end;
Query1.Next;
end;
for coluna := 1 to Query1.FieldCount do
begin
valorcampo := Query1.Fields[coluna - 1].DisplayLabel;
planilha.cells[1,coluna] := valorcampo;
end;
planilha.columns.Autofit;
Paulo
Curtir tópico
+ 0Posts
24/09/2012
Claudia Nogueira
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
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
planilha.cells[linha + 2,i+1] := Query1.Fields[i].AsString;
end;
Query1.Next;
end;
planilha.columns.Autofit;
Gostei + 0
25/09/2012
Alisson Santos
Gostei + 0
25/09/2012
Paulo
começa exportar, mais dá um erro( OLE error800AC472). Talvez seja a foto?
por favor me ajude.
Gostei + 0
25/09/2012
Paulo
começa exportar, mais dá um erro( OLE error800AC472). Talvez seja a foto?
por favor me ajude.
Tem como eu escolher os campos a serem exportados?
Gostei + 0
25/09/2012
Paulo
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
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
planilha.cells[linha + 2,i+1] := Query1.Fields[i].AsString;
end;
Query1.Next;
end;
planilha.columns.Autofit;
começa exportar, mais dá um erro( OLE error800AC472). Talvez seja a foto?
por favor me ajude.
Tem como eu escolher os campos a serem exportados?
Gostei + 0
25/09/2012
Claudia Nogueira
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
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
planilha.cells[linha + 2,i+1] := Query1.Fields[i].AsString;
end;
Query1.Next;
end;
planilha.columns.Autofit;
começa exportar, mais dá um erro( OLE error800AC472). Talvez seja a foto?
por favor me ajude.
Tem como eu escolher os campos a serem exportados?
Sim pode ser a foto. Você pode fazer um if pra verificar os campos.
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;