XPS stands for XML Paper Specification, which is a fixed layout file format developed by Microsoft. Unlike some formats that allow for dynamic content and layout changes, XPS is built to preserve the layout of documents and maintain their visual appearance across different devices. XPS files can be easily viewed using the Microsoft XPS Viewer, which is pre-installed on many Windows computers.
There are several benefits to converting Excel files to XPS format. Firstly, it provides an efficient way to share Excel data with others who lack access to Microsoft Excel or other spreadsheet software. Secondly, it ensures that the formatting of the original Excel file remains intact, making it easy to read and understand. Another advantage of converting Excel to XPS is accessibility: XPS files are built to be accessible, meaning they can be read by screen readers and assistive technology. In this article, we will explain how to convert an Excel file to XPS format in C++ using Spire.XLS for C++.
Install Spire.XLS for C++
There are two ways to integrate Spire.XLS for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.XLS for C++ in a C++ Application
Convert Excel to XPS in C++
Converting an Excel file to XPS format is very straightforward using Spire.XLS for C++. You just need to load the Excel file using the Workbook->LoadFromFile(LPCWSTR_S fileName) method and then call the Workbook->SaveToFile(LPCWSTR_S fileName, FileFormat::XPS) method to save it as XPS. The detailed steps are as follows:
- Specify the input and output file paths.
- Initialize an instance of the Workbook class.
- Load the Excel file specified by the input file path using Workbook->LoadFromFile() method.
- Save the Excel file to an XPS file with the specified file path using Workbook->SaveToFile(LPCWSTR_S fileName, FileFormat::XPS) method.
- C++
#include "Spire.Xls.o.h"; using namespace Spire::Xls; using namespace std; int main() { //Specify the input and output file paths wstring inputFile = L"Sample.xlsx"; wstring outputFile = L"ExcelToXPS.xps"; //Initialize an instance of the Workbook class Workbook* workbook = new Workbook(); //Load the Excel file specified by the input file path workbook->LoadFromFile(inputFile.c_str()); //Save the Excel file to an XPS file with the specified file path workbook->SaveToFile(outputFile.c_str(), Spire::Xls::FileFormat::XPS); workbook->Dispose(); delete workbook; }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.