While manipulating PDF files programmatically, you often need to export tables in PDF to Excel sheets. However, it requires an accurate conversion to ensure high-quality output. So why not try a powerful, high-speed, and easy-to-use PDF to Excel converter for C#? This article guides you on how to convert PDF files to Excel XLS or XLSX in C# in a few simple steps.
This article covers the following PDF to Excel conversions.
- C# .NET PDF to Excel Converter
- Convert a PDF to XLS in C#
- Convert a PDF to XLSX in C#
- Export PDF to Excel - Insert Blank First Column
- Save PDF as Excel XLS - Minimize Number of Sheets
How to Convert PDF to Excel in C#
For converting PDF files to Excel XLS/XLS in C#, we’ll use Aspose.PDF for .NET. The library supports creating and manipulating PDF documents as well as converting PDF files to other formats with high fidelity. Not only this but you can convert your PDF files to XLS/XLSX FREE.
You can either download its DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.PDF
Save PDF as Excel XLS in C#
To convert a PDF document to the XLS spreadsheet, you can simply load the PDF file and save it with the “.xls” extension. The following are the steps to perform this conversion.
- Load the PDF file using Document class.
- Create an object of the ExcelSaveOptions class.
- Save PDF file as Excel XLS using Document.Save(string, ExcelSaveOptions) method.
C# Code to Convert PDF to XLS
The following code sample shows how to convert PDF to Excel XLS in C#.
Input PDF Document
Converted Excel XLS
Export PDF to XLSX in C#
By default, Aspose.PDF converts the PDF document to XLS format. In case you want to get the converted Excel spreadsheet in XLSX format, you can specify it using ExcelSaveOptions class.
The following code sample shows how to convert a PDF document to Excel with XLSX format using C#.
C# PDF to Excel - Blank First Column
You can also insert a blank first column in the converted Excel spreadsheet. This can be done using ExcelSaveOptions.InsertBlankColumnAtFirst option.
- Load the PDF file using Document class.
- Create an object of the ExcelSaveOptions class.
- (Optional) Set output Excel format to XLSX using ExcelSaveOptions.Format property.
- Set ExcelSaveOptions.InsertBlankColumnAtFirst property to true.
- Save PDF file in Excel format using Document.Save(string, ExcelSaveOptions) method.
The following code sample shows how to add a blank first column in PDF to Excel conversion.
Minimized Number of Sheets in PDF to Excel Conversion
By default, every page in the input PDF document is converted into a separate worksheet. For large PDF documents with several pages, the converted Excel spreadsheet will also contain several worksheets. In such a case, you can customize the PDF to Excel conversion and minimize the number of worksheets in the converted spreadsheet. The following are the steps to perform this customization.
- Load the PDF file using Document class.
- Create an object of the ExcelSaveOptions class.
- (Optional) Set output Excel format to XLSX using ExcelSaveOptions.Format property.
- Set ExcelSaveOptions.MinimizeTheNumberOfWorksheets property to true.
- Save PDF file as XLS/XLSX using Document.Save(string, ExcelSaveOptions) method.
The following code sample shows how to minimize the number of worksheets in PDF to Excel conversion in C#.
Free PDF to Excel C# Converter
You can get a free temporary license to convert PDF files to Excel format without evaluation limitations.
Explore PDF to Excel Library
In case you are interested in exploring other features of Aspose.PDF, visit the documentation here.
Conclusion
In this article, you have learned how to convert PDF files to Excel formats programmatically in C#. Furthermore, you have seen how to customize the conversion using different options. You can easily integrate the provided code sample into your .NET applications.