Posted 16 July 2021, 11: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);
}