Conversion

Conversion (24)

Monday, 17 February 2014 08:50

New method of Convert Excel to PDF in C#

Written by support iceblue

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, add 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);
         }
    }
}
Thursday, 21 November 2013 09:10

How to Convert Excel to Text in C#, VB.NET

Written by Administrator

This article aims at introducing an easy solution to convert Excel (xls/xlsx) to Text in C# and VB.NET by a powerful and independent Excel .NET component, called Spire.Xls. Meanwhile, this Excel API supports for converting Excel (xls/xlsx) to PDF, HTML, Image, CSV, XML, etc, without Microsoft Excel installed on the machine. Download it from here to have a try.

Step 1: Create an instance of Spire.Xls.Document.

Workbook workbook = new Workbook();

Step 2: Load the file base on a specified file name.

workbook.LoadFromFile(@"..\ExceltoTxt.xls");

Step 3: Get the first worksheet of the Worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 4: Save the document object to a Txt file.

sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8);

Effect Screenshot:

Excel_to_Txt

Excel_to_Txt

Sample code:

[C#]
using Spire.Xls;
namespace Excel_to_Txt
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\ExceltoTxt.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace Excel_to_Txt
       Friend Class Program
              Shared Sub Main(ByVal args() As String)
                     Dim workbook As New Workbook()
                     workbook.LoadFromFile("..\ExceltoTxt.xls ")
                     Dim sheet As Worksheet = workbook.Worksheets(0)
                     sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8)
              End Sub
       End Class
End Namespace
Wednesday, 21 November 2012 06:32

Convert CSV to Datatable in C#, VB.NET

Written by support iceblue

CSV to datatable is a data issue that is most concerned by programmer and developers. Compared with Excel, CSV is a simple file format. Is CSV to datatable more easier than Excel to datatable? Please try the following solution. This section will introduce a solution to quickly convert CSV to datatable with C#, VB.NET via a .NET Excel component.

Spire.XLS for .NET, featured as fast and easy, enables you to convert CSV to datatable via two main methods:

  • Workbook.LoadFromFile(string fileName, string separator). This method can be used to load a CSV file.
  • Worksheet.ExportDataTable(). This method is a core method that can be called to export CSV to datatable.

Before viewing the whole code, feel free to download Spire.XLS for .NET and preview below picture.

CSV to Datatable

Detail Code:

[C#]
using Spire.Xls;
using Spire.Xls.Converter;

namespace ExportDataFromCSV
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "CSV document(*.csv)|*.csv";
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string csvFile = dialog.FileName;
                Workbook workbook = new Workbook();
                workbook.LoadFromFile(@"..\csvtodatatable.csv", ",");
                Worksheet worksheet = workbook.Worksheets[0];
                System.Data.DataTable t = worksheet.ExportDataTable();
                this.dataGridView1.DataSource = t;             
            }
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports Spire.Xls.Converter

Namespace ExportDataFromCSV
    
    Public Class Form1
        Inherits Form
        
        Public Sub New()
            MyBase.New
            InitializeComponent
        End Sub
        
        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim dialog As OpenFileDialog = New OpenFileDialog
            dialog.Filter = "CSV document(*.csv)|*.csv"
            Dim result As DialogResult = dialog.ShowDialog
            If (result = DialogResult.OK) Then
                Dim csvFile As String = dialog.FileName
                Dim workbook As Workbook = New Workbook
                workbook.LoadFromFile("..\csvtodatatable.csv", ",")
                Dim worksheet As Worksheet = workbook.Worksheets(0)
                Dim t As System.Data.DataTable = worksheet.ExportDataTable
                Me.dataGridView1.DataSource = t
            End If
        End Sub
    End Class
End Namespace

Spire.XLS is a .NET Excel component, which enables users to perform a wide range of Excel document processing tasks directly, such as generate, read, write and modify Excel document in WPF, .NET and Silverlight.

Monday, 08 October 2012 05:33

Convert CSV to Excel in C#, VB.NET

Written by support iceblue

This section will show you a very simple solution to quickly convert CSV to Excel(xls/xlsx) with C#, VB.NET. The whole CSV to Excel task can be realized by only three lines' of key code via a .NET Excel component.

