How to Convert Excel to HTML with C#

 For MS Excel is very powerful on managing data, people would like to use it to display data. We can send with E-mail or print to share an Excel file. But if we want to display data with webpage, how should we do?

Actually, a webpage is based on HTML. Therefore, we can convert Excel to HTML file and display data by using browser.

In this post, I want to introduce the way to convert Excel to HTML with C#. And I use a component, Spire.XLS to realize this function more quickly. So, I have added its dll file as reference in project at the beginning. 

The following steps shows details.

  1. Load file which we want to convert to HTML with workbook.LoadFromFile(). Then, initialize worksheet.
  2.  Save Excel to HTML by using sheet.SaveToHTML()
  3.  Launch the converted HTML file.

Main Coding:

using System;
using Spire.Xls;

namespace ExceltoHTML
{
    class toHTML
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@”D:\Work\My Documents\vip.xlsx”);

            //Initailize worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Save Excel to HTML
            sheet.SaveToHtml(“toHTML.html”);
            System.Diagnostics.Process.Start(“toHTML.html”);
        }
    }
}

Result Shown as Following:

___________________________________________________________________________________________

Click Here to LEARN MORE about Spire.XLS

Click Here to DOWNLOAD Spire.XLS

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

1 thought on “How to Convert Excel to HTML with C#”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s