我用midas开发了一套管理软件,其中把数据集导出excel时,好多机器都没有问题,但有的却不行,导出时提示,interface not support.(接口不支持).
ExcelApplication1、ExcelWorkbook1、ExcelWorksheet1为控件.
请问是不是系统环境是不是缺少文件啊.我的函数是这样写的:
//保存数据到EXCEL
Procedure TSysdb.PubP_DataSaveToExcel(TblName:TdataSet;
Const Tilte:string='';ShowCol:boolean=false);
var i,j,k:integer;
V:array of array of variant;
begin
if not SaveDialog1.Execute then exit;
application.ProcessMessages;
screen.Cursor :=crSQLWait;
try
try
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=false;
ExcelApplication1.Workbooks.Add(NULL,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
except
application.MessageBox('导出出错,请确认EXCEL97或EXCEL2000是否已按装!',CON_PROMPT,MB_OK+MB_ICONSTOP);
end;
with TblName do
begin
disablecontrols;
if not ShowCol then
V := VarArrayCreate([0,RecordCount+5,0,Fields.Count], varVariant)
else
V := VarArrayCreate([0,2*RecordCount+5,0,Fields.Count], varVariant);
i :=2;
j :=0;
k :=0;
V[0][2] := Tilte;
if not ShowCol then //显示单标题
for j:=0 to Fields.Count-1 do
if Fields[j].visible then //取到标题
begin
V[i][k] := Fields[j].displaylabel;
k := k+1;
end;
first;
while not eof do
begin
k:= 0;
if not ShowCol then //显示单标题
i:= i+1
else
i:= i+2;
for j:=0 to Fields.Count-1 do
begin
if Fields[j].visible then
begin
if not ShowCol then //显示单标题
begin
if Fields[j] is TStringField then
V[i][k] := ''''+Fields[j].AsString//取到数据
else
V[i][k] := Fields[j].value;//取到数据
k :=k+1;
end
else
begin
V[i][k] := Fields[j].displaylabel;
if Fields[j] is TStringField then
V[i+1][k] := ''''+Fields[j].AsString//取到数据
else
V[i+1][k] := Fields[j].value;//取到数据
k :=k+1;
end;
end;
end;
next;
end;
if not ShowCol then //显示单标题
begin
if Fields.Count<26 then
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Fields.Count),RecordCount+5])].Value := V
else
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Trunc(Fields.Count/26)-1)+Chr(Ord('A')+(Fields.Count mod 26)),RecordCount+5])].Value := V;
end
else
begin
if Fields.Count<26 then
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Fields.Count),2*RecordCount+5])].Value := V
else
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Trunc(Fields.Count/26)-1)+Chr(Ord('A')+(Fields.Count mod 26)),2*RecordCount+5])].Value := V;
end;
first;
enablecontrols;
end;
ExcelWorksheet1.SaveAs(SaveDialog1.FileName);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
finally
screen.Cursor := crdefault;
end;
end;
ExcelApplication1、ExcelWorkbook1、ExcelWorksheet1为控件.
请问是不是系统环境是不是缺少文件啊.我的函数是这样写的:
//保存数据到EXCEL
Procedure TSysdb.PubP_DataSaveToExcel(TblName:TdataSet;
Const Tilte:string='';ShowCol:boolean=false);
var i,j,k:integer;
V:array of array of variant;
begin
if not SaveDialog1.Execute then exit;
application.ProcessMessages;
screen.Cursor :=crSQLWait;
try
try
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=false;
ExcelApplication1.Workbooks.Add(NULL,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
except
application.MessageBox('导出出错,请确认EXCEL97或EXCEL2000是否已按装!',CON_PROMPT,MB_OK+MB_ICONSTOP);
end;
with TblName do
begin
disablecontrols;
if not ShowCol then
V := VarArrayCreate([0,RecordCount+5,0,Fields.Count], varVariant)
else
V := VarArrayCreate([0,2*RecordCount+5,0,Fields.Count], varVariant);
i :=2;
j :=0;
k :=0;
V[0][2] := Tilte;
if not ShowCol then //显示单标题
for j:=0 to Fields.Count-1 do
if Fields[j].visible then //取到标题
begin
V[i][k] := Fields[j].displaylabel;
k := k+1;
end;
first;
while not eof do
begin
k:= 0;
if not ShowCol then //显示单标题
i:= i+1
else
i:= i+2;
for j:=0 to Fields.Count-1 do
begin
if Fields[j].visible then
begin
if not ShowCol then //显示单标题
begin
if Fields[j] is TStringField then
V[i][k] := ''''+Fields[j].AsString//取到数据
else
V[i][k] := Fields[j].value;//取到数据
k :=k+1;
end
else
begin
V[i][k] := Fields[j].displaylabel;
if Fields[j] is TStringField then
V[i+1][k] := ''''+Fields[j].AsString//取到数据
else
V[i+1][k] := Fields[j].value;//取到数据
k :=k+1;
end;
end;
end;
next;
end;
if not ShowCol then //显示单标题
begin
if Fields.Count<26 then
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Fields.Count),RecordCount+5])].Value := V
else
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Trunc(Fields.Count/26)-1)+Chr(Ord('A')+(Fields.Count mod 26)),RecordCount+5])].Value := V;
end
else
begin
if Fields.Count<26 then
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Fields.Count),2*RecordCount+5])].Value := V
else
ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Trunc(Fields.Count/26)-1)+Chr(Ord('A')+(Fields.Count mod 26)),2*RecordCount+5])].Value := V;
end;
first;
enablecontrols;
end;
ExcelWorksheet1.SaveAs(SaveDialog1.FileName);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
finally
screen.Cursor := crdefault;
end;
end;
我那毕业设计是两层的,将数据倒到excel 中出现excel 启动运行起来,里面却没有倒出的数据,好象我是在连接数据库时将ADOConnection (偶菜,已经记不清是不是这个组件了,或者是datamodule)先free掉,在重新创建。