Insert Data using Javascript inside Excel



  • Hi , the workflow which is happening is like this ,

    jsreport.serverUrl = 'http://loaclhost:5488';
                var request = {
                    template: {
                        shortid: "XXXXXX"
                    },
                    data: data
                };
                jsreport.render(request);      
     };
    

    when this triggers in the HTML i'll get the data , so how can i use it in the beforeRender function


  • administrators

    what is the object passed here data: data? what you pass there is what you will have available as req.data in your beforeRender function, so you need to have all the data that you need, available before calling jsreport.render(request), if you are sure you have the data already there, i will add a console.log(JSON.stringify(data)) before jsreport.render(request) and then check your console to inspect the variables, maybe you are not sending the values that you think



  • HI the data is the collection of all the form (HTML) data and i have checked it in the console and it's having all the data needed that used for the report.
    The main thing is , the values in the data generated only when the user fills the form and clicks submit button.
    so before that basically the value of the data is empty.

    Only at the time of rendering the report , i was mapping the user filled data to the corresponding excel cell . Now , since i have to slice it up before the render , it's getting complicated



  • Is JSReport has option to connect to mongoDB and build report based on the data present inside it ?


  • administrators

    Is JSReport has option to connect to mongoDB and build report based on the data present inside it ?

    yes, just like you can use nodemailer inside an script then you can use another library, like a database connector and use it. with that you can query your database normally inside the script and fill the data of your template by putting it into req.data.yourData = <your value from query here>



  • thanks
    other than this ( using beforeRender ) , any other way i can cut / slice the data ?


  • administrators

    sorry for late reply.. yes, you can define a helper and then call it directly in the template, so you won't need an script for that. here is the example (note that an script is still used but just for adding some data to the template)



  • @bjrmatos Hi, is there a way possible that i can use {{name}} (JSON object name) inside the javascript ( like we do in the HTML) inside the EXCEL , rather then the afterRender or beforeRender .
    The afterRender & beforeRender are very straightforward & best solution to many problems , but since i don't get the data , unless someone post the data` so this is the main problem.
    Any solution for this issue ?



  • This post is deleted!

  • administrators

    Hi, is there a way possible that i can use {{name}} (JSON object name) inside the javascript ( like we do in the HTML) inside the EXCEL , rather then the afterRender or beforeRender .

    do you mean to access name inside the helpers of template? if yes, then you can pass it explicetly to the helper (as a parameter) when using it from handlebars, like {{trimField name date}}. unlike scripts, helpers can not access all the data in single variable, you need to pass what you need as parameters if you want to do something with it.

    The afterRender & beforeRender are very straightforward & best solution to many problems , but since i don't get the data , unless someone post the data` so this is the main problem.

    sorry i'm getting confused for what you want..

    since i don't get the data , unless someone post the data

    will your report only be called on form submit? if yes, then i don't see the problem, you will be able to get all data present during submit and send it to jsreport, in which it will process your data with the helpers that you defined. or are you trying to describe that you can not test the report easily without going to the flow of opening your form and then clicking submit? if that is the issue, you can attach some sample data to your report (there are some actions for that in the jsreport studio UI), so it allows you to test it right in jsreport studio without sending data


Log in to reply
 

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