Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

.NETASP.NETC#ProductsSpire.XLS
Home›.NET›Using Spire.XLS

Using Spire.XLS

By SibeeshVenu
July 12, 2015
381
9
Share:

[toc]

Introduction

Hi I hope you all are fine. Today we are going to see a new product Spire.XLS which helps us to create, manipulate, convert EXCEL file to other formats and many more. This product has been introduced by the company E-Iceblue. I hope you have read my article of Spire.Doc. If you have not read it, I recommend you to read it here: Using Spire.Doc

Download source code

  • Using Spire XLS With Visual Studio
  • Background

    Always, managing excel files through code is a tough job for me. If you are also thinking the same, I h3ly recommend this product Spire.XLX from E-Iceblue. It made the task easier than ever. In this article I will show you the demo for converting the Excel files to other formats. I hope you will like it.

    Download the files

    You can always the needed files from here: Download Spire.XLS

    Install Spire.XLS

    I am using evaluation version with one month temporary license. There are free versions also available for spire.xls with some limitation. You can try that. Now click on the exe file after you extract the downloaded file. The installation will get started then.

    So Shall we start?

    Once you Installed, you are ready to go. We will start with a “Simple Windows Form ” Application. Before getting started, Please install Spire.XLs and Visual studio 2008 or above. I am using Visual Studio 2015 RC. I hope everything set ?

    Open your Visual Studio, click on New->Project->Select Visual C# (if you are good in C# or select Visual Basic) Project->Windows->Windows forms application->Name your project(I am naming it as Using SpireXLs)

    Using Spire XLS

    Now create a group box and a button in your form and name them :). Later, click on the button.

    Using Spire XLS

    Now right click on your project and click add reference, in the browse tab find out the folder in which you have installed spire xls. Usually it will be in the C:\Program Files\e-iceblue\Spire.Xls. Now just find your framework version from BIN folder and add Spire.xls.dll

    Using Spire XLS

    Using Spire XLS

    Now we have added reference too. So shall we start coding ?

    Using the code

    To start with coding you need to add the needed namespaces as follows.

    [csharp]
    using Spire.Xls;
    using Spire.Pdf;
    using Spire.Xls.Converter;
    [/csharp]

    In the button click event you need to add the following lines codes.

    C# Code

    [csharp]
    private void button1_Click(object sender, EventArgs e)
    {
    // load Excel file
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("D:\\MyExcel.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("MyPDF.pdf");
    System.Diagnostics.Process.Start("MyPDF.pdf");

    }
    [/csharp]

    VB.NET Code

    [csharp]
    ‘load Excel file
    Dim workbook As New Workbook()
    workbook.LoadFromFile("D:\MyExcel.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("MyPdf.pdf")
    System.Diagnostics.Process.Start("MyPdf.pdf")
    [/csharp]

    In the above lines code, we are loading an excel file MyExcel.xlsx from my drive. The following is the content of our excel file.

    Using Spire XLS

    Now if you run your project and click our button, you will get a pdf file as follows.

    Using Spire XLS

    Cool!. Very simple right? Now we will go to other conversions as well.

    Excel to HTML

    To convert our excel file to HTML, you need to create a button in our form and paste the following codes to the button click event.

    C# Code

    [csharp]
    private void button2_Click(object sender, EventArgs e)
    {
    //load Excel file
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("D:\\MyExcel.xlsx");
    //convert Excel to HTML
    Worksheet sheet = workbook.Worksheets[0];
    sheet.SaveToHtml("MyHTML.html");
    //Preview HTML
    System.Diagnostics.Process.Start("MyHTML.html");

    }
    [/csharp]

    VB.NET Code

    [csharp]
    Private Shared Sub Main(args As String())
    ‘load Excel file
    Dim workbook As New Workbook()
    workbook.LoadFromFile("D:\\MyExcel.xlsx")
    ‘convert Excel to HTML
    Dim sheet As Worksheet = workbook.Worksheets(0)
    sheet.SaveToHtml("MyHTML.html")
    ‘Preview HTML
    System.Diagnostics.Process.Start("MyHTML.html")
    End Sub
    [/csharp]

    Now if you run the code, you can see an html file as follows.

    Using Spire XLS

    Excel To Image

    To convert our excel file to image, you need to create a button in our form and paste the following codes to the button click event.

    C# Code

    [csharp]
    private void button3_Click(object sender, EventArgs e)
    {
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("D:\\MyExcel.xlsx");
    Worksheet sheet = workbook.Worksheets[0];
    sheet.SaveToImage("MyImage.jpg");

    }
    [/csharp]

    VB.NET Code

    [csharp]
    Shared Sub Main(ByVal args() As String)
    Dim workbook As New Workbook()
    workbook.LoadFromFile("D:\\MyExcel.xlsx")
    Dim sheet As Worksheet = workbook.Worksheets(0)
    sheet.SaveToImage("MyImage.jpg")
    End Sub
    [/csharp]

    Now if you run the code, you can see an Image as follows.

    Using Spire XLS

    Using Spire XLS

    Excel to CSV

    To convert our excel file to image, you need to create a button in our form and paste the following codes to the button click event.

    C# Code

    [csharp]
    private void button3_Click(object sender, EventArgs e)
    {
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("D:\\MyExcel.xlsx");
    Worksheet sheet = workbook.Worksheets[0];
    sheet.SaveToFile("MyCSV.csv", ",", Encoding.UTF8);

    }
    [/csharp]

    VB.NET Code

    [csharp]
    Shared Sub Main(ByVal args() As String)
    Dim workbook As New Workbook()
    workbook.LoadFromFile("D:\\MyExcel.xlsx")
    Dim sheet As Worksheet = workbook.Worksheets(0)
    sheet.SaveToFile("MyCSV.csv", ",", Encoding.UTF8)

    End Sub
    [/csharp]

    Now if you run the code, you can see a CSV file as follows.

    Using Spire XLS

    Please be noted that, you can convert your excel to any other file format, there are plenty of options available. Please try that too. I have given only three options which I use always.

    Conclusion

    Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

    Your turn. What do you think?

    A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

    Kindest Regards
    Sibeesh Venu

    TagsConvert Excel to PDFConvert Excel to PDF in C#Convert Excel to PDF in CSharpExcel to HTMLSpire.OfficeSpire.XLsUsing Spire.XLS
    Previous Article

    Copy contents to clipboard

    Next Article

    How To Show Or Hide Columns In ...

    0
    Shares
    • 0
    • +
    • 0
    • 0
    • 0

    SibeeshVenu

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

    Related articles More from author

    • .NETASP.NETC#ProductsSpire.XLSVB.Net

      Working With Charts Using Spire.XLS

      August 11, 2015
      By SibeeshVenu
    • JQWidgetsJQX Grid

      How to disable enter key in JQWidget JQX editable grid

      June 5, 2015
      By SibeeshVenu
    • .NETVideosVisual StudioVisual Studio 2017

      The Cool New Refactoring and Text Editor Options in VS2017

      April 2, 2017
      By SibeeshVenu
    • Order Filter Conditions In jQWidget JQX Grid
      JQWidgetsJQX GridProducts

      Order Filter Conditions In jQWidget JQX Grid

      October 20, 2015
      By SibeeshVenu
    • Test API Client Output With Response
      .NETSQLWeb API

      Working With Test Client In Asp Net Web API Help Page

      May 31, 2016
      By SibeeshVenu
    • Run_Command_With_regedit
      .NETASP.NETHow to

      How to find CLSID of a DLL

      January 21, 2016
      By SibeeshVenu
    0

    My book

    Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

    YouTube

    MICROSOFT MVP (2016-2022)

    profile for Sibeesh Venu - Microsoft MVP

    Recent Posts

    • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
    • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
    • Easily move data from one COSMOS DB to another
    • .NET 8 New and Efficient Way to Check IP is in Given IP Range
    • Async Client IP safelist for Dot NET
    • Post Messages to Microsoft Teams Using Python
    • Get Azure Blob Storage Blob Metadata Using PowerShell
    • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
    • Integrate Azure App Insights in 1 Minute to .Net6 Application
    • Azure DevOps Service Connection with Multiple Azure Resource Group

    Tags

    Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
    • .NET
    • Achievements
    • ADO.NET
    • Android
    • Angular
    • Arduino
    • Article Of The Day
    • ASP.NET
    • Asp.Net Core
    • Automobile
    • Awards
    • Azure
    • Azure CDN
    • azure devops
    • Blockchain
    • Blog
    • Browser
    • C-Sharp Corner
    • C#
    • Career Advice
    • Code Snippets
    • CodeProject
    • Cognitive Services
    • Cosmos DB
    • CSS
    • CSS3
    • Data Factory
    • Database
    • Docker
    • Drawings
    • Drill Down Chart
    • English
    • Excel Programming
    • Exporting
    • Facebook
    • Fun
    • Gadgets
    • GitHub
    • GoPro
    • High Map
    • HighChart
    • How to
    • HTML
    • HTML5
    • Ignite UI
    • IIS
    • Interview
    • IoT
    • JavaScript
    • JQuery
    • jQuery UI
    • JQWidgets
    • JQX Grid
    • Json
    • Knockout JS
    • Linux
    • Machine Learning
    • Malayalam
    • Malayalam Poems
    • MDX Query
    • Microsoft
    • Microsoft ADOMD
    • Microsoft MVP
    • Microsoft Office
    • Microsoft Technologies
    • Microsoft Windows
    • Microsoft Windows Server
    • Mobile
    • MongoDB
    • Monthly Winners
    • MVC
    • MVC Grid
    • MySQL
    • News
    • Node JS
    • npm
    • Number Conversions
    • October 2015
    • Office 365
    • Office Development
    • One Plus
    • Outlook
    • Page
    • PHP
    • Poems
    • PowerShell
    • Products
    • Q&A
    • Raspberry PI
    • React
    • SEO
    • SharePoint
    • Skype
    • Social Media
    • Software
    • Spire.Doc
    • Spire.PDF
    • Spire.XLS
    • SQL
    • SQL Server
    • SSAS
    • SSMS
    • Storage In HTML5
    • Stories
    • Third Party Software Apps
    • Tips
    • Tools
    • Translator Text
    • Uncategorized
    • Unit Testing
    • UWP
    • VB.Net
    • Videos
    • Virtual Machine
    • Visual Studio
    • Visual Studio 2017
    • Wamp Server
    • Web API
    • Web Platform Installer
    • Webinars
    • WebMatrix
    • Windows 10
    • Windows 7
    • Windows 8.1
    • Wordpress
    • Writing

    ABOUT ME

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

    Contact Me

    • info@sibeeshpassion.com

    Pages

    • About
    • Search
    • Privacy Policy
    • About
    • Search
    • Privacy Policy
    © Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
    Go to mobile version