Easily Convert Excel to HTML in 3 Steps With C#
Detailed Blog page Skeleton loader

TL;DR: Let’s see how to convert Excel to HTML using the Syncfusion .NET Excel Library in C#. This process allows you to transform Excel files into web-friendly HTML format, maintaining the structure, charts, and styling for easy integration into your website. The blog will guide you through setting up the Syncfusion package, reading an Excel file, and exporting it to HTML with all the necessary formatting.

Converting an Excel document to HTML is a practical way to make Excel data accessible and viewable on web platforms. HTML files retain the structure and layout of the original Excel file, enabling easy data sharing and display on websites.

The Syncfusion .NET Excel Library, also known as Essential XlsIO, is a robust tool that facilitates the smooth creation, reading, and editing of Excel documents using C#. It supports the creation of Excel documents from scratch, modification of existing Excel documents, data import and export, Excel formulas, conditional formats, data validations, charts, sparklines, tables, pivot tables, pivot charts, template markers, and much more.

Enjoy a smooth experience with Syncfusion’s Excel Library! Get started with a few lines of code and without Microsoft or interop dependencies.

The XlsIO supports converting a worksheet or entire workbook to HTML while preserving formatting, including styles, hyperlinks, images, and 2D charts. This ensures that the essential visual elements of the original Excel document are retained.

Let’s see how to convert an Excel document to an HTML file using the Excel Library in C#!

Note: Before proceeding, refer to the .NET Excel Library’s getting started documentation.

Steps to convert an Excel document to HTML using C#

  1. First, create a .NET Core Console app in Visual Studio, as shown in the following image.
    Create a .NET console app
  2. Then, install the latest Syncfusion.XlsIO.NET.Core NuGet package to your app.
    Install Syncfusion.XlsIO.Net.Core NuGet package
  3. Now, add the following code to convert an Excel document to an HTML file.
    using Syncfusion.XlsIO;
     
    namespace Excel_to_HTML
    {
        class Program
        {
            public static void Main(string[] args)
            {
                using (ExcelEngine excelEngine = new ExcelEngine())
                {
                    // Initialize Excel engine and application.
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Xlsx;
     
                    // Load an existing Excel file.
                    using (FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read))
                    {
                        IWorkbook workbook = application.Workbooks.Open(inputStream);
     
                        // Save the workbook as an HTML file.
                        using (FileStream outputStream = new FileStream("Output.html", FileMode.Create, FileAccess.Write))
                        {
                            workbook.SaveAsHtml(outputStream);
                        }
                    }
                }
            }
        }
    }

Refer to the following images.

Input Excel document
Input Excel document

 

Converting an Excel document to HTML using .NET Excel Library and C#
Converting an Excel document to HTML using .NET Excel Library and C#

References

For more details, refer to Excel to HTML conversion using C# documentation and GitHub demo.

Witness the possibilities in demos showcasing the robust features of Syncfusion’s C# Excel Library.

Conclusion

Thanks for reading! In this blog, we’ve explored how to convert an Excel document to an HTML file using C# and Syncfusion .NET Excel Library (XlsIO). The Excel Library also allows you to export Excel data to imagesdata tablesCSVTSVHTMLcollections of objectsODSJSON, and other file formats.

Feel free to try out this versatile .NET Excel Library and share your feedback in the comments section of this blog post!

These features can be viewed by our existing customers from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you! 

Don't settle for ordinary spreadsheet solutions. Switch to Syncfusion and upgrade the way you handle Excel files in your apps!

Related blogs

Be the first to get updates

Kurmitha Manickhaperumal

Meet the Author

Kurmitha Manickhaperumal

Kurmitha M has been a .NET developer at Syncfusion since 2022, specializing in the development of the XlsIO library for Excel-related tasks.