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 XLSX or XLS 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
- Convert Excel to HTML using C#
- Enable Tooltips in Converted HTML using C#
- Use Presentation Preference in 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 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
Excel XLSX to HTML C# Conversion
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.
- Load the Excel XLS/XLSX file using Workbook class.
- Convert XLS/XLSX to HTML using Workbook.Save(String) method.
The following code sample shows how to convert XLS/XLSX file to HTML using C#.
C# XLSX to HTML – Enable Tooltips
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.
- Load the Excel file using Workbook class.
- Create an object of HtmlSaveOptions class.
- Enable tooltip using HtmlSaveOptions.AddTooltipText property.
- Save Excel file as HTML using Workbook.Save(String, HtmlSaveOptions) method.
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 XLSX and XLS files to HTML using C#. Furthermore, you have seen how to enable tooltips and presentation preference options in Excel to HTML conversion. You can read more about Aspose.Cells for .NET using documentation.