procedure TMain.Button1Click(Sender: TObject);
var
aSheet: variant;
begin
ExcelApplication1.Connect;
ExcelApplication1.Visible[0] := true; //False;//EXCEL不可见,看不到你的调用.
ExcelApplication1.Workbooks.Add(xlWBATWorkSheet, 0); //新增一个ASHEET.
aSheet := ExcelApplication1.Worksheets.Item[1];
aSheet.Range['A1', 'E10'].Value := '=TRUNC(RAND()*10)';
aSheet.Range['A1', 'E10'].Font.Name := 'Courier New';
aSheet.Cells[3, 3].Value := '=Sum(A1:B1)'; //求和,公式就可以照着写
aSheet.Columns[1].HorizontalAlignment := xlLeft; //设置该栏居左
aSheet.Columns[1].columnWidth := 9.00; //设置宽度
aSheet.Columns[2].columnWidth := 6.88;
aSheet.Columns[2].HorizontalAlignment := xlCenter;
aSheet.Rows[2].Insert;
// aSheet.Range['A1', 'B2'].MergeCells := True; //设置合并
// aSheet.SaveAs(SaveDialog1.FileName);//保存
// aSheet.Application.Quit;//退出
end;