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

Microsoft Excel is taken as the ideal tool to display and calculate data. When displaying data, users would like to set format to beautify appearance, for example, font style, background color, borders etc.

However, if we want to present the data information as a table in webpage not Excel, how to do? Some people may choose to write HTML code manually to display. But if there is lots of data, the code will be complicated. So in order to meet this requirement more easily and quickly, people think of another method, to convert Excel to HTML. We can import data to Excel and format it at first and then convert it to HTML. If so, we can find that the well formatted data information can be shown as a table in webpage.

Following, I will introduce an easy method to convert Excel to HTML by using C#, VB.NET.

In my example, I use a .NET Excel component, Spire.XLS for .NET. Through it, we can invoke sheet.SaveToHTML(filename string) method directly to save the Excel file to HTML.

CODE:

C#

using Spire.Xls;

 

namespace ExceltoHTML

{

    class Program

    {

        static void Main(string[] args)

        {

            Workbook workbook = new Workbook();

            workbook.LoadFromFile(@”E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx”);

 

            Worksheet sheet = workbook.Worksheets[0];

            sheet.SaveToHtml(“xlsx2html.html”);

            System.Diagnostics.Process.Start(“xlsx2html.html”);

        }

    }

}

VB

Imports Spire.Xls

 

Namespace ExceltoHTML

    Friend Class Program

        Shared Sub Main(ByVal args() As String)

            Dim workbook As New Workbook()

            workbook.LoadFromFile(“E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx”)

 

            Dim sheet As Worksheet = workbook.Worksheets(0)

            sheet.SaveToHtml(“xlsx2html.html”)

            System.Diagnostics.Process.Start(“xlsx2html.html”)

        End Sub

    End Class

End Namespace

           

RESULT

DOWNLOAD Spire.XLS for .NET Here

Advertisements

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