Skip to main content Skip to footer

Programmatically Convert Excel XLSX to PDF Using C# .NET

Quick Start Guide
Tutorial Concept C# XLSX Conversion - Use a C# .NET Excel API Library to convert XLSX files to other formats. This tutorial will show how to convert the XLSX to a PDF document.
What You Will Need

.NET application

Document Solutions for Excel, .NET Edition

Controls Referenced

Document Solutions for Excel, .NET (DsExcel) - C# Excel Library

Documentation | Online Demos

If you have Excel spreadsheets generated from .NET 8 applications, you may find it useful to store your files in a PDF format.

Why Do I Need to Convert an Excel Spreadsheet to PDF?

Several reasons include:

  • Universal Accessibility: PDFs can be opened and viewed by almost any device with a PDF reader, regardless of whether the recipient has Microsoft Excel installed. This makes it a great way to share data with anyone who needs to see it.
  • Preserving Formatting: When you convert an Excel spreadsheet to PDF, the formatting (fonts, colors, cell borders, etc.) is preserved exactly as it appears in the spreadsheet. This ensures that the recipient sees the data exactly as intended.
  • Restricting Edits: Unlike Excel files, PDFs are not easily editable. Converting a spreadsheet to a PDF can be a way to share information while preventing unintended modifications to the data.
  • Creating a Polished Document: PDFs can present data in a clean and professional format, which is useful for reports, presentations, or media kits.

Alternatively, you may need to create and distribute the following company reports:

  • Financial Statements, such as income statements, balance sheets, or cash flow statements
  • Company Budget Reports, which outline projected income and expenses
  • Sales Forecast Reports, which track metrics like sales figures, product performance, and customer trends
  • Inventory Reports, which track stock levels, product locations, and reorder points
  • Audit Reports, which contain detailed findings and recommendations to be shared with relevant parties

Document Solutions for Excel is a high-speed, small-footprint spreadsheet API that requires no dependencies on Excel. With full .NET/.NET Core support, you can generate, load, modify, and convert spreadsheets in .NET, .NET Framework, .NET Core, Mono, and Xamarin. Applications using this spreadsheet API can be deployed to the cloud, Windows, Mac, or Linux with no additional dependencies.

Exporting Excel Spreadsheets to PDF in .NET

This blog will cover the following:

Note: When working with Document Solutions for Excel on MAC or Linux, specify the Workbook.FontFolderPath and place the necessary fonts in it before exporting spreadsheets to PDF.

For more information, visit: Configure Fonts and Set Style.

Ready to Try It Out? Download Document Solutions for Excel, .NET Edition Today!

How to Create an Excel Spreadsheet and Save It to PDF

Step 1: Create an Excel Spreadsheet

Follow this link to create a basic Excel spreadsheet on Windows, MAC, or Linux.

At the end of this tutorial, the spreadsheet will look like this:

Create spreadsheet

Step 2: Convert Excel Spreadsheets to PDF

In Step 1, we created an Excel spreadsheet using the Document Solutions for Excel workbook and saved it to an Excel file. Instead of saving to an Excel file, you can directly save the workbook to PDF. Please note that if you need to print the worksheet on a single PDF, you can set additional options through the PageSetup class of the worksheet.

worksheet.PageSetup.Orientation = PageOrientation.Landscape;
worksheet.PageSetup.IsPercentScale = false;
worksheet.PageSetup.FitToPagesWide = 1;
worksheet.PageSetup.FitToPagesTall = 1;
workbook.Save(@"SimpleBudget.pdf");

The PDF will look like this:

Convert to PDF

How to Load an Excel Spreadsheet and Save to PDF

If you want to convert any of your Excel files (whether created with Excel, Document Solutions for Excel, or from another third-party tool), you can do so in just four simple steps using Document Solutions for Excel.

Suppose you want to convert an Excel file, such as the one shown below, that calculates the total account data summary (as per different age groups in a region) to a PDF.

Load spreadsheet

Follow these steps:

Step 1: Create an empty workbook.

var workbook = new GrapeCity.Documents.Excel.Workbook();

Step 2: Load the Excel file into the workbook.

workbook.Open("AgingReport.xlsx");

Step 3: Add additional options through the PageSetup class of the worksheet. This will export the whole worksheet to a single PDF page.

workbook.Worksheets[0].PageSetup.Orientation = PageOrientation.Landscape;
workbook.Worksheets[0].PageSetup.IsPercentScale = false;
workbook.Worksheets[0].PageSetup.FitToPagesWide = 1;
workbook.Worksheets[0].PageSetup.FitToPagesTall = 1;

Step 4: Save to PDF.

workbook.Save("AgingReport.pdf");

This simple conversion transforms the Excel spreadsheet into a PDF:

Convert to PDF

Supported PDF export features include:

Try the demo here and follow along with the video below:

Visit this help topic for more info on converting Excel to PDF with Document Solutions for Excel, Java Edition. 

Please comment below if this feature satisfies your requirements or if you are looking for additional features!

Ready to Try It Out? Download Document Solutions for Excel, .NET Edition Today!

Tags:

comments powered by Disqus