shit !
使用 node-xlsx 写入组装好的数据到excel中,始终报错,报错信息如下:
(node:6357) UnhandledPromiseRejectionWarning: TypeError: n.indexOf is not a function
at /Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15693:8
at Array.forEach (<anonymous>)
at check_ws_name (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15692:11)
at /Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15701:3
at Array.forEach (<anonymous>)
at check_wb_names (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15700:4)
at check_wb (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15713:2)
at Object.writeSync [as write] (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:21998:2)
at Object.build (/Users/mac/project/reptile/invoice/node_modules/node-xlsx/lib/index.js:77:33)
at writeXlsx (/Users/mac/project/reptile/invoice/index.js:269:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6357) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:6357) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
提示中没有什么有用信息,只能先用 node-xlsx 读入正常的excel 表格成JSON,再用这个正常的JOSN和自己组装的JSON进行对比。然鹅,并没有发现有什么不同
。
再仔细对比终于发现了问题,原因就是 excel每张表格的表名只能是字符串
,
let obj = {
name: more.tatalAmount, // 这里得到的名称是 Number,必须用toString()转成String
data: [
[
"111111111"
],