使用SheetJs导出Excel设置指定单元格格式

var tbl = document.getElementById('sheetjs');
var wb = XLSX.utils.table_to_book(tbl);


var ws = wb.Sheets["Sheet1"]; //  get the current sheet
console.log(ws["A2"].v); //  default v value '4.56'

ws["A2"].z = "$0.00"; //  format the cell

delete ws["A2"].w; // delete old formatted text if it exists
XLSX.utils.format_cell(ws["A2"]); // refresh cell

console.log(ws["A2"].w); // new formatted cell '$4.56'

 

参考网址:

https://www.cnblogs.com/kaidarwang/p/9449815.html

https://docs.sheetjs.com/docs/api/utilities

https://stackoverflow.com/questions/53085906/xlsx-utils-table-to-book-currency-coming-as-general

 

posted @ 2022-10-11 16:53  追极  阅读(1400)  评论(0编辑  收藏  举报