Convert XLS File to PDF in C# and VB.NET | helpprogrammers |

This technical tip shows how an Excel XLS document can be converted to PDF file. Aspose.Cells component is designed to provide a fast and convenient way to convert any type of Excel spreadsheet into PDF format.



The purpose of this article is to demonstrate step by step process to do the conversion into PDF format. Since we all know the great essence of Excel files remains in: the cells are organized in rows and columns into different worksheets, and contain all types of data or formulas with relative or absolute references to other cells. The Intuitive interface related formatting and capable calculation and graphing ability which have made it the dominant spreadsheet in the market today. It not only has editing options, but also possesses the versatility of spreadsheet management. This makes it easier to perform statistical analysis and manipulations on any type of data of any volume. Similarly, PDF (Portable Document Format) has its own advantages. The file format represents documents in a manner that is independent of the original application software, hardware, and operating system used to create those documents.



Aspose.Cells is an Excel® spreadsheet reporting component that enables you to read and write Excel® spreadsheets without utilizing Microsoft Excel® installed either on the client or server side. Aspose.Cells is a feature rich component that offers much more than just basic exporting of data. With Aspose.Cells , developers can export data, format spreadsheets in every detail and at every level, import images, import charts, create charts, manipulate charts, stream Excel® data, save in various formats including XLS, CSV, PDF, SpreadsheetML, TabDelimited, TXT, XML ( Aspose.Pdf integrated) and many more. Aspose.Cells has a huge list of features. Please take a look over the following code snippet for this approach.



Converting the XLS file to PDF Format





 using System;using System.IO;usingSystem.Windows.Forms;usingAspose.Cells; namespace AsposeExcel2PdfConverter{    /// <summary>    /// AsposeExcel2PdfConverter    /// Use Aspose.Cells to perform the task    /// </summary>class Class1    {        /// <summary>        /// The main entry point for the application.        /// </summary>        [STAThread]static void Main(string[] args)        {try            {                // Uncomment the code below when you have purchased                // license for Aspose.Cells. You need to                // deploy the license in the same folder as your                // executable, alternatively you can add the license                // file as an embedded resource to your project.                // // Set license for Aspose.Cells                // Aspose.Cells.LicensecellsLicense = new                // Aspose.Cells.License();                // cellsLicense.SetLicense("Aspose.Cells.lic");                 //Get the path of the Application folder.string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "..\\..");                //Get the template excel file path.stringdesignerFile = path + @"\Files\PurchasingReport.xls";                //Specify the pdf file path.stringpdfFile = path + @"\Files\PurchasingReport.pdf";                //Create a new Workbook.                //Open the template excel file which you have toAspose.Cells.Workbookwb = new Aspose.Cells.Workbook(designerFile);                //Save the pdf file.wb.Save(pdfFile, SaveFormat.Pdf);             }catch (Exception e)            {Console.WriteLine(e.Message);Console.ReadLine();             }        }    }}





  Imports SystemImports System.IOImports System.Windows.FormsImports Aspose.Cells 'AsposeExcel2PdfConverter'Use Aspose.Cells to perform the taskModule Module1     Sub Main()         Try ' Uncomment the code below when you have purchased license' forAspose.Cells. You need to deploy the' license in the same folder as your executable, alternatively' you can add the license file as an embedded resource to your' project.' ' Set license for Aspose.Cells' DimcellsLicense As Aspose.Cells.License = New' Aspose.Cells.License()' cellsLicense.SetLicense("Aspose.Cells.lic")             'Get the path of the Application folder.            Dim path As String = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "..\")            'Get the template excel file path.            Dim designerFile As String = path + "\Files\PurchasingReport.xls"            'Specify the pdf file path.            Dim pdfFile As String = path + "\Files\PurchasingReport.pdf"            'Create a new Workbook.            'Open the template excel file which you have to convert            Dim wb As Aspose.Cells.Workbook = New Aspose.Cells.Workbook(designerFile)            'Save the pdf file.wb.Save(pdfFile, SaveFormat.Pdf)          Catch e As ExceptionConsole.WriteLine(e.Message)Console.ReadLine()         End Try     End Sub  End Module 



More about Aspose Components



- Homepage of Aspose.Cells for .NET:


- Download Aspose.Cells for .NET:


- Read More Technical Tips by Aspose.Cells for .NET: