Question

Can anybody tell me how to export an excel spreadsheet to pdf using delphi code?

I know there is a command in the MS Word OLE object for exporting to PDf, but I cannot find anything about Excel.

Word To PDF Example:

Const
 wdExportFormatPDF = 17;

 WrdDoc.ExportAsFixedFormat(SaveToFile, wdExportFormatPDF);
Was it helpful?

Solution

The correct code is

wb.ExportAsFixedFormat(xlTypePDF, FileName);

or

sheet.ExportAsFixedFormat(xlTypePDF, FileName);

where wb is a workbook and sheet is a worksheet. If for some reason, your import library does not define xlTypePDF, it has value 0.

Some documentation links:

If you read the documentation carefully you will discover that you have been passing the parameters in the wrong order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top