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 Example Explorer.

Screenshot of HTML converted from Excel file with GemBox.Spreadsheet
HTML converted from Excel file with GemBox.Spreadsheet
using GemBox.Spreadsheet;

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

        var workbook = ExcelFile.Load("%#HtmlExport.xlsx%");

        var worksheet = workbook.Worksheets[0];

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

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

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

        workbook.Save("HtmlExport.html", options);
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

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

        Dim workbook = ExcelFile.Load("%#HtmlExport.xlsx%")

        Dim worksheet = workbook.Worksheets(0)

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

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

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

        workbook.Save("HtmlExport.html", options)
    End Sub
End Module

Check next example or download examples from GitHub.