Excel 自动化 'FitToPagesWide' 自动化对象不支持
Excel Automation 'FitToPagesWide' not supported by automation object
我正在尝试将 Excel sheet 导出为 PDF,我希望 sheet 适合页面宽度。在做一些研究时,我似乎应该使用 FitToPagesWide,但是,我找不到 Delphi 个示例。这是我的代码:
procedure TForm1.ExcelToPDF(const AFilename: string);
Const
XlTypePDF = 0;
xlQualityStandard = 0;
IncludeDocProperties = true;
IgnorePrintAreas = false;
LandscapeMode = 2;
var
P: OleVariant;
begin
P:= CreateOleObject('Excel.Application');
try
P.WorkBooks.Open(AFilename, 3);
p.ActiveSheet.Pagesetup.Orientation := LandscapeMode; orientation
p.ActiveSheet.PageSetup.FitToPagesWide := 1; // <-- not supported by automation object
p.ActiveWorkbook.exportAsFixedFormat(xlTypePDF,
AFilename,
xlQualityStandard,
IncludeDocProperties,
IgnorePrintAreas );
finally
p.Quit;
end;
似乎在设置 FitToPagesWide 之前设置 Zoom 和 FitToPagesTall 属性是可行的。
p.ActiveSheet.PageSetup.Zoom := false;
P.Activesheet.Pagesetup.FitToPagesTall := 1;
p.ActiveSheet.PageSetup.FitToPagesWide := 1;
我正在尝试将 Excel sheet 导出为 PDF,我希望 sheet 适合页面宽度。在做一些研究时,我似乎应该使用 FitToPagesWide,但是,我找不到 Delphi 个示例。这是我的代码:
procedure TForm1.ExcelToPDF(const AFilename: string);
Const
XlTypePDF = 0;
xlQualityStandard = 0;
IncludeDocProperties = true;
IgnorePrintAreas = false;
LandscapeMode = 2;
var
P: OleVariant;
begin
P:= CreateOleObject('Excel.Application');
try
P.WorkBooks.Open(AFilename, 3);
p.ActiveSheet.Pagesetup.Orientation := LandscapeMode; orientation
p.ActiveSheet.PageSetup.FitToPagesWide := 1; // <-- not supported by automation object
p.ActiveWorkbook.exportAsFixedFormat(xlTypePDF,
AFilename,
xlQualityStandard,
IncludeDocProperties,
IgnorePrintAreas );
finally
p.Quit;
end;
似乎在设置 FitToPagesWide 之前设置 Zoom 和 FitToPagesTall 属性是可行的。
p.ActiveSheet.PageSetup.Zoom := false;
P.Activesheet.Pagesetup.FitToPagesTall := 1;
p.ActiveSheet.PageSetup.FitToPagesWide := 1;