4/12/2012

How to Convert Excel to HTML with C#, VB.NET

HTML (Hyper-Text Mark-up Language) is one of the most frequently used formats for people to display pages and upload information on internet. Beside, every program makes HTML code, each program including Mozilla Firefox and Internet Explorer use the program to show information that is programmed to display. Thus, html is very important for cyber citizens.

HTML can be converted by many file formats, such as Word and Excel. Also HTML can be converted to Word and PDF. Using Spire.XLS, you can easily convert Excel to HTML.


How to convert Excel to HTML with C#,VB.NET

Besides converting excel to HTML, Excel also can be converted to PDF, XML, Image, CSV .etc by using Spire.XLS. Please look at the below procedure.


Procedure

1. Create a workbook.

2. Load an excel file from the system.

3. Save the excel file to HTML format and Launch it.


Main Code:

C# Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
namespace excel2html
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"C:\Program Files\e-iceblue\Spire.XLS\Demos\Data\employee.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToHtml("sample.html");
            System.Diagnostics.Process.Start("sample.html");
        }
    }
}


 
VB.NET Code:

Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Spire.Xls

Namespace excel2Html
        Class Program
               Shared Sub New(args As String())
                       Dim workbook As New Workbook()
                       workbook.LoadFromFile C:\Program Files\e-iceblue\Spire.XLS\Demos\Data\employee.xls")
                       Dim sheet As Worksheet = workbook.Worksheets(0)
                       sheet.SaveToHtml("sample.html")
               End Sub
        End Class
End Namespace



Preview

                                      


 Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.

Freely Download Spire.XLS



Source

2 comments:

  1. You can also use Aspose.Cells for .NET Library for converting excel files to HTML and you can use this Library to create, read and edit excel files also and convert excel file to many other formats.

    http://www.aspose.com/.net/excel-component.aspx

    ReplyDelete
  2. I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! this

    ReplyDelete