创建一个FORM,上面加一个按钮Button1, 保存为MainFormExcel,然后将Unit MainFormExcel用以下程序替代:运行后再c:根目录下生成一个text.xls文件。
unit MainFormExcel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
ComObj;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
V: Variant ;
begin
V := CreateOleObject('Excel.Application');
v.Workbooks.Add;
v.cells[1.1].value := 111;
v.ActiveWorkbook.SaveAs('c:/test.xls');
v.Workbooks.Close;
end;
end.