GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Convert Excel files to HTML in C# and VB.NET

GemBox.Spreadsheet allows you to save an Excel workbook or worksheet in HTML or MHTML format.

The following example shows how to convert an Excel file to HTML in C# and VB.NET.

Note the use of HtmlSaveOptions to set the worksheet options that are supported when saving an Excel file in HTML format. The example demonstrates saving of an entire Excel workbook and all its images in HTML format.

Since worksheet files must be physically saved on a disk, the following example cannot be run interactively from the Sample Explorer.

Input file: HtmlExport.xlsx.

Screenshot
Html Export Screenshot

See the full code below.

using System;
using System.Collections.Generic;
using System.Text;
using GemBox.Spreadsheet;
using GemBox.Spreadsheet.ConditionalFormatting;
using GemBox.Spreadsheet.PivotTables;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        ExcelFile ef = ExcelFile.Load("HtmlExport.xlsx");

        var ws = ef.Worksheets[0];

        // Some of the properties from ExcelPrintOptions class are supported in HTML export.
        ws.PrintOptions.PrintHeadings = true;
        ws.PrintOptions.PrintGridlines = true;

        // Print area can be used to specify custom cell range which should be exported to HTML.
        ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("A1", "I42"));

        HtmlSaveOptions options = new HtmlSaveOptions()
        {
            HtmlType = HtmlType.Html,
            SelectionType = SelectionType.EntireFile
        };

        ef.Save("HtmlExport.html", options);
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports GemBox.Spreadsheet
Imports GemBox.Spreadsheet.ConditionalFormatting
Imports GemBox.Spreadsheet.PivotTables

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim ef = ExcelFile.Load("HtmlExport.xlsx")

        Dim ws = ef.Worksheets(0)

        ' Some of the properties from ExcelPrintOptions class are supported in HTML export.
        ws.PrintOptions.PrintHeadings = True
        ws.PrintOptions.PrintGridlines = True

        ' Print area can be used to specify custom cell range which should be exported to HTML.
        ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("A1", "I42"))

        Dim options = New HtmlSaveOptions() With { _
                .HtmlType = HtmlType.Html, _
                .SelectionType = SelectionType.EntireFile _
            }

        ef.Save("HtmlExport.html", options)

    End Sub

End Module

Check next sample.