New method of Convert Excel to PDF in C#

Converting Excel to PDF with .NET excel component is so popular that we always try our best to improve our Spire.XLS better and better. We aim to make the function more powerful and support more elements in Excel worksheets. Now besides the previous method of converting Excel to PDF offered by Spire.XLS, we have updated the feature of excel conversion to PDF. With this new updates, more elements in Excel file can be converted to PDF successfully, such as chart, shape, smart art and etc. You only need three lines of code to accomplish the conversion work.

Firstly, Download Spire.XLS for .NET (version 7.3.2 or above) and install it on your system. Then, adds Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: "..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll".

Please check the original excel file first. In this worksheet, it contains image, shape, smart art, table and chart.

Excel to PDF

Now please check the codes in C#:

Step1: Load an excel workbook from the file.

Workbook workbook = new Workbook(); workbook.LoadFromFile(@"..\..\Sample.xlsx", ExcelVersion.Version2010);

Step2: Save the document to file in PDF format.

workbook.SaveToFile(@"..\..\result.pdf", Spire.Xls.FileFormat.PDF);

You will get the PDF file which is almost the same with the original file:

Excel to PDF

The full codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;

namespace ToPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010);
            workbook.SaveToFile("result.pdf", Spire.Xls.FileFormat.PDF);
         }
    }
}