//导出到excel的代码
procedure WriteExcel(title:string);
var
i, j: integer;
begin
try
ExcelApplication1 := TExcelApplication.Create(Application);
ExcelWorksheet1 := TExcelWorksheet.Create(Application);
ExcelWorkbook1 := TExcelWorkbook.Create(Application);
ExcelApplication1.Connect;
except
Application.Messagebox('Excel 导出失败,请检查是否安装了Excel或注销系统后再运行','错误', MB_ICONERROR + mb_Ok);
Abort;
end;
try
ExcelApplication1.Workbooks.Add(EmptyParam, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
ExcelWorksheet1.Cells.item[1, 3] := Title;
ExcelWorksheet1.Cells.Item[1, 3].font.size := '14';
ExcelWorksheet1.Cells.item[1, 3].font.Bold := true;
for j := 0 to StringGrid1.ColCount - 1 do
begin
ExcelWorksheet1.Cells.item[3, j + 1] := StringGrid1.cells[j,0];
ExcelWorksheet1.Cells.item[3, j + 1].font.size := '10';
ExcelWorksheet1.Cells.item[3, j + 1].font.Bold := true; //??
end;
for i := 1 to StringGrid1.RowCount-1 do
for j := 0 to StringGrid1.ColCount-1 do
ExcelWorksheet1.Cells.item[i+3, j + 1]:=StringGrid1.Cells[j,i];
ExcelApplication1.visible[0]:=true;
except
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
end;
end;