Dynamic height and weight in table



  • I tried your solution:

    {
      template: {
      content: dataContent,
      recipe: 'xlsx',
      engine: "handlebars",
      phantom: optionsPhantom,
      xlsxTemplate: {
         shortid: idXLSXTemplate
      },
      "helpers": "function hackMerge(fileName, path, opts) {\n    \/\/ workaround for this bug\n    \/\/ https:\/\/github.com\/jsreport\/jsreport-xlsx\/issues\/20\n    opts.data.root.$xlsxTemplate[fileName].hack = function () {\n        return new Function('obj', 'return obj' + path)(opts.data.root.$xlsxTemplate[fileName]);\n    }\n    \n    xlsxMerge.call(this, fileName, 'hack()', opts)\n}"
      },
      data : dataReport
    }
    

    And I get this error:

    Error during rendering report:

    Unexpected identifier evalmachine.<anonymous>:409
    function hackMerge(fileName, path, opts) { opts.data.root.$xlsxTemplate[fileName].hack = function () { return new Function('obj', 'return obj' + path)(opts.data.root.$xlsxTemplate[fileName]); } xlsxMerge.call(this, fileName, 'hack()', opts) }
                                                                                                                                                                                                      ^^^^^^^^^
    SyntaxError: Unexpected identifier
    
    xlsXmerge it´s not declared
    


  • Did you alter the default jsreport server configuration? What you have in tasks.strategy ?



  • I have not altered the default jsreport server configuration and my tasks.strategy file is empty.



  • Hm, it works for me...
    Can you run like this other helpers, for example in html recipe?
    What jsreport version you have?
    Do you send the json correctly escaped?
    Maybe you could add a console.log(request.template.helpers) here to see if jsreport gets what you expect https://github.com/jsreport/jsreport-templates/blob/master/lib/templates.js#L76



  • btw the latest release of jsreport includes fix for complex paths in xlsx helpers. So you can use standard xlsxMerge there.



  • Hello:

    Thank you very much for your help.

    I solved the error, it was silly. Attribute "helpers" in the API call work correctly. The error was in the string content of the attribute "helpers." You and I put:

    "function hackMerge(fileName, path, opts) { opts.data.root.$xlsxTemplate[fileName].hack = function () { return new Function('obj', 'return obj' + path)(opts.data.root.$xlsxTemplate[fileName]); } xlsxMerge.call(this, fileName, 'hack()', opts) }"
    

    And the correct way is:

    "function hackMerge(fileName, path, opts) { opts.data.root.$xlsxTemplate[fileName].hack = function () { return new Function('obj', 'return obj' + path)(opts.data.root.$xlsxTemplate[fileName]); };  xlsxMerge.call(this, fileName, 'hack()', opts) }" 
    

    With special attention to semicolon (";") before the if-else statement.

    I have worked very hard creating tables in JSReport. I have created an adapted example for anyone who has the same needs as I did. The example is this (https://playground.jsreport.net/studio/workspace/HyqJPOI3x/21).



  • Ah, I can imagine this was easy to overlook. Glad you found it in the end.

    Btw here you can find how to do code highlights for your next posts
    https://help.github.com/articles/creating-and-highlighting-code-blocks/



  • Code highlighted ;-)



  • Hello:

    One question more. Now, I want do a report with bars and lines in the graph. I am triying this (https://playground.jsreport.net/studio/workspace/HyqJPOI3x/23). Any ideas?



  • Try to click Download in the Run context and open it in the excel. It will fix the xml and gives you protocol where you find what was wrong.


Log in to reply
 

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