用Delphi导出数据到Excel时报OLE error 800A03EC错误.

szdhsoft 2009-02-02 02:17:06
用Delphi导出数据到Excel时报OLE error 800A03EC错误.
请问是什么原因啊???
...全文
8616 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
Axsus 2012-08-09
  • 打赏
  • 举报
回复
Delphi中 有没有关于#VALUE, #NULL类似值的处理方法?
zhangxuyu1118 2011-08-01
  • 打赏
  • 举报
回复
mark
dingchuan1983 2009-12-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 p412578 的回复:]
在把数据保存为excel时 会报这个错:OLE Error 800A03EC

一般是由下面几个造成的:

1、缺少这个:use ComObj, 没有引用单元文件;

2、没有创建OLE对象直接引用了,应该这样:MyExcel:=CreateOleObject(Excel.Application);

3、对单元格赋值或赋表达式不正确导致的,或超出excel可识别值的范围;

如:XlsSheet.Cells[i,j].Value := Cells[j,i];  当cell[0,0]就会报这个错,因为excel单元格不是从[0,0]开始的;

[/Quote]

我这里是因为第三点,谢谢了
cui_cn200879 2009-02-09
  • 打赏
  • 举报
回复
我是使用软件的,我的程序是用拼音码调用品名的,一输入字母"C"程序就关闭,用杀毒软件杀了一后,再启动程序,输入"C"程序没退出,就出现这个提示,关了以后,还是按字母"C"退出.
kye_jufei 2009-02-07
  • 打赏
  • 举报
回复

procedure TWKO_PD_REPORT_F.cx_tenOKClick(Sender: TObject);
var
ExcelApp:Variant;
iLoop,i:Integer;
begin
if CheckBox1.Checked then
begin
if (cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表開始日期和結束日期不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end
else
begin
if (cx_planer.Text='')or(cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表條件不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end;

try
Application.ProcessMessages;
ExcelApp:=CreateOleObject('Excel.Application');
except
MessageDlg('對不起,你電腦上沒有安裝Excel,請確認!',mtWarning,[mbOK],0);
Exit;
end;

try
ExcelApp.Caption:='十大機種總報表';
ExcelApp.Visible:=False;
ExcelApp.WorkBooks.Add;
ExcelApp.WorkBooks[1].WorkSheets[1].name:='十大機種總報表';
ExcelApp.WorkBooks[1].WorkSheets[1].Activate;
Screen.Cursor:=crSQLWait;
Application.ProcessMessages;
ExcelApp.cells.Interior.ColorIndex:=2;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='新細明體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells.font.size:=9;
ExcelApp.WorkBooks[1].WorkSheets[1].Columns[4].ColumnWidth:=13.5;
ExcelApp.WorkBooks[1].WorkSheets[1].Columns[5].ColumnWidth:=17.38;
ExcelApp.WorkBooks[1].WorkSheets[1].Columns[9].ColumnWidth:=11.63;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='標楷體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8]:='昆盈十大機種總報表';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.size:=14;
ExcelApp.Range['A1:I1'].MergeCells:=True;
ExcelApp.Range['A1:I1'].HorizontalAlignment:=xlCenter;

ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,1]:='月份';
ExcelApp.Range['A2:A3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,2]:='父階料號';
ExcelApp.Range['B2:B3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,3]:='機種類別';
ExcelApp.Range['C2:C3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,4]:='機種';
ExcelApp.Range['D2:D3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,5]:='日期';
ExcelApp.Range['E2:E3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,6]:='總標準工時';
ExcelApp.Range['F2:F3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,7]:='總投入工時';
ExcelApp.Range['G2:G3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,8]:='總工單量';
ExcelApp.Range['H2:H3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,9]:='總單位標準工時';
ExcelApp.Range['I2:I3'].MergeCells:=True;

Application.ProcessMessages;
for i:=0 to DaysBetween(cx_kssj.Date,cx_jssj.Date) do
begin
lab_age.Caption:='開始導出"'+ FormatDateTime('yyyy/mm/dd',IncDay(cx_kssj.Date,i))+'"的數據';
Application.ProcessMessages;
if CheckBox1.Checked then
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from RES_TENMAX_MODEL where dt between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' Order by dt';
adoq_wko_pdreport.Open;
end
else
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from RES_TENMAX_MODEL where JGLB='''+ VarToStr(Trim(cx_planer.Text))+''' and dt between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' Order by dt';
adoq_wko_pdreport.Open;
end;

pb1.Min:=0;
pb1.Max:=adoq_wko_pdreport.RecordCount;
Application.ProcessMessages;
adoq_wko_pdreport.First;
for iLoop:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+iLoop,1].RowHeight:=14;
ExcelApp.cells[4+iLoop,1].value:=adoq_wko_pdreport.FieldByName('YF').AsString;
ExcelApp.cells[4+iLoop,2].value:=adoq_wko_pdreport.FieldByName('LH').AsString;
ExcelApp.cells[4+iLoop,3].value:=adoq_wko_pdreport.FieldByName('JGLB').AsString;
ExcelApp.cells[4+iLoop,4].value:=adoq_wko_pdreport.FieldByName('MODEL').AsString;
ExcelApp.cells[4+iLoop,5].value:=adoq_wko_pdreport.FieldByName('DT').AsString;
ExcelApp.cells[4+iLoop,6].value:=adoq_wko_pdreport.FieldByName('SUMBZGS').AsString;
ExcelApp.cells[4+iLoop,7].value:=adoq_wko_pdreport.FieldByName('SUMTRGS').AsString;
ExcelApp.cells[4+iLoop,8].value:=adoq_wko_pdreport.FieldByName('SUMQTY').AsString;
ExcelApp.cells[4+iLoop,9].value:=adoq_wko_pdreport.FieldByName('DWBZGS').AsString;
pb1.Position:=pb1.Position+1;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end;
end;

Application.ProcessMessages;
ExcelApp.Range['A1:I'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].HorizontalAlignment:=xlCenter ;
ExcelApp.Range['A1:I'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].Borders.linestyle:=xlContinuous;
Screen.Cursor:=crDefault;
pb1.Position:=0;
ModalResult:=mrOk;
ExcelApp.Visible:=True;
except
ExcelApp.ActiveWorkBook.Saved:=True;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
end;

22222bbb 2009-02-06
  • 打赏
  • 举报
回复
用CXGRID自带的导出就可以了.一条语句搞定.
genispan 2009-02-06
  • 打赏
  • 举报
回复
过来看看
starluck 2009-02-04
  • 打赏
  • 举报
回复


上面的注意修改掉SQL語句和SAVEAS的存儲路徑就可以你用了。 編程愉快
starluck 2009-02-04
  • 打赏
  • 举报
回复



procedure TForm1.Button1Click(Sender: TObject);
var
i,j : integer;
exls,sheet,book: variant;
begin
try
exls:=CreateOleObject('Excel.application');
exls.WorkBooks.Add;
book := exls.workbooks[1];
sheet := exls.worksheets[1];
except
application.MessageBox('请先安装MICROSOFT EXCEL!','提示',mb_ok+mb_iconinformation);
exit;
end;
adoqueryx.SQL.Clear;
adoqueryx.SQL.Add('select * from tests');
adoqueryx.Open;

with adoqueryx do
begin
DisableControls;
for i:=1 to FieldCount do
begin
exls.WorkSheets[1].Cells[1,i].value:=Fields[i-1].DisplayName;
end;
first;
i:=2;
while not eof do
begin
for j:=1 to fieldcount do
begin
exls.WorkSheets[1].Cells[i,j]:=fields[j-1].AsString;
end;
next;
i:=i+1;
end;
EnableControls;
exls.WorkBooks[exls.WorkBooks.Count].SaveAS(ExtractFilePath(ParamStr(0))+'aaaa.xls');
exls.activeWorkBook.saved:=true;
exls.workbooks.close;
exls.quit;
end;
adoqueryx.Close;

end;

szdhsoft 2009-02-03
  • 打赏
  • 举报
回复
以上的三种可能都排除了,还是找不到问题根源,急啊
szdhsoft 2009-02-03
  • 打赏
  • 举报
回复
有这么神奇的事情???
wjbwjb 2009-02-03
  • 打赏
  • 举报
回复
重装EXCEL就可以了
szdhsoft 2009-02-03
  • 打赏
  • 举报
回复
我按P412578 这位仁兄的方法试了还是不行
szdhsoft 2009-02-03
  • 打赏
  • 举报
回复
procedure TForm14.Button1Click(Sender: TObject);
var
i,j : integer;
exls,sheet: variant;
begin
try
exls:=CreateOleObject('Excel.application');
sheet:=createoleobject('excel.sheet');
except
application.MessageBox('请先安装MICROSOFT EXCEL!','提示',mb_ok+mb_iconinformation);
exit;
end;
adoqueryx.SQL.Clear;
adoqueryx.SQL.Add('select id,target_mobile,sendtime from sms_send_history order by id');
adoqueryx.Open;

with adoqueryx do
begin
DisableControls;
for i:=1 to FieldCount do
begin
exls.WorkSheets[1].Cells[1,i].value:=Fields[i-1].DisplayName;
end;
first;
i:=2;
while not eof do
begin
for j:=1 to fieldcount do
begin
exls.WorkSheets[1].Cells[i,j]:=fields[j-1].AsString;
end;
next;
i:=i+1;
end;
EnableControls;
exls.WorkBooks[exls.WorkBooks.Count].SaveAS(ExtractFilePath(ParamStr(0))+'Excel\aaaa.xls');
exls.activeWorkBook.saved:=true;
exls.workbooks.close;
exls.quit;
end;
adoqueryx.Close;
end;
P412578 2009-02-03
  • 打赏
  • 举报
回复
ExcelApp.WorkSheets[1].Cells[i,1].Value 你要这样写,不能对excelapp直接付值
P412578 2009-02-03
  • 打赏
  • 举报
回复
ExcelApp.WorkSheets[1].Cells[i,1].Value 你要这样写,不能对excelapp直接付值
starluck 2009-02-03
  • 打赏
  • 举报
回复
把代码贴出来,这样好解决。看错误应该是建立的时候就出错了。
szdhsoft 2009-02-03
  • 打赏
  • 举报
回复
还是一样的效果,没有用,不知道是什么原因
P412578 2009-02-02
  • 打赏
  • 举报
回复
在把数据保存为excel时 会报这个错:OLE Error 800A03EC

一般是由下面几个造成的:

1、缺少这个:use ComObj, 没有引用单元文件;

2、没有创建OLE对象直接引用了,应该这样:MyExcel:=CreateOleObject(Excel.Application);

3、对单元格赋值或赋表达式不正确导致的,或超出excel可识别值的范围;

如:XlsSheet.Cells[i,j].Value := Cells[j,i]; 当cell[0,0]就会报这个错,因为excel单元格不是从[0,0]开始的;
szdhsoft 2009-02-02
  • 打赏
  • 举报
回复
procedure TForm14.Button1Click(Sender: TObject);
var
i,j : integer;
exls,sheet: variant;
begin
try
exls:=CreateOleObject('Excel.application');
sheet:=createoleobject('excel.sheet');
except
application.MessageBox('请先安装MICROSOFT EXCEL!','提示',mb_ok+mb_iconinformation);
exit;
end;
adoqueryx.SQL.Clear;
adoqueryx.SQL.Add('select id,target_mobile,sendtime from sms_send_history order by id');
adoqueryx.Open;

with adoqueryx do
begin
DisableControls;
for i:=1 to adoqueryx.FieldCount do
begin
exls.Cells[1,i].value:=adoqueryx.Fields[i-1].DisplayName;
end;
first;
i:=2;
while not eof do
begin
for j:=1 to fieldcount do
begin
exls.Cells[i,j]:=fields[j-1].AsString;
end;
next;
i:=i+1;
end;
EnableControls;
exls.WorkBooks[exls.WorkBooks.Count].SaveAS(ExtractFilePath(ParamStr(0))+'Excel\aaaa.xls');
exls.activeWorkBook.saved:=true;
exls.workbooks.close;
exls.quit;
end;
adoqueryx.Close;
end;
加载更多回复(2)
具体内容请参考我的BLOG:http://blog.csdn.net/smallwhiteyt/archive/2009/11/08/4784771.aspx 如果你耐心仔细看完本文,相信以后再遇到导出EXCLE操作的时候你会很顺手觉得SO EASY,主要给新手朋友们看的,老鸟可以直接飘过了,花了一晚上的时间写的很辛苦,如果觉得对你有帮助烦请留言支持一下,我会写更多基础的原创内容来回报大家。 C#导出数据EXCEL表格是个老生常谈的问题了,写这篇文章主要是给和我一样的新手朋友提供两种导出EXCEL的方法并探讨一下导出的效率问题,本文中的代码直接就可用,其中部分代码参考其他的代码并做了修改,抛砖引玉,希望大家一起探讨,如有不对的地方还请大家多多包涵并指出来,我也是个新手,出错也是难免的。 首先先总结下自己知道的导出EXCEL表格的方法,大致有以下几种,有疏漏的请大家补充。 1.数据逐条逐条的写入EXCEL 2.通过OLEDB把EXCEL做为数据源来写 3.通过RANGE范围写入多行多列内存数据EXCEL 4.利用系统剪贴板写入EXCEL 好了,我想这些方法已经足够完成我们要实现的功能了,方法不在多,在精,不是么?以上4中方法都可以实现导出EXCEL,方法1为最基础的方法,意思就是效率可能不是太高,当遇到数据量过大时所要付出的时间也是巨大的,后面3种方法都是第一种的衍生,在第一种方法效率低下的基础上改进的,这里主要就是一个效率问题了,当然如果你数据量都很小,我想4种方法就代码量和复杂程度来说第1种基本方法就可以了,或当你的硬件非常牛逼了,那再差的方法也可以高效的完成也没有探讨的实际意义了,呵呵说远了,本文主要是在不考虑硬件或同等硬件条件下单从软件角度出发探讨较好的解决方案。

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