我在控件中,我用comobj方式调用excel
var: OleVariant;App := CreateOleObject('Excel.Application');但是此操作无法成功报没有初始化
所以我加入对Com的初始化
OleInitialize(NiL) ;
App := CreateOleObject('Excel.Application');不报错了
但是我使用App对象时仍旧报错“variant method call not supported”
var: OleVariant;App := CreateOleObject('Excel.Application');但是此操作无法成功报没有初始化
所以我加入对Com的初始化
OleInitialize(NiL) ;
App := CreateOleObject('Excel.Application');不报错了
但是我使用App对象时仍旧报错“variant method call not supported”
解决方案 »
- 有没有用delphi搞游戏开发的
- 做个TClientDataSet调查!希望大家参与。
- 一个窗体如何控调用另一个窗体中的过程?
- 又一个字符串分割的问题
- 调用TOleContainer,如何直接显示word界面
- 如何在TQuery里使用append、insert语句
- 一个简单的问题
- 哪位大哥能提供<Delphi2 程序设计大全>的电子版或提供下载地址?在下不胜感激.也欢迎大家看了下文后,踊跃发言.
- 关于locate语句的小问题!
- Delphi难题来了?(真正的高手只在乎技术,不在乎分数)
- 如何运用delphi组合查询做出象pb中的查询,可自由添加查询条件的
- 一个绝难的dbchart作图表问题,这个急啊
eclApp,WorkBook:Variant;
......
try
eclApp:=CreateOleObject('Excel.Application');
WorkBook:=CreateOleobject('Excel.Sheet');
except
ShowMessage('您的机器里未安装Microsoft Excel。');
end; //end of try;
首先新建一Application, 然后在Form1上放置Servers栏控件ExcelApplication1、 ExcelWorkbook1、 ExcelWorksheet1, 再放置控件Table1、 Datasource1、 Dbgrid1、 Button1、 Button2、 Button3、 Button4, 并设置Table1.databasename:=dbdemos, Table1.TableName:=Country.db, Table1.active:=True, Button1.Caption:='SaveToExcel', Button2.caption:='PrintPreview', Button3.caption:='Print', Button4.caption:='CloseExcel'。代码如下: unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes,
Graphics, Controls,
Forms, Dialogs, Excel97, OleServer, Db, DBTables,
Grids, DBGrids, StdCtrls;type
TForm1 = class(TForm)
ExcelApplication1: TExcelApplication;
ExcelWorkbook1: TExcelWorkbook;
ExcelWorksheet1: TExcelWorksheet;
Table1: TTable;
Table1Name: TStringField;
Table1Capital: TStringField;
Table1Continent: TStringField;
Table1Area: TFloatField;
Table1Population: TFloatField;
button1: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.button1Click(Sender: TObject);
var
i,row,column:integer;
begin
Try
ExcelApplication1.Connect;
Except
MessageDlg('Excel may not be installed',
mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
ExcelApplication1.Workbooks.Add(Null,0);
ExcelWorkbook1.ConnectTo
(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo
(ExcelWorkbook1.Worksheets[1] as _Worksheet);
Table1.Open;
row:=1;
While Not(Table1.Eof) do
begin
column:=1;
for i:=1 to Table1.FieldCount do
begin
ExcelWorksheet1.Cells.Item[row,column]:
=Table1.fields[i-1].AsString;
column:=column+1;
end;
Table1.Next;
row:=row+1;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ExcelWorksheet1.PrintPreview;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
ExcelWorksheet1.PrintOut;
end;procedure TForm1.Button4Click(Sender: TObject);
begin
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
end;end.