Spire.XLS for .NET, as a professional .NET Excel component built from C#, VB.NET, enables you to mainly convert CSV to Excel by calling two methods: One method is Spire.Xls.Workbook.LoadFromFile(string fileName, string separator, int row, int column) which is used to load CSV file from system. The other is Workbook. SaveToFile(string fileName, ExcelVersion version) to save the CSV file just loaded as Excel. In the solution, Sheet1 is named to be "csv to excel" by setting the Property: Spire.Xls.Worksheet.Name. Besides, Excel background color is added in the target Excel file by Worksheet.Range[].Style.Color.

Before displaying the whole code, please download Spire.XLS for .NET and view the target Excel file as below picture:

CSV to Excel

[C#]
using Spire.Xls;

namespace csvtoxls
{
    class Program
    {
        static void Main(string[] args)
        {
         Workbook workbook = new Workbook();
         workbook.LoadFromFile(@"D:\michelle\my file\csv2xls.csv", ",", 1, 1);
         Worksheet sheet = workbook.Worksheets[0];
         sheet.Name = "csv to excel";
         //set the backgroundcolor=LightBlue of Range["A1:E1"]
         sheet.Range["A1:E1"].Style.Color = Color.Chocolate;
         //set the backgroundcolor=LightBlue of Range["A2:E6"]
         sheet.Range["A2:E6"].Style.Color = Color.SpringGreen;
         //set the backgroundcolor=Silver of Range["A7:E12"]
         sheet.Range["A7:E12"].Style.Color = Color.SkyBlue;
         //set the backgroundcolor=Silver of Range["A13:E19"]
         sheet.Range["A13:E19"].Style.Color = Color.Yellow;
         workbook.SaveToFile("result.xls", ExcelVersion.Version97to2003);        
        }
    }
}
[VB.NET]
Imports Spire.Xls

Namespace csvtoxls
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            Dim workbook As Workbook = New Workbook
            workbook.LoadFromFile("D:\michelle\my file\csv2xls.csv", ",", 1, 1)
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.Name = "csv to excel"
            'set the backgroundcolor=LightBlue of Range["A1:E1"]
            sheet.Range("A1:E1").Style.Color = Color.Chocolate
            'set the backgroundcolor=LightBlue of Range["A2:E6"]
            sheet.Range("A2:E6").Style.Color = Color.SpringGreen
            'set the backgroundcolor=Silver of Range["A7:E12"]
            sheet.Range("A7:E12").Style.Color = Color.SkyBlue
            'set the backgroundcolor=Silver of Range["A13:E19"]
            sheet.Range("A13:E19").Style.Color = Color.Yellow
            workbook.SaveToFile("result.xls", ExcelVersion.Version97to2003)
        End Sub
    End Class
End Namespace
Wednesday, 17 August 2011 06:53

Convert Specific Worksheet Cells to Image

Written by support iceblue

This section aims at providing a detail solution for developers on how to convert specific worksheet cells to image via this .NET Excel component Spire.XLS for .NET in C#, VB.NET. This Excel library helps us quickly convert certain excel cells to different image formats such as jpeg, png, bmp, tiff, gif, ico, emf, exif etc.

When we convert worksheet to image, Spire.XLS for .NET provides us a method: Spire.Xls.Worksheet.SaveToImage(int firstRow, int firstColumn, int lastRow, int lastColumn); As we see, there are four parameters passed in this method. These four parameters determine the certain range of cells. After deciding the cell range, we can successfully convert cells to image. Now, let us see the whole task step by step.

Step 1: Create a template Excel Workbook in MS Excel

I create a new Excel file in MS Excel and add some data which have different formats in the first sheet, here is a screenshot of created file.

Excel to Image

Step 2: Download and Install Spire.XLS for .NET

Spire.XLS for .NET is an Excel Api which enables users to quickly generate, read, edit and manipulate Excel files on .NET Platform. Here you can download Spire.XLS for .NET and install it on your development computer. After installing it, Spire.XLS for .NET will run in evaluation mode which is the same when you install other Spire components. This evaluation mode has no time limit.

Step 3: Create a project and Add References

We can create a new project of Console Application either in C# or VB.NET. I create in C#, but we can choose VB.NET too.

In this project, we need to add references in our project. Apart from adding System.Drawing, we will use Spire.XLS for .NET, so we also have to add Spire.Xls.dll, Spire.Common.dll and Spire.License.dll in our download Bin folder of Spire.Xls. Here we can see the default path: "..\Spire.XLS\Bin\NET4.0\Spire.XLS.dll"

Step 4: Convert Specific Worksheet Cells to Image

In this step, first we can initialize a new object of the class Spire.Xls.Workbook, then, load the template Excel file. Since I want to convert cells in the first sheet to image, I need get the first worksheet data in Excel file. You also can get other worksheet data. Finally specify cell range and save the cells in the range as image file. Spire.XLS for .NET supports 12 image formats: Bmp, Emf, Equals, Exif, Gif, Icon, Jpeg, MemoryBmp, Png, ReferenceEquals, Tiff and Wmf.

[C#]
using System.Drawing;
using System.Drawing.Imaging;
using Spire.Xls;
using Spire.Xls.Converter;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize a new Workbook object
            Workbook workbook = new Workbook();
            //Open Template Excel file
            workbook.LoadFromFile(@"..\excel to image.xlsx");
            //Get the first wirksheet in Excel file
            Worksheet sheet = workbook.Worksheets[0];
            //Specify Cell Ranges and Save to certain Image formats
            sheet.SaveToImage(1, 1, 6, 3).Save("image1.png",ImageFormat.Png);
            sheet.SaveToImage(7, 1, 12, 3).Save("image2.jpeg", ImageFormat.Jpeg);
            sheet.SaveToImage(13, 1, 18, 3).Save("image3.bmp", ImageFormat.Bmp);
        }
    }
}
          
[VB.NET]
Imports System.Drawing
Imports System.Drawing.Imaging
Imports Spire.Xls
Imports Spire.Xls.Converter

Namespace ConsoleApplication1
	Class Program
		Private Shared Sub Main(args As String())
			'Initialize a new Workbook object
			Dim workbook As New Workbook()
			'Open Template Excel file
			workbook.LoadFromFile("..\excel to image.xlsx")
			'Get the first wirksheet in Excel file
			Dim sheet As Worksheet = workbook.Worksheets(0)
			'Specify Cell Ranges and Save to certain Image formats
			sheet.SaveToImage(1, 1, 6, 3).Save("image1.png", ImageFormat.Png)
			sheet.SaveToImage(7, 1, 12, 3).Save("image2.jpeg", ImageFormat.Jpeg)
			sheet.SaveToImage(13, 1, 18, 3).Save("image3.bmp", ImageFormat.Bmp)
		End Sub
	End Class
End Namespace

Result Task

After executing above code, cells in the first worksheet named "Sheet1" has been converted to three images. They are named "image1.png", "image2.jpeg" and "image3.bmp". You can see them as below:

Excel to Image

In this section, I have introduced how we can convert specific cells to image by using Spire.XLS for .NET. I sincerely hope it can help you and give you some insight.

Spire.XLS for .NET offers fast speed, high efficiency and reliability to satisfy development application requirements. As you see above, the results do show that Spire.XLS for .NET benefit customers from years of research.

We appreciate any kind of queries, comments and suggestions at E-iceblue Forum. We promise a quick reply within minutes or hours as we can.

This section just aims at introducing an easiest solution to convert Excel (XLS/XLSX) to CSV with C#, VB.NET via an Excel component. Two reasons can be attributed to call this solution the easiest: One is that the key code of Excel to CSV is only three lines; the other reason is that you can directly convert Excel to CSV without opening the original Excel file.

Spire.XLS for .NET, as a .NET Excel component, enables users to fast create, read, write and modify Excel document without Microsoft Office Excel Automation. Besides, it has powerful conversion functions, such as it can easily convert excel to PDF, Excel to HTML, Excel to XML, XML to Excel, Excel to Image and Excel to CSV.

By calling a class Spire.XLS.Worksheet in Spire.XLS.dll component, you can convert Excel to CSV by calling a method: public void SaveToFile(string fileName, string separator, Encoding encoding) with three parameters passed. Please preview the effective screenshot of this task first:

Excel to CSV

Now before view the whole code of Excel to CSV conversion, please Download Spire.XLS for .NET.

Sample Code:

[C#]
using Spire.Xls;
namespace xls2csv
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\ExceltoCSV.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("sample.csv", ",", Encoding.UTF8);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace xls2csv
       Friend Class Program
              Shared Sub Main(ByVal args() As String)
                     Dim workbook As New Workbook()
                     workbook.LoadFromFile("..\ExceltoCSV.xls ")
                     Dim sheet As Worksheet = workbook.Worksheets(0)
                     sheet.SaveToFile("sample.csv", ",", Encoding.UTF8)
              End Sub
       End Class
End Namespace
Tuesday, 19 July 2011 07:19

Worksheet to Image in C#, VB.NET

Written by support iceblue

Making a Microsoft Excel worksheet to an image file can be quite useful when you might need to use an image of a worksheet in an application or web page. This can be the most effective solution for developers to convert worksheet to image as this solution converts Excel spreadsheets-including all text, formatting and diagrams-to graphic files.

Spire.XLS for .NET supports converting Excel worksheets to images. To use this feature, you need to invocate the method - public void SaveToImage(string fileName) in your program or project. You can convert a worksheet to image file(s) with different attributes or options and you can save the image file to disk. Most image formats are supported, such as BMP, PNG, GIF, JPG, JPEG, TIFF, and etc.

  • Create a new workbook
  • Load information from excel file and transfer into workbook
  • Save workbook as any image file format at your will

Below is an effective screenshot of the target . png image from Excel spreadsheet.

Excel to Image

Download Spire.XLS for .NET (or Spire.Office) with .NET Framework 2.0 (or above) together. In your application add Spire.XLS reference. The following code snippet shows how to convert an Excel worksheet to an image in C#, VB.NET.

[C#]
using Spire.Xls;
namespace Xls2Image

{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\test.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToImage("sample.jpg");
        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace Xls2Image
       Friend Class Program
              Shared Sub Main(ByVal args() As String)
                     Dim workbook As New Workbook()
                     workbook.LoadFromFile("..\..\test.xls")
                     Dim sheet As Worksheet = workbook.Worksheets(0)
                     sheet.SaveToImage("sample.jpg")
              End Sub
       End Class
End Namespace
Tuesday, 19 July 2011 06:38

Export Excel to XML and Import XML to Excel

Written by support iceblue

How can we export Excel to Office Open XML and import Office Open XML to Excel quickly and with sound quality? The answer is what most developers desire to know and clients concern. Here will demonstrate an effortless method to export Excel to Office Open XML and import Office Open XML to Excel separately or synchronously.

Spire.XLS for .NET is a professional .NET Excel component which enables us to fast export Excel to Office Open XML or import Office Open XML to Excel within just three steps. The export/import features such unique as below:

  • Microsoft Excel is not necessary on client and/or server side.
  • Export/import can be proceeding separately or synchronously.

Excel to XML

Spire.Xls for .NET always welcomes any kind of trial or evaluation, so feel free to download Spire.XLS for .NET to realize transform between Excel and Office Open XML within 3 steps.

PS: Spire.Xls only supports Office OpenXML.

Export Excel to Office Open XML in C#, VB.NET

The whole process of exporting Excel to Office Open XML in C#, VB.NET can be described as 3 simple steps:

  • Create a new workbook
  • Load information from excel file and transfer into workbook
  • Save workbook as Office Open XML file format

The following is the code sample that we use to export Excel to Office Open XML in C#, VB.NET

[C#]
Workbook wb = new Workbook();
wb.LoadFromFile(@"..\..\sample.xlsx");
wb.SaveAsXml("result.xml");
[VB.NET]
Dim wb As New Workbook()
wb.LoadFromFile(@"..\..\sample.xlsx")
wb.SaveAsXml("result.xml")

Import Office Open XML to Excel in C#, VB.NET

In this section, you will feel it is as easy as ABC to import Office Open XML to Excel in C#, VB.NET. This process will also be completed in 3 steps too. Please see the codes below:

[C#]
Workbook workbook = new Workbook();
workbook.LoadFromXml(@"..\..\test.xml");
workbook.SaveToFile("result.xlsx",ExcelVersion.Version2010);
[VB.NET]
Dim workbook As New Workbook()
workbook.LoadFromXml("..\..\test.xml")
workbook.SaveToFile("result.xlsx",ExcelVersion.Version2010)
Tuesday, 19 July 2011 03:26

Excel to HTML in C#, VB.NET

Written by support iceblue

This article describes a simple approach to convert Excel to HTML by using C#/VB.NET. We will use as few codes as you can image to convert Excel to HTML in C#/VB.NET, with the perfect quality as you expect. The appearance of data can be improved as you can edit the HTML by applying personal CSS. Thus we believe any effect and requirement you or your clients wished to have.

Spire.XLS for .NET provides a well-designed class-workbook, which allows us to create new Excel or load an Excel in, and then we can convert Excel to HTML; meanwhile most optimization on the Excel is also allowed during the conversion. Spire.Xls for .NET is always welcome to any kind of trial and evaluation. So now please feel free to download Spire.XLS for .NET and then follow our guide to quickly convert Excel to HTML using C#/VB.NET or try other function of Spire.Xls for .NET.

Now please check my code samples for converting Excel to HTML in C#/VB.NET.

[C#]
using Spire.Xls;
namespace Xls2Html

{
    class Program
    {
        static void Main(string[] args)
        {
            //load Excel file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\test.xls");
            
            //convert Excel to HTML
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToHtml("sample.html");

            //Preview HTML
            System.Diagnostics.Process.Start("sample.html");
        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace Xls2Html

	Class Program
		Private Shared Sub Main(args As String())
			'load Excel file
			Dim workbook As New Workbook()
			workbook.LoadFromFile("..\..\test.xls")

			'convert Excel to HTML
			Dim sheet As Worksheet = workbook.Worksheets(0)
			sheet.SaveToHtml("sample.html")

			'Preview HTML
			System.Diagnostics.Process.Start("sample.html")
		End Sub
	End Class
End Namespace

Now we can run this application and then a perfect HTML will be presented in your browser. Please see our effective screenshot as below:

Excel to HTML

Friday, 08 July 2011 05:23

Excel to PDF in C#, VB.NET

Written by support iceblue

In order to convert Excel to PDF in C#/VB.NET, you may have searched a lot, finding huge lines of codes but not perfect in quality. Here is the nice solution you are looking for. Within this section, we will demonstrate how to convert Excel to PDF using C#/VB.NET. This conversion will be successfully managed within just several lines of codes, but the quality will be absolutely perfect; As the PDF will be the same as your Excel file.

Spire.XLS for .NET is .NET Excel component which enables your .NET applications to fast generate, read, write and modify Excel document without Microsoft Office Excel Automation. It also fully supports converting files from Excel to PDF, Excel to HTML, Excel to CSV, Excel to Text, Excel to Image and Excel to XML. Any kind of trial and evaluation is always welcomed. Please feel free to download Spire.XLS for .NET to have a trial.

Spire.XLS now offers a new method to convert excel to PDF, which supports convert chart, shape and smart art in excel file to PDF. Please refer to new method of convert Excel to PDF.

The following is the code samples for converting Excel to PDF in C#/VB.NET. You can directly copy and paste into your project to have a try and convert your Excel to PDF for personal use.

[C#]
using Spire.Xls;
using Spire.Pdf;
using Spire.Xls.Converter;

namespace ExceltoPDF
{
    class Program
    {
        static void Main(string[] args)
        {
           // load Excel file
           Workbook workbook = new Workbook();
           workbook.LoadFromFile("D:\\test.xlsx");
 
           // Set PDF template
           PdfDocument pdfDocument = new PdfDocument();
           pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
           pdfDocument.PageSettings.Width = 970;
           pdfDocument.PageSettings.Height = 850;

           //Convert Excel to PDF using the template above
           PdfConverter pdfConverter = new PdfConverter(workbook);
           PdfConverterSettings settings = new PdfConverterSettings();
           settings.TemplateDocument = pdfDocument;
           pdfDocument = pdfConverter.Convert(settings);

           // Save and preview PDF
           pdfDocument.SaveToFile("sample.pdf");
           System.Diagnostics.Process.Start("sample.pdf");
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports Spire.Pdf
Imports Spire.Xls.Converter

Namespace ExceltoPDF
	Class Program
		Private Shared Sub Main(args As String())
			' load Excel file
			Dim workbook As New Workbook()
			workbook.LoadFromFile("D:\test.xlsx")

			' Set PDF template
			Dim pdfDocument As New PdfDocument()
			pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape
			pdfDocument.PageSettings.Width = 970
			pdfDocument.PageSettings.Height = 850

			'Convert Excel to PDF using the template above
			Dim pdfConverter As New PdfConverter(workbook)
			Dim settings As New PdfConverterSettings()
			settings.TemplateDocument = pdfDocument
			pdfDocument = pdfConverter.Convert(settings)

			' Save and preview PDF
			pdfDocument.SaveToFile("sample.pdf")
			System.Diagnostics.Process.Start("sample.pdf")
		End Sub
	End Class
End Namespace

After this code, you can run this application and you will see the PDF converted from Excel. Below is a comparison of the original Excel and target PDF, please have a check.

Excel to PDF

Page 2 of 2