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.
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 Sharp
- First, create a .NET Core Console app in Visual Studio, as shown in the following image.
- Then, install the latest Syncfusion.XlsIO.NET.Core NuGet package to your app.
- 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.
References
For more details, refer to Excel to HTML conversion using C# documentation and GitHub demo.
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 images, data tables, CSV, TSV, HTML, collections of objects, ODS, JSON, 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! ****
Top comments (0)