xlsx error



  • Hi, I'm doing a report for excel (xlsx), but when it was executed with json, I get the following error:

    Error while executing templating engine. Cannot read property 'xl/worksheets/sheet7.xml' of undefined. Error on line 199:42.
    
      197 | 
      198 |   function add (filePath, xmlPath) {
    > 199 |     var obj = this.ctx.root.$xlsxTemplate[filePath]
          |                                          ^
      200 |     var collection = safeGet(obj, xmlPath)
      201 | 
      202 |     var xml = escape(this.tagCtx.render(this.ctx.data).trim(), this.ctx.root)
    
    
    TypeError: Cannot read property 'xl/worksheets/sheet7.xml' of undefined
        at Object.add (evaluate-template-engine-helpers.js:199:42)
        at Object.<anonymous> (evaluate-template-engine-helpers.js:429:17)
        at eval (eval at createFunctionContext (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:257:23), <anonymous>:6:91)
        at prog (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/runtime.js:221:12)
        at execIteration (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:51:19)
        at Object.<anonymous> (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:61:13)
        at Object.eval [as main] (eval at createFunctionContext (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:257:23), <anonymous>:5:34)
        at main (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
        at ret (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
        at ret (/home/marlon/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
    

    My code is this:

    {{#each informe}}
    
    {{#xlsxAdd "xl/worksheets/sheet7.xml" "worksheet.sheetData[0].row"}}  
    <row >  
        <c t="inlineStr"><is><t>{{empaque}}</t></is></c>  
        <c t="inlineStr"><is><t>{{zona}}</t></is></c>  
      
    </row>  
    {{/xlsxAdd}}  
    {{/each}}
    {{{xlsxPrint}}}
    
    

    I uploaded a jsreport template



  • Please share playground demo.

    It is just a guess but...
    It seems something is cleaning input req.data where xlsx is storing parsed document. Maybe a custom script.
    Make sure you always extend the input data instead of assigning it.

    function beforeRender(req, res) {
      req.data = Object.assign({}, req.data, {foo: "foo"})
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.