Excel Java report based on the template

Posted by: vin.sinha on 24 October 2020, 8:30 pm EST

    • Post Options:
    • Link

    Posted 24 October 2020, 8:30 pm EST - Updated 29 September 2022, 3:49 pm EST

    Hi There, I am currently evaluating the grape city Java APIs for excel. Currently we have requirement to build dynamic report based on the backend dynamic data.

    When I tried the GC excel apis, its working fine for the single row configured row template. But when I have same object in more than 1 row , it’s not repeating the set of rows together as expected.

    I have attached here the screen shot of our basic template.

    Really appreciate if you can provide some insight and what exactly I am missing.

    //create a new workbook
           Workbook workbook = new Workbook();
    
           //Load template file from resource
           // InputStream templateFile = getResourceStream("Estonia_report_1.xlsx");
           File templateFile = new File("report_1.xlsx");
           workbook.open(new FileInputStream(templateFile));
    
           List<AdvertisingEventEE> advertisingEvents = new ArrayList<AdvertisingEventEE>();
    
           //#region Init Data
           AdvertisingEventEE record1 = new AdvertisingEventEE();
    
           record1.setActivityType("Activity 111");
           record1.setAmountLC(111.34);
           record1.setEventLocation("New York 111");
           record1.setEventName("Party 111");
           record1.setLocalCurrency("USD");
           record1.setPurposeType("Confidential 111");
    
           advertisingEvents.add(record1);
    
           //#region Init Data
           AdvertisingEventEE record2 = new AdvertisingEventEE();
           record2.setActivityType("Activity 222");
           record2.setAmountLC(222.34);
           record2.setEventLocation("New York 222");
           record2.setEventName("Party 222");
           record2.setLocalCurrency("Ruppee");
           record2.setPurposeType("Confidential 222");
    
           advertisingEvents.add(record2);
    //#endregion
    
    //Init template global settings
           workbook.getNames().add("TemplateOptions.KeepLineSize", "true");
    
    //Add data source
           workbook.addDataSource("advertisingEvent", advertisingEvents);
    //Invoke to process the template
           workbook.processTemplate();
    //save to an excel file
           workbook.save("Report.xlsx");
    
  • Posted 26 October 2020, 10:27 am EST

    Hello,

    We are working on your issue and we will get back to you soon on the same.

    Thanks,

    Reeva

  • Posted 27 October 2020, 6:04 am EST

    Hello,

    Can you please share your “Estonia_report_1.xlsx” template file with us so that we can replicate this issue further at our end and try to fix it? And also share which version of GcExcel JAVA are you using?

    Thanks,

    Reeva

  • Posted 27 October 2020, 7:08 am EST

    Thank you Reeva for your response. Here is the attached “Estonia_report_1.xlsx”. Idea is to repeat row from 5 to 7 for list of advertisingEvent object data.

    Please let me know if you would like further input from my side.

    Pls note, we are planning to have a customer demo this Friday Oct 30th, so appreciate if you can help on priority.

    Thanks again!

  • Posted 27 October 2020, 9:32 am EST

    Hello,

    We didn’t receive your attachment yet. Please zip the file once again and then attach.

    Thanks,

    Reeva

  • Posted 28 October 2020, 5:27 pm EST

    template.xlsx.zip

    Attaching here the template again in xlsx and archive format. Appreciate your quick response.

  • Posted 29 October 2020, 7:07 am EST

    Hi Reeva, any update on the above attached template?

  • Posted 29 October 2020, 8:52 am EST

    Hello,

    I am unable to run your the sample with attached template.xlsx file and facing this exception: “Can’t find field or get method for ‘eventLocation’ of type ‘class AdvertisingEventEE’.”

    Please have a look at attached sample which isn’t working at our end. Request you to please modify the sample to replicate the issue and revert. We will look into this issue thereon.

    Thanks,

    Reeva

    TemplateIssue_JAVA.zip

  • Posted 29 October 2020, 8:31 pm EST

    grapecity-template.zip

    HI Reeva,

    PFA code base from my local which is generating the output as Report.xlsx from the sample java code, template xlsx file is “template.xlsx”. I have executed this code base in my local and working fine.

    As I mentioned above its repeating the for single row object. Challenge I am facing when I have same object and its attribute configured for multiple row. So inside the attached project template.xlsx example row 5 to 7 should repeat together.

    Thanks!

  • Posted 30 October 2020, 9:08 am EST

    Hello,

    We are able to replicate the issue and hence we are escalating the same to the concerned team for the fix.

    Tracking id for your issue is #DOCXLS-3278

    We will update you as soon as we hear anything from our concerned team.

    Thanks,

    Reeva

  • Posted 2 November 2020, 8:21 am EST

    HI Reeva, is there any update on this ?

  • Posted 3 November 2020, 3:07 am EST

    Hello,

    As per our understanding, you want to get a report like the one attached. Hence, you need to add a “Range” property for template in A6. Such as

    Aruande esitaja: {{advertisingEvent.eventLocation(R=A5:F7)}}			
    
    

    I have attached modified template and exported excel file. Please have a look. Let me know if you face any other issue.

    Thanks,

    Reeva

    Attachments.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels