procedure LeadExcel(adbGrid: TDBGridEH); stdcall; export //导出数据
var
j, k, col: integer;
sheet, exele: variant;
begin
with adbGrid.DataSource.DataSet do
if not Active or IsEmpty then Exit;
try
exele := CreateOleObject('Excel.Application');
except
MessageBox(adbGrid.handle, PChar('你使用的系统没有装Excel!'), '提示', MB_OK + MB_ICONSTOP);
exit;
end;
exele.Workbooks.Add;
exele.Worksheets[1].Name := 'sheet1';
sheet := exele.Workbooks[1].Worksheets['sheet1'];
exele.WorkSheets[1].Activate;
sheet.Cells[1, 5].Value := '查询数据表';
col := 0;
for j := 0 to adbGrid.fieldcount - 1 do //生成表头 dbegStat是TDBGrid
begin
if adbGrid.Columns[j].Visible then
begin
sheet.Cells[2, col + 1].Value := adbGrid.Columns[j].Title.Caption;
inc(col);
end;
end;
k := 3; //从Excel表的第5行开始添加数据。
//开始导出数据
with adbGrid.DataSource.DataSet do
begin
if not IsEmpty then
begin
first;
while not Eof do
begin
col := 0;
for j := 0 to adbGrid.Columns.Count - 1 do
if (adbGrid.Columns[j].Visible) and (adbGrid.Columns[j].Field <> nil) then
begin
if adbGrid.Columns[j].Field.DataType in [ftString] then
sheet.Cells[k, col + 1].Value := '''' + adbGrid.Columns[j].Field.AsString
else
sheet.Cells[k, col + 1].Value := adbGrid.Columns[j].Field.AsString;
inc(col);
end;
inc(k);
next;
end;
end;
exele.visible := true;
end;
end;这个过程,在程序中,不会出错,
可是放在DLL中,可以调用(用这种方法调用procedure LeadExcel(adbGrid: TDBGridEh); stdcall; external 'PPublicFunction.dll';)。但在关闭程序时,出错了。
出错信息为:
raised too many consecutive exceptions:'access violation at Ox00r21f3f':read of address Ox012058e8.Process Stopped.请问为什么,如何解决。谢谢!
var
j, k, col: integer;
sheet, exele: variant;
begin
with adbGrid.DataSource.DataSet do
if not Active or IsEmpty then Exit;
try
exele := CreateOleObject('Excel.Application');
except
MessageBox(adbGrid.handle, PChar('你使用的系统没有装Excel!'), '提示', MB_OK + MB_ICONSTOP);
exit;
end;
exele.Workbooks.Add;
exele.Worksheets[1].Name := 'sheet1';
sheet := exele.Workbooks[1].Worksheets['sheet1'];
exele.WorkSheets[1].Activate;
sheet.Cells[1, 5].Value := '查询数据表';
col := 0;
for j := 0 to adbGrid.fieldcount - 1 do //生成表头 dbegStat是TDBGrid
begin
if adbGrid.Columns[j].Visible then
begin
sheet.Cells[2, col + 1].Value := adbGrid.Columns[j].Title.Caption;
inc(col);
end;
end;
k := 3; //从Excel表的第5行开始添加数据。
//开始导出数据
with adbGrid.DataSource.DataSet do
begin
if not IsEmpty then
begin
first;
while not Eof do
begin
col := 0;
for j := 0 to adbGrid.Columns.Count - 1 do
if (adbGrid.Columns[j].Visible) and (adbGrid.Columns[j].Field <> nil) then
begin
if adbGrid.Columns[j].Field.DataType in [ftString] then
sheet.Cells[k, col + 1].Value := '''' + adbGrid.Columns[j].Field.AsString
else
sheet.Cells[k, col + 1].Value := adbGrid.Columns[j].Field.AsString;
inc(col);
end;
inc(k);
next;
end;
end;
exele.visible := true;
end;
end;这个过程,在程序中,不会出错,
可是放在DLL中,可以调用(用这种方法调用procedure LeadExcel(adbGrid: TDBGridEh); stdcall; external 'PPublicFunction.dll';)。但在关闭程序时,出错了。
出错信息为:
raised too many consecutive exceptions:'access violation at Ox00r21f3f':read of address Ox012058e8.Process Stopped.请问为什么,如何解决。谢谢!
解决方案 »
- 定义了个const类型可是超过了255个字符,怎么办?
- 有了解杭州恒生电子的吗
- 远程服务器的的scktsrvr.exe已运行了.可是我为什么不能连接.请高手指教.
- 谁还有des或者3des的源码?
- Rave主从表
- delphi中有什么简单制作动画得办法?
- 有关在STINGRID中更改颜色的问题
- cxgrid的create问题
- 请问为什么运行动画时如果timer设置较小时出现屏幕闪烁情况?
- 怎样得到网上邻居里的信息
- 怎样同时执行多段SQL语句?-----挺有难度!!!
- 有奖竞猜 有个叫 No1os_sinox 人,狂发答复贬低windows和linux,抬高自己,大家认为这个人是sinox自己人还是仇人?
exele:=Unassigned;
sheet.Cells[k, col + 1].Value := adbGrid.Columns[j].Field.AsString;
如如改成
sheet.Cells[k, col + 1].Value := 'aaa';
就不会了。
你试试把接口改了看看。
或
ExcelWksheet.Cells[j,i]:=DBGrid1.Fields[i-1].AsString
但还不知为什么。