There is a really strange behaviour that I struggle to debug and understand. I am not able to make a clean copy of a worksheet containing a Pivot Table into the same workbook whenever I want. Fyi I am using the last Aspose.Cells 23.4.
-
In the case that I open the existing workbook and only copy the source sheet (PIVOT3 containing a Pivot Table) into PIVOT3_copy_only.
-
In the case that I open the workbook, creates full Pivot Table in PIVOT3, and then copy this source she into PIVOT3_copy_after_creation new sheet, it completely messes up. It means I created the source sheet content + copied it in the same run.
Here is the code I use for the first run (fails) :
//loading workbook
try {
workbook = new Workbook(new FileInputStream(workbookPath));
} catch (FileNotFoundException e) {
Logger.error("pkg.ExcelInterpreterAsposeTest.loadWorkbook", e.getMessage(), e);
} catch (Exception e) {
Logger.error("pkg.ExcelInterpreterAsposeTest.loadWorkbook", e.getMessage(), e);
}
interpreter = new ExcelInterpreter(workbook);
interpreter.createPivotFromTable("PolicyData", "tblPolicies", "PIVOT3", "49", "1", "P_PIVOT_3", "5");
interpreter.addPivotDataField("PIVOT3", "P_PIVOT_3", "Construction", "-4112", "# ### ### ### ##0");
interpreter.addPivotCalculatedDataField("PIVOT3", "P_PIVOT_3", "CalculatedField1", "= Construction - BusinessType", "# ### ### ##0.#");
interpreter.addPivotFieldsToSection("PIVOT3", "P_PIVOT_3", "3", "Flood,Expiry");
interpreter.addPivotFieldsToSection("PIVOT3", "P_PIVOT_3", "1", "Region,Location");
interpreter.addPivotFieldsToSection("PIVOT3", "P_PIVOT_3", "2", "State");
interpreter.setPivotStyle("PIVOT3", "P_PIVOT_3", "PivotStyleMedium9");
interpreter.copySheetFromToNotWorking("PIVOT3", "PIVOT3_copy_after_creation");
Second run (right copy) :
//loading workbook
try {
workbook = new Workbook(new FileInputStream(workbookPath));
} catch (FileNotFoundException e) {
Logger.error("pkg.ExcelInterpreterAsposeTest.loadWorkbook", e.getMessage(), e);
} catch (Exception e) {
Logger.error("pkg.ExcelInterpreterAsposeTest.loadWorkbook", e.getMessage(), e);
}
interpreter.copySheetFromToNotWorking("PIVOT3", "PIVOT3_copy_only");
I attach the result file sampledatainsurance.zip (191.5 KB)
And the class I use : ExcelInterpreter.zip (3.4 KB)
Please let me know what’s wrong and if it can be fixed. For the time being, I used a workaround to save temporary workbooks before copies worksheets, it is dirty but it works. Though I would like to get rid of this workaround.
Thank you