HtmlToXlsx(filename, [html]) Last updated: 10. Nov 2023

API only function

Converts a html table to an Excel file (XLSX).

Parameters

Name Type Description
filename string Specify output filename.
html (optional) string A string containing a table to convert from HTML to an Excel file (XLSX).
If not specified, the current output buffer (using the write method) will be used as table content.

Returns

An excel file in bytes.

• The title attribute of table is used as name for worksheet.
• Multiple tables (worksheets) are supported.
• Use style and styles "background-color" "color" to set cell style.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
// Use the write function to write to the output buffer
write('<table>');
write('<tr><th>Column1</th><th>Column2</th></tr>'); // headers
write('<tr><td>Row1Value1</td><td>Row1Value2</td></tr>'); // row 1
write('<tr><td>Row2Value1</td><td>Row2Value2</td></tr>'); // row 2
write('</table>');

return docly.HtmlToXlsx("test.xlsx");