Convert MS Excel XLS/XLSX to HTML using C#

excel to html C#

Excel to HTML conversion could be useful in various scenarios such as converting sheets to web pages or embedding the content of the sheets within the web applications and so on. In this article, you will learn how to convert MS Excel (XLS/XLSX) files to HTML using C#. Furthermore, you will come to know how to use additional options to customize the Excel to HTML conversion.

Excel to HTML C# API

Aspose.Cells for .NET is a well-known spreadsheet manipulation API that lets you create, read, and modify the Excel files without MS Office. The API also provides a built-in spreadsheet converter that allows you to convert Excel worksheets to HTML files with high fidelity. You can download the API or install it within your application using NuGet.

PM> Install-Package Aspose.Cells

Convert Excel to HTML using C#

Excel to HTML conversion can be achieved within a couple of lines of code. Just load the Excel file and save it with .html extension. The following are the steps to perform this operation.

The following code sample shows how to convert XLS/XLSX file to HTML using C#.

Enable Tooltips in Excel to HTML Conversion

There might be the case when the text’s length exceeds the width of cells in the worksheets. In such a scenario, the text gets cut off in the converted HTML file. To tackle this issue, Aspose.Cells for .NET provides the option for enabling tooltips in the HTML file. The following are the steps to do so.

The following code sample shows how to enable tooltips in Excel to HTML conversion in C#.

Use Presentation Preference in Excel to HTML Conversion

Aspose.Cells for .NET provides HtmlSaveOptions.PresentationPreference property that makes you enhance the rendering of the spreadsheet’s layout in the resultant HTML file. In other words, it is used to get a more attractive presentation of Excel workbooks.

The following code sample shows how to enhance the presentation of Excel files.

Conclusion

In this article, you have learned how to convert Excel files to HTML using C#. Furthermore, you have seen how to enable tooltips and presentation preference options in XLS/XLSX to HTML conversion. You can read more about Aspose.Cells for .NET using documentation.

See Also