This guide will brief you on how to save Excel file as PDF using C#. After going through the recommended steps and example code, you can easily convert Excel to PDF in C# without using MS Office interop.
Steps to Save Excel File as PDF using C#
- Install package Aspose.Cells for .NET from NuGet.org
- Import Aspose.Cells namespace into Visual Studio .NET console application
- Instantiate License object to set it via SetLicense method
- Load the XLSX file into Aspose.Cells object model using Workbook constructor
- Save the Excel file as PDF via Save method of the Workbook class
Sometimes you need to extract a PDF (which is widely accepted and standard format) copy of Excel spreadsheet, so the users should view your report data directly on their environment/platform without needing any tool. The steps (mentioned above) explain the process to render Excel workbook to PDF format using C#. We will write a couple of lines in C# to convert Excel file to PDF.
Code to Save Excel File as PDF using C#
In the sample code, we demonstrate on how to convert XLSX to PDF in C#. You just need to write a few lines of code in C# and you are able to convert whole Excel workbook to PDF format without Office. Your Excel file might have formatted data, charts, pivot tables, formulas, images and other objects. The conversion becomes challenging as you always need results with maximum accuracy and precision. Aspose.Cells does convert the Excel file to PDF format properly accompanied with excellence. You can also find detailed article on how to convert Excel to XPS in C# .NET.