Y
ysp_1984
Unregistered / Unconfirmed
GUEST, unregistred user!
用下面的代码,将数据库内容导出到EXCEL 中时出现错误,错误为"没有注册类别".是什么意思啊?
procedure DataToExcel(TbOrQuery:TCustomADODataset;GridCtrl:TDBGrid );
var
SaveFn:String;
SaveDialog1: TSaveDialog;
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
ACount,i:Integer;
low,row:Integer;
begin
SaveDialog1:=TSaveDialog.Create(Application.Owner);
SaveDialog1.Filter:='*.Xls';
if Not SaveDialog1.Execute then SaveDialog1.Execute ;
SaveFn:=SaveDialog1.FileName ;
if SaveFn='' then begin messagedlg('請輸入文件名!',mtinformation,[mbok],0);
abort end;
low:=2;
ACount:=GridCtrl.FieldCount ;
ExcelApplication1:=TExcelApplication.Create(Application.Owner);
ExcelWorksheet1:=TExcelWorksheet.Create(Application.Owner );
ExcelWorkbook1:=TExcelWorkbook.Create(Application.Owner );
try
ExcelApplication1.Connect ;
except
MessageDlg('請確定是否正確安裝Excel2000?',mterror,[mbok],0);
abort;
end;
ExcelApplication1.Visible[0]:=false;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(null,0) );
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
for i:=1 to ACount do
ExcelWorksheet1.Cells.Item[1,i]:=GridCtrl.Columns[i-1].Title.Caption ;
TbOrQuery.First ;
while not TbOrQuery.Eof do
begin
for row:=1 to ACount do begin
ExcelWorksheet1.Cells.Item[low,row].NumberFormatLocal:='@';
ExcelWorksheet1.Cells.Item[low,row]:=TbOrQuery.Fields[row-1].Value ;
end;
low:=low+1;
TbOrQuery.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveFn+'.xls');
ExcelWOrkBook1.Close(False);
ExcelWorksheet1.Disconnect ;
ExcelWorkbook1.Disconnect ;
ExcelApplication1.Disconnect;
ExcelWOrkBook1.Close;
ExcelApplication1.Quit;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
ExcelApplication1.Free ;
end;
procedure DataToExcel(TbOrQuery:TCustomADODataset;GridCtrl:TDBGrid );
var
SaveFn:String;
SaveDialog1: TSaveDialog;
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
ACount,i:Integer;
low,row:Integer;
begin
SaveDialog1:=TSaveDialog.Create(Application.Owner);
SaveDialog1.Filter:='*.Xls';
if Not SaveDialog1.Execute then SaveDialog1.Execute ;
SaveFn:=SaveDialog1.FileName ;
if SaveFn='' then begin messagedlg('請輸入文件名!',mtinformation,[mbok],0);
abort end;
low:=2;
ACount:=GridCtrl.FieldCount ;
ExcelApplication1:=TExcelApplication.Create(Application.Owner);
ExcelWorksheet1:=TExcelWorksheet.Create(Application.Owner );
ExcelWorkbook1:=TExcelWorkbook.Create(Application.Owner );
try
ExcelApplication1.Connect ;
except
MessageDlg('請確定是否正確安裝Excel2000?',mterror,[mbok],0);
abort;
end;
ExcelApplication1.Visible[0]:=false;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(null,0) );
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
for i:=1 to ACount do
ExcelWorksheet1.Cells.Item[1,i]:=GridCtrl.Columns[i-1].Title.Caption ;
TbOrQuery.First ;
while not TbOrQuery.Eof do
begin
for row:=1 to ACount do begin
ExcelWorksheet1.Cells.Item[low,row].NumberFormatLocal:='@';
ExcelWorksheet1.Cells.Item[low,row]:=TbOrQuery.Fields[row-1].Value ;
end;
low:=low+1;
TbOrQuery.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveFn+'.xls');
ExcelWOrkBook1.Close(False);
ExcelWorksheet1.Disconnect ;
ExcelWorkbook1.Disconnect ;
ExcelApplication1.Disconnect;
ExcelWOrkBook1.Close;
ExcelApplication1.Quit;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
ExcelApplication1.Free ;
end;