我正在尝试将Excel工作表导出为PDF,我希望工作表适合页面的宽度。在进行一些研究时,似乎我应该使用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;
答案 0 :(得分:1)
似乎在设置FitToPagesWide之前设置Zoom和FitToPagesTall属性。
p.ActiveSheet.PageSetup.Zoom := false;
P.Activesheet.Pagesetup.FitToPagesTall := 1;
p.ActiveSheet.PageSetup.FitToPagesWide := 1;