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.

-1


a source to share


3 answers


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.

+3


a source


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?

0


a source


You can also print from Excel to XPS. Not technically converting, but maybe exactly what you need.

Dim ws As Worksheet
Set ws = ActiveSheet
Call ws.PrintOut(ActivePrinter:="Microsoft XPS Document Writer", _
                PrintToFile:=True, PrToFileName:="S:\Temp\Test3.xps")

      

0


a source







All Articles