type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Excelid: Variant;
i: Byte;
begin
Excelid := Null;
try
Excelid:=CreateOleObject( 'Excel.Application' );
except
on Exception do raise exception.Create('无法创建Xls文件,请确认是否安装EXCEL');
end;
Excelid.Visible := True;
Excelid.WorkBooks.Add;
for i:=Ord('A') to Ord('Z') do
Excelid.WorkSheets[1].Cells[1,i-Ord('A')+1].Value := Chr(i);
for i:=Ord('a') to Ord('z') do
Excelid.WorkSheets[2].Cells[1,i-Ord('a')+1].Value := Chr(i);
end;