tags:

views:

763

answers:

2

I am looking for a way to programatically convert Excel reports to XPS format. Is this supported anywhere in the Microsoft framework, or should we look for a third party tool?

Yes currently we are programatically creating Excel reports using ExcelWriter and need to produce XPS reports for a client. So we either go direct to XPS which seems to be a larger learning curve, or convert the Excel report to XPS.

+3  A: 

There is an add on for Office 2007 that gives you the ability to export to XPS or PDF. Invoke Excel via Microsoft.Office.interop.Excel and export to XPS.

From my own code (Workbook is an instance but providing 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.

Colin Burnett
A: 

I would prefer the method suggested by Colin, but you could also use SaveAs on the workbook with the FileFormat constant of 18 for XPS as described in this related question:

What is the FileType number for PDF in Excel 2007 that is needed to save a file as PDF through the API?

0xA3