protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
817 stars 417 forks source link

Write HTML to XLSX #61

Open ravelley opened 7 years ago

ravelley commented 7 years ago

Is it possible to embed HTML values? I have an API returning HTML for formatting purposes (list, strong text, etc.), which needs to be exported into Excel. I previously exported the HTML using the following code:

var html = document.getElementById(id).outerHTML;
if (window.navigator.msSaveOrOpenBlob) {
   var blobObject = new Blob([html]);
   window.navigator.msSaveOrOpenBlob(blobObject, filename)
} else {
   var link = $('<a id="download-xls"></a>');
   $('body').append(link);
   link.attr('href', 'data:application/vnd.ms-excel,' + encodeURIComponent(html));
   link.attr('download', filename);
   link[0].click();
}

This worked for the most part, except Excel understandably gave a security warning when opening the file.

Setting cell.v obviously does not work, and cell.h seems to only be used for reading. It seems like it may not be possible, but I want to make sure I haven't missed something.