Convert Excel to XPS programmatically
I am looking for a way to programmatically convert Excel reports to XPS format. Is this supported somewhere within Microsoft, or should we look for a third party tool?
Yes, we are currently generating Excel reports programmatically using ExcelWriter and we need to generate XPS reports for the client. So we'll either go directly to XPS, which seems like a more complex learning curve, or we'll convert the Excel report to XPS.
a source to share
There is an add for Office 2007 that gives you the option to export to XPS or PDF. Call Excel via Microsoft.Office.interop.Excel and export to XPS.
From my own code (Workbook is an instance, but it contains the full namespace instead):
Microsoft.Office.Interop.Excel.Workbook.ExportAsFixedFormat(
Excel.XlFixedFormatType.xlTypeXPS,
pdfpath, Excel.XlFixedFormatQuality.xlQualityStandard,
true, true,
fpage, tpage,
false,
oMissing
);
There is an MSDN article on how to do this.
a source to share
I would prefer the method suggested by Colin, but you can also use SaveAs
in the book with a constant FileFormat
18
for XPS as described in this related question:
What is the FileType number for PDF in Excel 2007 that is required to save the file as PDF via API?
a source to share