F
fwcy
Unregistered / Unconfirmed
GUEST, unregistred user!
本人写了一个数据库转EXCEL过程,但执行时在excel中却无法导出数据。
procedure Tfm_bf.BitBtn3Click(Sender: TObject);
var row, i: integer;
begin
if SaveDialog1.Execute then
begin
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet);
ExcelWOrkSheet1.Cells.Item[1, 1] := '银行帐号';
ExcelWOrkSheet1.Cells.Item[1, 2] := '姓名';
ExcelWOrkSheet1.Cells.Item[1, 3] := '工资';
query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from gz ');
Query1.Prepare;
query1.ExecSQL;
row := 2;
while not Query1.Eof do
begin
for i := 0 to Query1.Fields.Count - 1 do
begin
ExcelWOrkSheet1.Cells.Item[row, i + 1] := Query1.Fields.AsString;
end;
row := row + 1;
Query1.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveDialog1.FileName);
ExcelWOrkBook1.Close(false);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
Screen.Cursor := crDefault;
Application.MessageBox('保存完毕!', '消息', 0);
end;
procedure Tfm_bf.BitBtn3Click(Sender: TObject);
var row, i: integer;
begin
if SaveDialog1.Execute then
begin
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet);
ExcelWOrkSheet1.Cells.Item[1, 1] := '银行帐号';
ExcelWOrkSheet1.Cells.Item[1, 2] := '姓名';
ExcelWOrkSheet1.Cells.Item[1, 3] := '工资';
query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from gz ');
Query1.Prepare;
query1.ExecSQL;
row := 2;
while not Query1.Eof do
begin
for i := 0 to Query1.Fields.Count - 1 do
begin
ExcelWOrkSheet1.Cells.Item[row, i + 1] := Query1.Fields.AsString;
end;
row := row + 1;
Query1.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveDialog1.FileName);
ExcelWOrkBook1.Close(false);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
Screen.Cursor := crDefault;
Application.MessageBox('保存完毕!', '消息', 0);
end;