// Create a new workbook Workbook workbook = new Workbook(); // Define a json data source String dataSource = "{ \"ds\":" + "[\n" + " {\"Area\": \"North America\",\"City\": \"Chicago\",\"Category\": \"Consumer Electronics\",\"Name\": \"Bose 785593-0050\",\"Revenue\": 92800},\n" + " {\"Area\": \"North America\",\"City\": \"New York\",\"Category\": \"Consumer Electronics\",\"Name\": \"Bose 785593-0050\",\"Revenue\": 92800},\n" + " {\"Area\": \"South America\",\"City\": \"Santiago\",\"Category\": \"Consumer Electronics\",\"Name\": \"Bose 785593-0050\",\"Revenue\": 19550},\n" + " {\"Area\": \"Europe\",\"City\": \"Berlin\",\"Category\": \"Consumer Electronics\",\"Name\": \"Sony WH-1000XM4\",\"Revenue\": 30000},\n" + " {\"Area\": \"Asia\",\"City\": \"Tokyo\",\"Category\": \"Consumer Electronics\",\"Name\": \"Sony WH-1000XM4\",\"Revenue\": 45000},\n" + " {\"Area\": \"North America\",\"City\": \"Los Angeles\",\"Category\": \"Consumer Electronics\",\"Name\": \"Apple AirPods\",\"Revenue\": 60000},\n" + " {\"Area\": \"Europe\",\"City\": \"Paris\",\"Category\": \"Consumer Electronics\",\"Name\": \"Apple AirPods\",\"Revenue\": 55000},\n" + " {\"Area\": \"Asia\",\"City\": \"Seoul\",\"Category\": \"Consumer Electronics\",\"Name\": \"Samsung Galaxy Buds\",\"Revenue\": 40000},\n" + " {\"Area\": \"South America\",\"City\": \"Buenos Aires\",\"Category\": \"Consumer Electronics\",\"Name\": \"Samsung Galaxy Buds\",\"Revenue\": 35000},\n" + " {\"Area\": \"North America\",\"City\": \"Toronto\",\"Category\": \"Consumer Electronics\",\"Name\": \"Bose 785593-0050\",\"Revenue\": 50000}\n" + " ]" + "}"; // Data source sheet IWorksheet dataSourceSheet = workbook.getWorksheets().add(); dataSourceSheet.setName("DataSource"); ITable table = dataSourceSheet.getTables().add(dataSourceSheet.getRange("A1:E4"), true); // Set binding path table.setBindingPath("ds"); table.getColumns().get(0).setDataField("Area"); table.getColumns().get(1).setDataField("City"); table.getColumns().get(2).setDataField("Category"); table.getColumns().get(3).setDataField("Name"); table.getColumns().get(4).setDataField("Revenue"); // Set data source dataSourceSheet.setDataSource(new JsonDataSource(dataSource)); // Pivot table sheet IWorksheet pivotSheet = workbook.getWorksheets().get(0); pivotSheet.setName("PivotSheet"); // Create pivot table IPivotCache pivotcache = workbook.getPivotCaches().create(table); IPivotTable pivottable = pivotSheet.getPivotTables().add(pivotcache, pivotSheet.getRange("A1"), "pivottable1"); // Config pivot table's fields IPivotField fieldArea = pivottable.getPivotFields().get("Area"); fieldArea.setOrientation(PivotFieldOrientation.RowField); IPivotField fieldCity = pivottable.getPivotFields().get("City"); fieldCity.setOrientation(PivotFieldOrientation.RowField); IPivotField fieldName = pivottable.getPivotFields().get("Name"); fieldName.setOrientation(PivotFieldOrientation.ColumnField); IPivotField fieldRevenue = pivottable.getPivotFields().get("Revenue"); fieldRevenue.setOrientation(PivotFieldOrientation.DataField); pivotSheet.getUsedRange().autoFit(); pivottable.setColumnGrand(false); pivottable.setRowGrand(false); pivottable.refresh(); SjsSaveOptions saveOptions = new SjsSaveOptions(); // Set the IncludeBindingSource property to false to exclude the binding source from being exported. saveOptions.setIncludeBindingSource(false); // Document Solutions for Excel support using SaveOptions to save .sjs file format. workbook.save("IncludeBindingSourceOption.sjs", saveOptions);