NB. While primarily looking for an answer relating to the xlsx package (as it seems to be vastly suggested and discussed), I fear that it might be impossible. So, I'm also open to going in another direction (as long as it's free and works for Angular/Excel).
I've found xlxs and I'm producing Excel formatted files. I'd like to control a bit of the style so I added the property s to a cell as suggested in the comments (code sample here).
testMagic() {
const table = document.getElementById("donkey");
const workBook = XLSX.utils.table_to_book(table);
workBook.Sheets.Sheet1.A1.s = { font: { bold: true } };
XLSX.writeFile(workBook, "wonkey.xlsx");
}
I see no difference in the downloaded file, though. I've googled the issue but the combo Angular and xlsx and styling isn't commonly blogged.
I'm hoping it's something rather easy to resolve that I'm missing due to confusion and ignorance.
I think you are using community(free) version of XLSX package. And the cell styling and other additional features to modify cell formats are only available in Pro version of the library. Please check here.
You can check official information here.
This is the community version. We also offer a pro version with performance enhancements, additional features like styling, and dedicated support.
P.S.- An alternative option to update the excel sheet and format the cells, use the exceljs npm package. you can see more details about styling here. See the example here(StackBlitz).
This answer is a bit irrelevant to the question description but makes sense under this question title.
If you are wondering how to format a cell into the category 'text' since your data is automatically changing formats (number to date / phone number to exponential), then there is a parameter that can help while instantiating the Worksheet
raw:boolean
Use as:
const worksheet: XLSX.WorkSheet=XLSX.utils.table_to_sheet(tableElement, {raw:true});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With