传入的数据
内容1
内容2
云函数:
const cloud = require('wx-server-sdk')
const nodeExcel = require('excel-export');
const path = require('path');
cloud.init({
env: "lghcloud2-fnker",
traceUser: true
})
const db = cloud.database({ env: "lghcloud2-fnker"})
// 云函数入口函数
exports.main = async (event, context) => {
if(event.type=='publish'){
var tableMap = {
styleXmlFile:path.join(__dirname,"styles.xml"),
name: Date.now()+"-export",
cols: [],
rows: [],
}
var tableHead = event.dataHead;
//添加表头
for(var i=0;i<tableHead.length;i++){
tableMap.cols[tableMap.cols.length]={
caption:tableHead[i],
type:'string'
}
}
//表体:伪数据
var MtableList = event.Mdatalist
var assMtableList = event.assMdatalist
//添加每一行数据
if(MtableList.length>=assMtableList.length){
for(let i=0;i<assMtableList.length;i++){
tableMap.rows[tableMap.rows.length]=[
MtableList[i].process,
MtableList[i].pieceRate,
assMtableList[i].assprocess,
assMtableList[i].asspieceRate,
]
}
for(let i=assMtableList.length;i<MtableList.length;i++){
tableMap.rows[tableMap.rows.length]=[
MtableList[i].process,
MtableList[i].pieceRate,"",""
]
}
var name=event.bagname
//保存excelResult到相应位置
var excelResult = nodeExcel.execute(tableMap);
var filePath = "outputExcels";
var fileName = name + '.xlsx';
//图片上传到云存储
return await cloud.uploadFile({
cloudPath: path.join(filePath, fileName),
fileContent: new Buffer(excelResult,'binary')
}).then(res=>{
console.log(res.fileID);
return res;
}).catch(err=>{
});
}
}
}
老哥,你报错信息提示这个值找不到,你再看看你传入的参数。