excel导出的问题。 (20分)

  • 主题发起人 主题发起人 寒与凉
  • 开始时间 开始时间
to:寒与凉
use ComObj
 
在uses里面加ComObj了,但还是编译不了
 
to:寒与凉
错误提示是什么。发给我,帮到底了!whhtao@sina.com
 
procedure ExportToExcel(ADOQry: TADOQuery);
var
MyExcel: Variant;
WorkBook: OleVariant;
WorkSheet: OleVariant;
i,j:integer;
begin
try
MyExcel:=CreateOleObject('Excel.Application');
MyExcel.Application.WorkBooks.Add;
MyExcel.Caption:='将数据导入到EXCEL表中';
MyExcel.Application.Visible:=true;
WorkBook:=MyExcel.Application.workbooks[1];
Worksheet:=workbook.worksheets.item[1];

except
Application.MessageBox ('对不起,请确认您是否安装了EXCEL!','提示',MB_OK+MB_ICONINFORMATION);
end;
i:=1;
{
// With worksheet do
// begin
worksheet.cell.Range(worksheet.Cells(1, 1), worksheet.Cells(1, ADOQry.FieldCount)).Font.Name := Font
//'设标题为黑体字
Range(worksheet.Cells(1, 1), worksheet.Cells(1, ADOQry.FieldCount)).Font.Bold = True
//'标题字体加粗
Range(worksheet.Cells(1, 1), worksheet.Cells(Irowcount + 1, Icolcount)).Borders.LineStyle = xlContinuous
//'设表格边框样式
// end;
}
with ADOQry do
begin
for j:=0 to FieldCount-1 do
worksheet.cells[1,j+1]:=Fields[j].FieldName;
First;
while not Eof do
begin
inc(i);
try
for j:=0 to fieldcount-1 do
begin
worksheet.cells[i,j+1].NumberFormatLocal :='@';
worksheet.cells[i,j+1]:=Fields[j].asstring;
end;
Next;
except
Application.MessageBox('EXCEL非法操作!','提示',MB_OK+MB_ICONINFORMATION);
abort;
end;
end;
end;
end;
[:(]
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
842
import
I
I
回复
0
查看
602
import
I
I
回复
0
查看
644
import
I
I
回复
0
查看
330
import
I
I
回复
0
查看
537
import
I
后退
顶部