Excel files are widely used to store and organize the data in the form of worksheets. Furthermore, you can perform various computations as well as analysis of the data. However, in certain cases, you have to convert the Excel files into other formats. For example, you may need to convert an Excel worksheet to HTML or image in order to display it within your web or desktop application. For such cases, this article covers how to convert Excel files to HTML in Node.js applications. In addition, you will learn how to use additional options to customize the converted HTML.
- Node.js Excel to HTML Converter API
- Convert Excel Files to HTML in Node.js
- Enable Gridlines in Excel to HTML Conversion
- Show Tooltip in Excel to HTML Conversion
- Include Hidden Sheets in Excel to HTML Conversion
- Get a Free API License
Node.js Excel to HTML Converter API
Aspose.Cells for Node.js via Java API is designed to implement spreadsheet automation from within your Node.js applications. It provides a range of features to manipulate Excel files seamlessly. Furthermore, the API allows you to convert Excel files to other formats. In order to use the API, you can download its package from the Downloads section or use the following NPM command.
> npm install aspose.cells
Convert Excel Files to HTML in Node.js
When converting an Excel file to HTML, Aspose.Cells for Node.js via Java creates a separate tab for each worksheet. Thus, you can navigate between the sheets quite easily. The following are the steps to convert an Excel file to HTML.
- Load Excel file using Workbook class.
- Save Excel file as HTML using Workbook.save(String) method.
The following code sample shows how to convert an Excel file to HTML using Node.js.
Excel File
Converted HTML
Enable Gridlines in Excel to HTML Conversion in Node.js
By default, the gridlines are disabled in the converted HTML file. However, you can enable them using the HtmlSaveOptions class. The following are the steps to perform this operation.
- Load XLSX file using Workbook class.
- Create an instance of HtmlSaveOptions class.
- Enable gridlines using HtmlSaveOptions.setExportGridLines(true) method.
- Save converted HTML using Workbook.save(String, HtmlSaveOptions) method.
The following code sample shows how to enable gridlines in Excel to HTML conversion.
Converted HTML
Enable Tooltip in XLSX to HTML Conversion in Node.js
In some cases, the values may exceed the width of the cells in a worksheet. In such situations, you can enable the tooltips to display complete text in the converted HTML. The following are the steps to enable tooltips in Excel to HTML conversion.
- Load Excel file using Workbook class.
- Create an instance of HtmlSaveOptions class.
- Use HtmlSaveOptions.setAddTooltipText(true) method to enable tooltip.
- Save Excel file as HTML using Workbook.save(String, HtmlSaveOptions) method.
The following code sample shows how to enable tooltip in Excel to HTML conversion in Node.js.
Include Hidden Sheets in XLS/XLSX to HTML Conversion
Excel workbooks may also contain the hidden sheets that are not included in Excel to HTML conversion by default. In order to render hidden sheets, you can use HtmlSaveOptions.setExportHiddenWorksheet() method. The following are the steps to perform this operation.
- Load XLSX file using Workbook class.
- Create an instance of HtmlSaveOptions class.
- Include hidden sheets using HtmlSaveOptions.setExportHiddenWorksheet(true) method.
- Save converted HTML using Workbook.save(String, HtmlSaveOptions) method.
The following code sample shows how to include hidden sheets in Node.js Excel to HTML conversion.
Get a Free API License
In case you want to try the API without evaluation limitations, you can get a free temporary license.
Conclusion
Excel to HTML conversion is often used in web applications to display worksheets on web pages. In accordance with that, this article has covered how to convert Excel workbooks to HTML files in Node.js. Furthermore, you have seen how to customize the Excel to HTML conversion with different options. You can explore more about Aspose.Cells for Node.js via Java using documentation.