Convert Excel to PDF with VS2008 and Office2007

I am trying to use Interop.Excell to save an Excel workbook as a PDF file. I use VS2008 and Office2007, and downloaded and installed SaveAsPDFandXPS.exe from Microsoft. This allowed me to save the Word document in pdf format using the following code: object frmt = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; wrd.ActiveDocument.SaveAs (ref dest, ref frmt, ref unknown, ref unknown, ... Pretty cool expet for the whole Interop stuff.

In any case, I was unsatisfied with finding a parallel in Interop.Excell for Word.WdSaveFormat.wdFormatPDF. Workbook.SaveAs accepts Interop.Excel.XlFileFormat, but there is no option for the PDF format. Has anyone done this or have experience in this field?

+4
source share
2 answers

This question has been answered:

What is the FileType number for PDF in Excel 2007, which is required to save a PDF file through the API?

You need to call the Workbook.ExportAsFixedFormat method:

 ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF FileName:="sales.pdf" Quality:=xlQualityStandard DisplayFileAfterPublish:=True 

This method should be preferable to using SaveAs , since it also allows you to specify all PDF / XPS options.

Note. This method was added to the Excel object model with Excel 2007 and requires a Save as PDF or XPS add-in for Microsoft Office 2007 (or SP2) to install.

+7
source

According to Microsoft, the constant used with Workbook.SaveAs to save as PDF is 57.

"The pdf format is not listed here. However, it is numbered 57." From: http://msdn.microsoft.com/en-us/library/bb241279%28office.12%29.aspx

0
source

All Articles