P
pllink_qyd
Unregistered / Unconfirmed
GUEST, unregistred user!
數據庫導入excel問題:(或者誰提供一段正確的代碼阿。。感謝ING…)
請問我該引用的都引用了。。為什麼還一直提示我createoleobject沒定義。。一直停留在那行出錯。。
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, Excel2000, OleServer, Buttons, DB, ADODB,comobj;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ExcelID:Variant;
I:Integer;
begin
ADOQuery1.close;
ADOQuery1.sql.add('select * from Product where Pro_time>='''+Edit1.text+''' and Pro_time<='''+Edit2.text+''' ');
ADOQuery1.open;
if ADOQuery1.recordcount<>0 then
begin
if SD.Execute then
begin
try
ExcelID := Application.createoleobject('Excel.Application');
Except
Application.MessageBox('你的計算机可能沒有安裝EXCEL','提示',MB_OK+MB_ICONERROR);
exit;
end;
ExcelID.workBooks.add;
for I:=0 to ADOQuery1.recordcount do
begin
ExcelID.activesheet.Range['A'+IntToStr(I+1)].Value:=ADOQuery1.FieldByName('pro_time').Asstring;
ExcelID.ActiveSheet.Range['B'+IntToStr(I+1)].Value:=ADOQuery1.FieldByName('memo').Asstring;
ADOQuery1.Next;
end;
ExcelID.ActiveWorkbook.SaveAs(SD.FileName);
ExcelID.workBooks.close;
ExcelID.Quit;
Application.Message('成功','提示',MB_OK);
end;
end;
end.
請問我該引用的都引用了。。為什麼還一直提示我createoleobject沒定義。。一直停留在那行出錯。。
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, Excel2000, OleServer, Buttons, DB, ADODB,comobj;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ExcelID:Variant;
I:Integer;
begin
ADOQuery1.close;
ADOQuery1.sql.add('select * from Product where Pro_time>='''+Edit1.text+''' and Pro_time<='''+Edit2.text+''' ');
ADOQuery1.open;
if ADOQuery1.recordcount<>0 then
begin
if SD.Execute then
begin
try
ExcelID := Application.createoleobject('Excel.Application');
Except
Application.MessageBox('你的計算机可能沒有安裝EXCEL','提示',MB_OK+MB_ICONERROR);
exit;
end;
ExcelID.workBooks.add;
for I:=0 to ADOQuery1.recordcount do
begin
ExcelID.activesheet.Range['A'+IntToStr(I+1)].Value:=ADOQuery1.FieldByName('pro_time').Asstring;
ExcelID.ActiveSheet.Range['B'+IntToStr(I+1)].Value:=ADOQuery1.FieldByName('memo').Asstring;
ADOQuery1.Next;
end;
ExcelID.ActiveWorkbook.SaveAs(SD.FileName);
ExcelID.workBooks.close;
ExcelID.Quit;
Application.Message('成功','提示',MB_OK);
end;
end;
end.