Ignore cells if datasource is empty

Posted by: nimish.g on 21 October 2021, 5:16 pm EST

    • Post Options:
    • Link

    Posted 21 October 2021, 5:16 pm EST

    When the list of accounts is empty grapecity throws a NPE.

    Expectation: I would like to know if there is a way to not show rows A2 to A4 if list of accounts is empty.

    PFA excel template and exception stacktrace present in zip file

    final List<Account> accounts=new ArrayList<>();
    final Map<String, Object> dataSourceMap = new HashMap<>();
    dataSourceMap.put("account", accounts);
    final Workbook workbook = new Workbook();
    dataSourceMap.forEach((key, value) -> workbook.addDataSource(key, value));
    Class Account{
    String name;
    String List<String> statementNames;
    ```[zip filename="grapecity.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-fdfaa484-f38c-488f-9799-d9e87378a872.zip[/zip]
  • Posted 21 October 2021, 7:59 pm EST

    Hello Nimish,

    You can put a check before calling the process template to check if the list is empty or not. If the list is empty, you can simply delete the particular range.


    Regards, Prabhat Sharma.

  • Posted 21 October 2021, 8:19 pm EST

    Hi Prabhat,

    I was wondering if its possible to do in the excel template as i have other datasources for other sheets.

  • Posted 24 October 2021, 5:51 pm EST

    Hello Nimish,

    We are discussing this with the developers and will get back to you with the updates soon. [Internal Tracking Id: DOCXLS-5052]

    Regards, Prabhat Sharma.

  • Posted 2 November 2021, 6:09 pm EST


    As per the developers, if the list is empty, you need to delete the particular range manually.

    Can you please share a stripped-down sample of the Empty data source so that the developers can see what you are doing exactly and see if they can add something in the API to avoid the exception?

    Regards, Prabhat Sharma.

Need extra support?

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

Learn More

Forum Channels