Aller au contenu principal

ExcelExportAsPDF

Structure

TCommonLibrary.ExcelExportAsPDF(AMachine:TatVirtualMachine); // (sExcelFileName, sPDFFileName, bIncludeDocProperties, bIgnorePrintArea, iPageFrom, iPageTo, bOpenAfterPublish)

Type

Procedure

Description

The TCommonLibrary.ExcelExportAsPDF procedure serves as a pass-through to the ExportAsFixedFormat method in Excel's OLE automation (Windows drivers). This means the procedure requires Excel to be installed on the server for it to work correctly.

If the script can open the document using OLE (like Workbooks.Open method (Excel) | Microsoft Learn) then it passes along all the variables to their ExportAsFixedFormat function, as documented here: Worksheet.ExportAsFixedFormat method (Excel) | Microsoft Learn

The only parameter that is hardcoded is the second Quality parameter, which is set to Standard (0).

Behind-the-scenes Scripting Call:

//Open Excel Workbook
try
ExcelWorkbook := ExcelApplication.Workbooks.Open(sExcelFileName);
//reference
//https://docs.microsoft.com/en-us/office/vba/api/excel.workbooks.open
except
ExcelWorkbook := Null;
bResult := False;
end;

If VarIsNull(ExcelWorkbook) = False then
begin
Try
ExcelWorkbook.ExportAsFixedFormat(0, sPDFFileName, 0, bIncludeDocProperties, bIgnorePrintArea, iPageFrom, iPageTo, bOpenAfterPublish, EmptyParam);
// reference
//https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.exportasfixedformat
Except
bResult := False;
End;
end;