导出来之后,再FORMAT一下这个EXCEL文件.
procedure TfrmBaseGrid.FormatXls(const sFile, sTitle, sImgFile: string);
var
sTmp: string;
xls, vApp: Variant;
i, j, iRow, iCol, iWidth, iHeight: Integer;
Bmp: TBitmap;
begin
try
ShowPlan('正在导入数据,请稍候......', 1, False);
xls := CreateOleObject('Excel.Application');
try
xls.WorkBooks.Open(sFile);
(**)
vApp := xls.ActiveWorkBook.ActiveSheet;
if sTitle <> '' then
begin
vApp.Rows['1:1'].Insert(-4121);
vApp.Range['A1'].FormulaR1C1 := sTitle;
end;
iRow := vApp.UsedRange.Rows.Count;
iCol := vApp.UsedRange.Columns.Count;
ShowPlan('正在转换数据格式,请稍候......', iRow + 1, False);
for i := 1 to iRowdo
begin
for j := 1 to iColdo
begin
sTmp := vApp.Cells[i, j];
vApp.Cells[i, j] := sTmp;
end;
SetPlanPos;
end;
SetPlanPos;
(**)
if (sImgFile <> '') and (FileExists(sImgFile)) then
begin
Bmp := TBitmap.Create;
try
Bmp.LoadFromFile(sImgFile);
iWidth := Bmp.Width;
iHeight := Bmp.Height;
finally
Bmp.Free;
end;
vApp.Shapes.AddPicture(sImgFile, True, True, 10, iRow * 14.25, iWidth, iHeight);
end;
(**)
xls.ActiveWorkBook.Save;
finally
xls.Quit;
VarClear(xls);
ClosePlan(True);
end;
except
on e: Exceptiondo
messageBox(handle,'错误',PChar(e.Message),mb_Ok or MB_ICONERROR)
end;
end;