W
wglifs
Unregistered / Unconfirmed
GUEST, unregistred user!
我用两种方法操作Excel,都遇到了问题:
第一种:使用控件的源码如下
try
ExcelApplication1:=TExcelApplication.Create(ExcelApplication1);
ExcelWorksheet1:=TExcelWorksheet.Create(ExcelApplication1);
ExcelWorkbook1:= TExcelWorkbook.Create(ExcelWorksheet1);
ExcelApplication1.Connect;
except
application.MessageBox('Excel没有安装!','提示',64);
screen.Cursor:= crDefault;
Abort;
end;
try
ExcelApplication1.Workbooks.Add('Model.xlt',0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
ExcelWorksheet1.Cells.Item[1,2]:='123456;
finally
ExcelWorksheet1.SaveAs('123');
ExcelApplication1.Workbooks.Close(0);
ExcelWorkbook1.Free;
ExcelWorkbook1:= nil;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Destroy;
end;
有安装过Office2003和Office2000,都会出现同样的提示:Interface not supported
第二种:使用ComObj,代码如下
try
xlApp := CreateOleObject('Excel.Application');
except
application.MessageBox('Excel没有安装!','提示',64);
screen.Cursor:= crDefault;
Abort;
end;
try
xlApp.WorkBooks.Add;
xlApp.WorkBooks.Open('Model.xls');
xlApp.Cells[1,2].Value:='123456';
finally
xlApp.SaveAs('123.xls');
xlApp.WorkBooks.Close;
xlApp.Quit;
end;
会出现错误提示:Method 'saveas' not supported by automation object.
我是想调出一个模版,然后再将数据导入,哪们大侠有这方面的示例程序吗?
第一种:使用控件的源码如下
try
ExcelApplication1:=TExcelApplication.Create(ExcelApplication1);
ExcelWorksheet1:=TExcelWorksheet.Create(ExcelApplication1);
ExcelWorkbook1:= TExcelWorkbook.Create(ExcelWorksheet1);
ExcelApplication1.Connect;
except
application.MessageBox('Excel没有安装!','提示',64);
screen.Cursor:= crDefault;
Abort;
end;
try
ExcelApplication1.Workbooks.Add('Model.xlt',0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
ExcelWorksheet1.Cells.Item[1,2]:='123456;
finally
ExcelWorksheet1.SaveAs('123');
ExcelApplication1.Workbooks.Close(0);
ExcelWorkbook1.Free;
ExcelWorkbook1:= nil;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Destroy;
end;
有安装过Office2003和Office2000,都会出现同样的提示:Interface not supported
第二种:使用ComObj,代码如下
try
xlApp := CreateOleObject('Excel.Application');
except
application.MessageBox('Excel没有安装!','提示',64);
screen.Cursor:= crDefault;
Abort;
end;
try
xlApp.WorkBooks.Add;
xlApp.WorkBooks.Open('Model.xls');
xlApp.Cells[1,2].Value:='123456';
finally
xlApp.SaveAs('123.xls');
xlApp.WorkBooks.Close;
xlApp.Quit;
end;
会出现错误提示:Method 'saveas' not supported by automation object.
我是想调出一个模版,然后再将数据导入,哪们大侠有这方面的示例程序吗?