Pivot tables toJson issue

Posted by: kmalyi on 16 July 2021, 2:00 am EST

  • Posted 16 July 2021, 2:00 am EST

    Hello we got a problem and would be happy if you can help us. Workflow is more complicated then described in code but this sample still doesn't work too.

    @Test
    public void pivotTest() throws Exception{
    String data = IOUtils.toString(
    this.getClass().getResourceAsStream("/data/schedule/GrapecityDataJson.json"),
    "UTF-8"
    );
    Workbook.SetLicenseKey(gcExcelKey);
    Workbook workbook = new Workbook();
    //data contains two worksheets (first is primary and second with Pivot table)
    workbook.fromJson(data);
    IWorksheet worksheetWithPivot = workbook.getWorksheets().get(1);
    String worksheetWithPivotJson = worksheetWithPivot.toJson();
    workbook.getWorksheets().get(1).delete();
    String workbookJson = workbook.toJson();
    //we want to create new duplicated workbook and add worksheet with Pivot
    Workbook workbookNew = new Workbook();
    workbookNew.fromJson(workbookJson);
    IWorksheet add = workbookNew.getWorksheets().add();
    // on add.fromJson(worksheetWithPivotJson) we have Exception
    // caused by: java.lang.NullPointerException
    // at com.grapecity.documents.excel.r.ao.a(Unknown Source) ~[gcexcel-4.1.3.jar:?]
    // at com.grapecity.documents.excel.D.aw.a(Unknown Source) ~[gcexcel-4.1.3.jar:?]
    // at com.grapecity.documents.excel.D.aw.a(Unknown Source) ~[gcexcel-4.1.3.jar:?]
    // at com.grapecity.documents.excel.di.fromJson(Unknown Source) ~[gcexcel-4.1.3.jar:?]
    // at com.grapecity.documents.excel.di.fromJson(Unknown Source) ~[gcexcel-4.1.3.jar:?]
    add.fromJson(worksheetWithPivotJson);
    }
  • Replied 16 July 2021, 2:02 am EST

    Here is Json with dataGrapecityDataJson.zip

    Please let me know if you need more information about this issue. Thanks!
  • Replied 18 July 2021, 9:16 pm EST

    Hello,

    We have escalated this issue to the development and will let you know as soon as we get the update from their end.
    [Internal Tracking ID: DOCXLS-4531]

    Regards,
    Prabhat Sharma.
  • Marked as Answer

    Replied 19 July 2021, 3:35 pm EST

    Hello,

    As per the developers, the Pivot table is stored in the worksheet while the pivot cache is stored in the workbook that different pivot tables shared.
    So when using worksheet tojson, pivot cache info would be lost. And some error would happen when using worksheet from json.
    If you want to use PivotTable, you should use workbook.fromjson and remove unwanted sheet in order to preserve the pivot cache info.

    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