Export Html Tables To Excel Worksheet In C Sharp

Sample date Updated on Apr 10, 2026
excel excel-library html-tables html-to-excel xlsio

This repository provides examples of exporting HTML tables into Excel worksheets using Syncfusion XlsIO in a C# ASP.NET Core environment. The project demonstrates two main scenarios: importing HTML table content directly from a web page and importing HTML tables from an existing HTML file stored in the application’s web root. In both cases, the imported table data is automatically formatted into an Excel worksheet and returned to the client as a downloadable Excel file.

The repository includes controllers that handle user input, process HTML table strings or files, and generate Excel workbooks with the imported data. One example shows how to accept HTML table content as a string parameter, convert it into a byte stream, and import it into the worksheet starting at the first row and column. Another example demonstrates how to read an HTML file (Import-HTML-Table.html) from the project’s web root path, import the table, and save the result as an Excel file (Import-HTML-Table.xlsx). Both approaches apply auto-fit operations to rows and columns to ensure clean formatting in the generated workbook. The repository structure is straightforward, with controllers containing action methods that instantiate the Excel engine, create workbooks, access worksheets, and call the ImportHtmlTable method to bind HTML table content. The output files are returned to the client as downloadable Excel documents, making it easy to transform web-based tabular data into professional Excel reports. This project serves as a reference for developers who want to automate the conversion of HTML tables into Excel worksheets in C#, providing a reliable and efficient solution for exporting structured data. By following the examples, developers can adapt the approach to their own applications, ensuring that HTML tables are quickly and accurately transformed into Excel files with consistent formatting and layout.

Up arrow