How to convert Excel to XPS in C#

Many of our customers have requested to convert Excel workbook to an XPS file. Spire.XLS for .NET allows you to convert Excel (.xls, xlsx) to XPS. You only need three core lines of code to convert Excel workbook into XPS. Multiple elements in Excel file can be converted to XPS successfully, such as chart, shape, smart art, Image and etc.

Firstly, Download Spire.XLS for .NET (version 7.5.16 or above) and install it on your system. Then, adds Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: "..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll".

Please check the original excel file first. In this worksheet, it contains image, shape, smart art, table and chart.

How to convert Excel to XPS in C#

Now please check the codes in C#:

Step 1: Load an excel workbook from the file.

Workbook workbook = new Workbook(); 
workbook.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);

Step 2: Save the workbook to file in XPS format.

workbook.SaveToFile("result.xps", Spire.Xls.FileFormat.XPS);

Effective screenshot of XPS file:

How to convert Excel to XPS in C#

Full Codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;

namespace ExceltoXPS
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook(); 
            workbook.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);
         
            workbook.SaveToFile("result.xps", Spire.Xls.FileFormat.XPS);
        }
    }
}