简体   繁体   English

js-xlsx 中的货币格式

[英]currency format in js-xlsx

I'm using js-xlsx/xlsx.js library to export data to excel.我正在使用 js-xlsx/xlsx.js 库将数据导出到 excel。 https://github.com/SheetJS/js-xlsx https://github.com/SheetJS/js-xlsx

It works well except the formatting part for currency.除了货币的格式化部分,它运行良好。

I used {v:12.34, z: '0.00%'} for percentage formatting, it works fine.我使用 {v:12.34, z: '0.00%'} 进行百分比格式,它工作正常。

But when I use {v:1234.56, z :'$0.00'} for currency, then it does not work.但是当我使用 {v:1234.56, z :'$0.00'} 作为货币时,它就不起作用了。 No currency formatting in the export file.导出文件中没有货币格式。

Can anyone help me with this?谁能帮我这个? Thanks!谢谢!

I had the same issue and ended up using a forked version of the repo that has made some advancements in terms of formatting: https://github.com/protobi/js-xlsx我遇到了同样的问题,最终使用了 repo 的分叉版本,该版本在格式方面取得了一些进步: https : //github.com/protobi/js-xlsx

Instead of using the z property of the cell, include the following: {v: 42145.822, s: { numFmt: "m/dd/yy"}}不使用单元格的z属性,而是包含以下内容: {v: 42145.822, s: { numFmt: "m/dd/yy"}}

Check out https://github.com/protobi/js-xlsx#cell-object for more detail.查看https://github.com/protobi/js-xlsx#cell-object了解更多详情。

We can simply use the formatting syntax Excel uses, eg $ ###,### :我们可以简单地使用 Excel 使用的格式语法,例如$ ###,###

XLSX.SSF.format('$#,##0.00', 12345.6789)

Instead of using the .z property of the cell, include the following:不使用单元格的.z属性,而是包含以下内容:

{v: 42145.822, s: { numFmt: "$#,###.00"}} 

See this old issue: https://github.com/SheetJS/js-xlsx/issues/158看到这个老问题: https : //github.com/SheetJS/js-xlsx/issues/158

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM