Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用loop-in-cloud函数将json数据呈现到DOCX表中_Javascript_Node.js_Reactjs_Google Cloud Functions_Docx - Fatal编程技术网

Javascript 使用loop-in-cloud函数将json数据呈现到DOCX表中

Javascript 使用loop-in-cloud函数将json数据呈现到DOCX表中,javascript,node.js,reactjs,google-cloud-functions,docx,Javascript,Node.js,Reactjs,Google Cloud Functions,Docx,这是一段代码,其中我们为申请者提供json,表标题为value,索引为key。 我得到了这个错误:---- TypeError:无法读取新表({… 此方法用于从json数据添加表行: createNewRow = (title,index) => { return new TableRow({ children:[ new TableCell({ children: [

这是一段代码,其中我们为申请者提供json,表标题为value,索引为key。 我得到了这个错误:----
TypeError:无法读取新表({…

此方法用于从json数据添加表行:


    createNewRow = (title,index) => {
      return new TableRow({
              children:[
                new TableCell({
                  children: [
                    new Paragraph({
                      text:index,
                      // heading:HeadingLevel.HEADING_1,
                    }),
                  ],
                  verticalAlign: VerticalAlign.LEFT
                }),
                new TableCell({
                  children: [
                    new Paragraph({
                      text:title,
                      // heading:HeadingLevel.HEADING_1,
                    }),
                  ],
                  verticalAlign: VerticalAlign.LEFT
                }),
              ]
            })
    }

创建表方法:


    createDataTable = (applicantData) => {
      console.log("recived data"+applicantData);
      return new Table({
        width: {
            size: 4535,
            type: WidthType.DXA,
        },
        rows:[
          Object.entries(applicantData).forEach(([key, value]) => {
            console.log("key "+key+"\tvalue "+value);
            createNewRow(value,key);
          })
        ]
      });
    }

这是云的主要功能


    exports.genrateDOCXFile = functions.https.onRequest(async (req, res) => {
        res.set("Access-Control-Allow-Origin", "*");
        var applicantData = req.body.applicantData;
        // var phoneNum = req.body.phoneNumber;
        // var db = admin.firestore();
        console.log("applicantData:"+applicantData);
    
        const doc = new Document({
            sections: [{
                properties: {},
                children: [
                    new Paragraph({
                      alignment: AlignmentType.CENTER,
                      heading:HeadingLevel.HEADING_1,
                      children: [
                            new TextRun({
                                text: "Satya Financing Agency",
                                bold: true,
                                underline: {
                                    type: UnderlineType.DOUBLE,
                                    color: "990011",
                                },
                                allCaps: true,
                            }),
                        ],
                    }),
                    createDataTable(applicantData),
                ],
            }],
        });
    
        const b64string = await Packer.toBase64String(doc);
        
        res.setHeader('Content-Disposition', 'attachment; filename=My Document.docx');
        res.send(Buffer.from(b64string, 'base64'));
    
    });