.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Web Services >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

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

Posted By:Zarfishan       Posted Date: March 14, 2013    Points: 40    Category: Web Services    URL: http://www.dotnetspark.com  

This technical tip will show users how to convert xls file to pdf file using c# and vb.net.
 

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


     

Further Readings:

Responses
Author: sonfacesd         Company URL: http://www.dotnetspark.com
Posted Date: July 25, 2013

I used .NET barcode reader to read barcode in .NET program. It is very easy.
Author: cindy313         Company URL: http://www.dotnetspark.com
Posted Date: September 10, 2013

as for me,i used another .net barcode reader found on google.not bad!

Author: cindy313         Company URL: http://www.dotnetspark.com
Posted Date: September 15, 2013

here is the link
http://www.keepautomation.com/products/net_barcode_reader/

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend