We are trying to produce a pivot table based on .xlsx file which we create programmatically.
FileInputStream input_document = new FileInputStream(new File("testme.xlsx"));
XSSFWorkbook wb = new XSSFWorkbook(input_document);
XSSFSheet pivotSheet = wb.createSheet("Pivot sheet");
//create pivot table
XSSFPivotTable pivotTable = pivotSheet.createPivotTable(
new AreaReference(new CellReference("\'Selected Messages\'!A3"), new CellReference("\'Selected Messages\'!T4620"), //make the reference big enough for later data
SpreadsheetVersion.EXCEL2007),
new CellReference("\'Pivot sheet\'!C5"), wb.getSheet("Selected Messages"));
//Configure the pivot table
//Use first column as row label
pivotTable.addRowLabel(0);
pivotTable.addRowLabel(2);
pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 5, "Number of messages");
pivotTable.addColLabel(4);
pivotTable.addReportFilter(11);
wb.write(new FileOutputStream("SXSSFPivotTableTest.xlsx"));
wb.close();
Here is our code sample we use. The testme.xlsx is the produced file by us and it contains a lot of data.The data are in the Selected Message
sheet. We want to create a pivot table from those data, in a new sheet in the same file and then create a new file which will contain all the sheets.
Our problem is that after the creation when we try to open the new file Excel tries to recover it but it removes the pivot table and all the .xml file which are responsible for it. The error message we get is shown below :
Removed Feature: PivotTable report from /xl/pivotCache/pivotCacheDefinition1.xml part (PivotTable cache) Removed Feature: PivotTable report from /xl/pivotTables/pivotTable1.xml part (PivotTable view) Removed Records: Workbook properties from /xl/workbook.xml part (Workbook)
Does anyone have the same problem in any previous version or in the latest? Any solution that may help us overcome our problem?
NOTE The produced .xlsx can be opened with LibreOffice.
The headers are
Type,MRN or Correl ID,From,Sent To,Received,CoA,CoD,Exp,Exc,Size,Type Error,Pointer,Reason,Original Value,Action by recipient,Interchange Error code,Rejected Msg,Action by recipient2,Error code
'Selected Messages'!A3:T3
contains the headings of the table? Those strings are the pivot table field names then and must be unique. Can you at least post the content of'Selected Messages'!A3:T3
? – Axel Richter'Selected Messages'!A3:T3
in your question. – Axel RichterCellReference("\'Selected Messages\'!A3")...
. It is not necessary. Before my first now deleted comment, I had not seen that you are using the additional sheet parameter increatePivotTable
. – Axel Richter