In this step by step tutorial, we’ll explain how to convert Excel to XPS in C# project. The code sample in this how-to topic shows that you can convert Excel to XPS in C# without Microsoft Excel. This does not required Microsoft Interop either.
Steps to Convert Excel to XPS in C#
- Get Aspose.Cells for .NET API from NuGet.org
- Add reference to Aspose.Cells namespace
- Use SetLicense method to apply the license
- Create an object of Workbook class
- Load input Excel (XLSX or XLS) to be converted to XPS
- Save the Converted XPS file using Xps SaveFormat
In this example, we are converting XLSX to XPS in C#, but by using the same code and steps you can also convert XLS to XPS in C# applications and projects. The code and the process is same in both cases.
C# Code to Convert Excel to XPS in C#
As the above code snippet shows, the conversion can be easily done using just two lines of code of the API. Just like we wrote a how-to topic to export large Excel file to CSV in C# without using Interop or Excel, it is important to note that we have converted Excel to XPS in C# without Microsoft Excel and interop as well. So you can run this code anywhere without installing Excel. That means the code can run on the server and in Windows or ASP.NET applications alike.