Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at validateString (internal/validators.js:117:11) at Object.basename (path.js:1156:5) at new Picture (/var/user/node_modules/excel4node/distribution/lib/drawing/picture.js:55:89) at DrawingCollection.add (/var/user/node_modules/excel4node/distribution/lib/drawing/index.js:22:34) at Worksheet.addImage (/var/user/node_modules/excel4node/distribution/lib/worksheet/worksheet.js:268:51) at /var/user/index.js:107:8 at Array.forEach (<anonymous>) at Runtime.exports.main [as handler] (/var/user/index.js:77:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) (callId: 1650792911572-0.21096792130201525) (trace: 17:35:11 start->17:35:13 system error (Error: errCode: -504002 functions execute fail | errMsg: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at validateString (internal/validators.js:117:11) at Object.basename (path.js:1156:5) at new Picture (/var/user/node_modules/excel4node/distribution/lib/drawing/picture.js:55:89) at DrawingCollection.add (/var/user/node_modules/excel4node/distribution/lib/drawing/index.js:22:34) at Worksheet.addImage (/var/user/node_modules/excel4node/distribution/lib/worksheet/worksheet.js:268:51) at /var/user/index.js:107:8 at Array.forEach (<anonymous>) at Runtime.exports.main [as handler] (/var/user/index.js:77:13) at processTicksAndRejections (internal/process/task_queues.js:97:5)), abort) at C (http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:658323) at http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:684615 at http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:46812 at n (http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:23689)
//这个例子有导出图片功能 const xl = require('excel4node') exports.main = async (event) => { // create a new instance of a Workbook class const wb = new xl.Workbook() // cdd Worksheets to the workbook const ws = wb.addWorksheet('列表') { //for循环填充行列数据i和j,自己编吧,这里仅用花括号意思一下 //i循环里,设定行高,控制图片显示大小 ws.row(i + 1).setHeight(65) //j循环里,把图片插在第一列 let res = await cloud.downloadFile({ fileID }) let image = res.fileContent ws.addImage({ image, type: 'picture', position: { type: 'twoCellAnchor', from: { col: j + 1, colOff: 0, row: i + 1, rowOff: 0, }, to: { col: j + 2, colOff: 0, row: i + 2, rowOff: 0, }, }, }) } const buffer = await wb.writeToBuffer() const resFile = await cloud.uploadFile({ cloudPath: cloudPath, fileContent: buffer }) }
文档在这里:https://github.com/natergj/excel4node
at validateString (internal/validators.js:117:11)
at Object.basename (path.js:1156:5)
at new Picture (/var/user/node_modules/excel4node/distribution/lib/drawing/picture.js:55:89)
at DrawingCollection.add (/var/user/node_modules/excel4node/distribution/lib/drawing/index.js:22:34)
at Worksheet.addImage (/var/user/node_modules/excel4node/distribution/lib/worksheet/worksheet.js:268:51)
at /var/user/index.js:107:8
at Array.forEach (<anonymous>)
at Runtime.exports.main [as handler] (/var/user/index.js:77:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5) (callId: 1650792911572-0.21096792130201525) (trace: 17:35:11 start->17:35:13 system error (Error: errCode: -504002 functions execute fail | errMsg: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:117:11)
at Object.basename (path.js:1156:5)
at new Picture (/var/user/node_modules/excel4node/distribution/lib/drawing/picture.js:55:89)
at DrawingCollection.add (/var/user/node_modules/excel4node/distribution/lib/drawing/index.js:22:34)
at Worksheet.addImage (/var/user/node_modules/excel4node/distribution/lib/worksheet/worksheet.js:268:51)
at /var/user/index.js:107:8
at Array.forEach (<anonymous>)
at Runtime.exports.main [as handler] (/var/user/index.js:77:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)), abort)
at C (http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:658323)
at http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:684615
at http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:46812
at n (http://127.0.0.1:16367/appservice/__dev__/WAService.js?t=wechat&s=1650785945374&v=2.23.4:2:23689)
//这个例子就差个导出图片的功能 const cloud = require('wx-server-sdk') //这里最好也初始化一下你的云开发环境 cloud.init() const db = cloud.database() const xlsx = require('node-xlsx');//引入npm exports.main = async (event, context) => { //查询要生成表格的数据 const dataList = await db.collection("bhds").where({ kdid: event.kdid, sssj:event.sssj, }).limit(1000).get() //获取数据 const data = dataList.data //获取创建工作簿 let sheet = [] //设置表头名称 let title = ['图片','商家代号','款号', '商品名称', '颜色', '均码','XS','S','M','L','XL','XXL','XXXL','总数','拿货价',] await sheet.push(title) //循环写入数据 for (let rowIndex in data) { let rowcontent = [] rowcontent.push(data[rowIndex].cpimg[0]+'/sf2') rowcontent.push(data[rowIndex].sssj) rowcontent.push(data[rowIndex].hh) rowcontent.push(data[rowIndex].cpname) rowcontent.push(data[rowIndex].color) rowcontent.push(data[rowIndex].jm) rowcontent.push(data[rowIndex].xs) rowcontent.push(data[rowIndex].s) rowcontent.push(data[rowIndex].m) rowcontent.push(data[rowIndex].l) rowcontent.push(data[rowIndex].xl) rowcontent.push(data[rowIndex].xxl) rowcontent.push(data[rowIndex].xxxl) rowcontent.push(data[rowIndex].zs) rowcontent.push(data[rowIndex].cbj) await sheet.push(rowcontent) } //生成文件 const buffer = await xlsx.build([{ name: event.nhmc+event.nazt, data: sheet }]) //上传文件到云存储 return await cloud.uploadFile({ cloudPath: 'nhb/' +event.sssjs+ event.nhmc+event.nazt + Date.now() + '.xlsx', fileContent: buffer, }) }