Home > Code > C# > Excel XLS Document Conversion to PDF File inside .NET Applications

Excel XLS Document Conversion to PDF File inside .NET Applications

by sher azam   on Sep 17, 2013   Category: C#   |  Views: 2530    |  Points: 25   |  Gold 


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 analyses 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

[C#]

using System;
using System.IO;
using System.Windows.Forms;
using Aspose.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.License cellsLicense = 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.
string designerFile = path + @"\Files\PurchasingReport.xls";
//Specify the pdf file path.
string pdfFile = path + @"\Files\PurchasingReport.pdf";
//Create a new Workbook.
//Open the template excel file which you have to
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(designerFile);
//Save the pdf file.
wb.Save(pdfFile, SaveFormat.Pdf);

}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();

}
}
}
}

[VB]


Imports System
Imports System.IO
Imports System.Windows.Forms
Imports Aspose.Cells

'AsposeExcel2PdfConverter
'Use Aspose.Cells to perform the task
Module Module1

Sub Main()

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
' Dim cellsLicense 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 Exception
Console.WriteLine(e.Message)
Console.ReadLine()

End Try

End Sub

End Module

More about Aspose Components

- Homepage of Aspose.Cells for .NET: http://www.aspose.com/.net/excel-component.aspx

- Download Aspose.Cells for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/default.aspx



Post Code  |  Code Snippet Home

User Responses


  Re :Excel XLS Document Conversion to PDF File inside .NET Applications   
Posted by Tamara
on 29/10/2013
Points : 5

Read this blog about how you can compress images added in spreadsheet and then convert excel file to pdf i found this blog very interesting :

http://www.aspose.com/blogs/aspose-products/aspose-cells-product-family/archive/2013/10/23/resampling-of-the-images-in-excel-to-pdf-conversion-supported-along-with-other-valuable-enhancements-included-in-aspose.cells-for-.net-7.6.0.html

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts