Convert Excel file to PDF in C# and VB.NET

The following sample demonstrates how to convert Excel files from one format to another in C# and VB.NET.

You can load any Excel file format (XLS, XLSX, ODS, HTML, CSV, TAB, or TXT) and convert it into any other Excel file format (XLS, XLSX, ODS, HTML, CSV, TAB, or TXT). You can also convert them into PDF, XPS, and image formats.

Note that below you have Run options with which you can upload your own input Excel file or download the current input file and verify if the conversion to PDF file is satisfactory.

Screenshot

Convert Excel to PDF Screenshot

See the full code below, use RUN EXAMPLE to execute.

Upload your file (Drag files here)

1using System;
2using System.Drawing;
3using System.Text;
4using GemBox.Spreadsheet;
5
6class Sample
7{
8    [STAThread]
9    static void Main(string[] args)
10    {
11        // If using Professional version, put your serial key below.
12        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
13
14        ExcelFile ef = ExcelFile.Load("ComplexTemplate.xlsx");
15
16        // In order to achieve the conversion of a loaded Excel file to PDF,
17        // or to some other Excel format,
18        // we just need to save an ExcelFile object to desired output file format.
19
20        ef.Save("Convert.xls");
21    }
22}
1Imports System.Text
2Imports System.Drawing
3Imports GemBox.Spreadsheet
4
5Module Samples
6
7    Sub Main()
8
9        ' If using Professional version, put your serial key below.
10        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
11
12        Dim ef As ExcelFile = ExcelFile.Load("ComplexTemplate.xlsx")
13
14        ' In order to achieve the conversion of a loaded Excel file to PDF,
15        ' or to some other Excel format,
16        ' we just need to save an ExcelFile object to desired output file format.
17        ef.Save("Convert.xls")
18
19    End Sub
20
21End Module
Check alternative approaches as:

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.