[Error] While adding data in template



  • Hi Team,

    Can you help me in resolving this.
    https://playground.jsreport.net/studio/workspace/ry0peD8pl/658
    Unable to populate the data in excel.
    I require the same template format/design as per the needs.
    But when i m clearing all format it works.


  • administrators

    hi! after looking your xlsx template, the problem here is that you will need to insert rows before other rows that were created in the template in the first place, i've never tried that but it seems to me that you will need two things, insert your new rows with the correct indexes and after that, you will need to update the indexes of the previous rows that were there, basically you will need to implement a "move rows" logic, we don't have a specific helper at the moment that can help you with that but i think this can be done in combination with xlsxReplace and xlsxAdd. unfortunately i don't have too much time to try to implement it but if you can figure it out please share your solution with us, so we can analyze it and maybe in the future make it more easy for others.



  • ok i can take one more try with what you are reffering or if i can create the same template in js report with style ..if yes can you give me one example for styling the excel with jsreport

    Also how do i include helper function in my content.handlebar in my IDE code.In playground it works but locally in IDE it is not working.

    @bjrmatos any idea .


  • administrators

    the xlsx recipe lets you build the raw representation of an excel which is just a xml file, the format of this xml is called Office Open XML, so in order to apply styles you need to write the styles in the xml, here is a page that describes the format of the styles inside the xml. as you can see we just give you helpers to modify the xml, but since the Office Open XML allows you to do a lot of things we can't have an example for everything that is possible, but this will change with time and with the help of the community that explore the xlsx recipe and build excel files with it.

    here you have an small example of a conditional formatting, and also here is another topic in forum of another user that was trying to use styles too, maybe it can help.

    here is one advice from the xlsx docs:

    When you are lost, it is always good idea to create a test xlsx file in excel, unzip it and analyze its content. Another approach we recommend is to create the whole excel the first, upload it into jsreport and then only replace its data, which is simple.

    so you can try to apply the styles using the Excel program, then rename the excel from .xlsx to .zip and unzip it, then inspect how the xml definitions for the styles that you were using looks like.

    Also how do i include helper function in my content.handlebar in my IDE code.In playground it works but locally in IDE it is not working.

    i guess you are editing the sources files of your reports created by jsreport, in that case you should have a folder with the following structure.

    0_1524673648129_Captura de pantalla 2018-04-25 a las 11.27.16 a.m..png

    to add helpers to your handlebars template you should add the helpers functions in the helpers.js.

    here is an example of the content of the helpers.js file

    function now() {
        return new Date().toLocaleDateString()
    }
    
    function nowPlus20Days() {
        var date = new Date()
        date.setDate(date.getDate() + 20);
        return date.toLocaleDateString();
    }
    
    function total(items) {
        var sum = 0
        items.forEach(function (i) {
            console.log('Calculating item ' + i.name + '; you should see this message in debug run')
            sum += i.price
        })
        return sum
    }
    


  • Thanks @bjrmatos for very detailed answer on styles.(It worked for me after reading your refrences)

    Coming to helpers when i run my report with my local IDE code,the produced excel is not taking the helper function.

    I think my IDE is not taking the reference of helpers.js in handlebar.

    Do we need to add anything in config file or what.

    I'm stuck on this without helper function my work will not move.0_1524756181746_upload-e9e37333-5810-4bec-966f-83c4ec25c94f
    0_1524756219102_upload-13238699-76ab-4ebc-823b-6dee05c55923


  • administrators

    Do we need to add anything in config file or what.

    hmm no, when using the fs store the helper.js file is loaded automatically as long it is inside a template folder which is also inside data folder (the full path is like this data/templates/TemplateName/helper.js).

    what IDE is that? if you try starting the server from normal cli console (without IDE), does it work?



  • I'm using Webstorm ...

    if you try starting the server from normal cli console (without IDE), does it work? No it didnt but i tried on some other machine it was working.

    One more doubt,for sake if i have 2 Tables and data on these tables is dynamic as we dont know how many rows it will populate(based on the json data we get)
    0_1525064513637_upload-d87f4c86-a294-45a9-8415-da2e29b757d0

    How do i get to know the starting index of second table where i need to start entering the data.(with osme function in helper i mnot getting the actual index)

    Can you pleas help @administrators


  • administrators

    How do i get to know the starting index of second table where i need to start entering the data.(with osme function in helper i mnot getting the actual index)

    i think if your first table starts at, lets say 30 index, and if you have 20 items in your data, then your second table will start at 54 index, you just need to sum some values while you are passing the row index of second table.

    I'm using Webstorm ...
    if you try starting the server from normal cli console (without IDE), does it work? No it didnt but i tried on some other machine it was working.

    about this, i'm not sure why the helpers are not loading in your machine.. if it works in another machine, does the other machine have different OS than your machine? what OS is your machine using? do you see anything weird in the logs of jsreport when your helpers are not being taken? it will help if we can know more about the structure of your project, and your jsreport configuration file, can you zip the relevant files and folders of your project and send it to me? you can send the zip file to me at bjrmatos@gmail.com



  • Sure i will send u the zip.


Log in to reply
 

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