Hi,
hi, thanks for your reply, it works well with you example code.
But when I tried another case in which I create pivot table through coding instead of from excel directly it would fail.
Hi,
PivotTable report when using and without using the line of code
(“CellArea area = pivotTable.getRowRange();”) that corresponds to
retrieving Row range. When commenting the line of code, it does not
format the PivotTable report items Ok. When using the line of code, it
does format the table fine.
e.g
Sample code:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet
int sheetIndex = workbook.getWorksheets().add();
Worksheet sheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = sheet.getCells();
//Setting the value to the cells
Cell cell = cells.get("A1");
cell.setValue("Sport");
cell = cells.get("B1");
cell.setValue("Quarter");
cell = cells.get("C1");
cell.setValue("Sales");
cell = cells.get("D1");
cell.setValue("Names");
cell = cells.get("A2");
cell.setValue("Golf");
cell = cells.get("A3");
cell.setValue("Golf");
cell = cells.get("A4");
cell.setValue("Tennis");
cell = cells.get("A5");
cell.setValue("Tennis");
cell = cells.get("A6");
cell.setValue("Tennis");
cell = cells.get("A7");
cell.setValue("Tennis");
cell = cells.get("A8");
cell.setValue("Golf");
cell = cells.get("B2");
cell.setValue("Qtr3");
cell = cells.get("B3");
cell.setValue("Qtr4");
cell = cells.get("B4");
cell.setValue("Qtr3");
cell = cells.get("B5");
cell.setValue("Qtr4");
cell = cells.get("B6");
cell.setValue("Qtr3");
cell = cells.get("B7");
cell.setValue("Qtr4");
cell = cells.get("B8");
cell.setValue("Qtr3");
cell = cells.get("C2");
cell.setValue(1500);
cell = cells.get("C3");
cell.setValue(2000);
cell = cells.get("C4");
cell.setValue(600);
cell = cells.get("C5");
cell.setValue(1500);
cell = cells.get("C6");
cell.setValue(4070);
cell = cells.get("C7");
cell.setValue(5000);
cell = cells.get("C8");
cell.setValue(6430);
cell = cells.get("D2");
cell.setValue("Ken");
cell = cells.get("D3");
cell.setValue("Ken");
cell = cells.get("D4");
cell.setValue("Sam");
cell = cells.get("D5");
cell.setValue("Sam");
cell = cells.get("D6");
cell.setValue("Sam");
cell = cells.get("D7");
cell.setValue("Sam");
cell = cells.get("D8");
cell.setValue("Ken");
PivotTableCollection pivotTables = sheet.getPivotTables();
//Adding a PivotTable to the worksheet
int index = pivotTables.add("=A1:D8","E3","PivotTable2");
//Accessing the instance of the newly added PivotTable
PivotTable pivotTable = pivotTables.get(index);
//Unshowing grand totals for rows.
pivotTable.setRowGrand(false);
//Dragging the first field to the row area.
pivotTable.addFieldToArea(PivotFieldType.ROW,0);
pivotTable.addFieldToArea(PivotFieldType.ROW,3);
//Dragging the second field to the column area.
pivotTable.addFieldToArea(PivotFieldType.COLUMN,1);
//Dragging the third field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA,2);
//pivotTable setting
pivotTable.setRowGrand(false);
pivotTable.setColumnGrand(false);
//Row Labels setting
PivotFieldCollection rowFields = pivotTable.getRowFields();
if (rowFields != null) {
for (int i=0; i<rowFields.getCount(); i++) {
rowFields.get(i).setAutoSubtotals(false);
}
}
//Create another style object with yellow color
Style style = workbook.createStyle();
style.setPattern(BackgroundType.SOLID);
style.setBackgroundColor(Color.getYellow());
//CellArea area = pivotTable.getRowRange(); //highlight code line
pivotTable.format(3, 4, style);
pivotTable.format(3, 5, style);
pivotTable.format(3, 6, style);
pivotTable.format(4, 4, style);
pivotTable.format(4, 5, style);
pivotTable.format(4, 6, style);
pivotTable.format(5, 4, style);
pivotTable.format(5, 5, style);
pivotTable.format(5, 6, style);
pivotTable.setRefreshDataFlag(true);
pivotTable.refreshData();
pivotTable.calculateData();
pivotTable.calculateRange();
pivotTable.setRefreshDataFlag(false);
//Saving the Excel file
workbook.save("out1.xlsx");
We need to investigate it thoroughly to evaluate your issue. I have logged an investigation ticket with an id “CELLSJAVA-41151” for your issue. We will look into it soon.
Hi,
Thanks for providing us template files and code segment.
For your issues/ queries:
- After an initial test, I observed the issue as you mentioned by using the following
sample code. I got the formatting issue with data area in the pivot
table report, see the comments attached to the lines of codes. I used the template file provided by you.
e.g
Sample code:
Workbook workbook = new Workbook("test.xlsx");
//Obtaining the reference of the newly added worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
PivotTableCollection pivotTables = sheet.getPivotTables();
//Accessing the instance of the newly added PivotTable
PivotTable pivotTable = pivotTables.get(0);
Style style = new Style();
style.setPattern(BackgroundType.SOLID);
style.setBackgroundColor(Color.getYellow());
//Apply formatting to the DataBodyRange of PivotTable.
CellArea dataArea = pivotTable.getDataBodyRange();
int dataAreaStartRow = dataArea.StartRow;
int dataAreaStartColumn = dataArea.StartColumn;
int dataAreaEndRow = dataArea.EndRow;
int dataAreaEndColumn = dataArea.EndColumn;
System.out.println("DataBody StartRow="+dataAreaStartRow + " StartColumn=" + dataAreaStartColumn + " EndRow=" + dataAreaEndRow + " EndColumn=" + dataAreaEndColumn ); //Ok
pivotTable.format(dataAreaStartRow, dataAreaStartColumn, style);
// It should format F10 cell in the data area but it does not format the
cell at all.
//pivotTable.format(dataAreaStartRow, dataAreaStartColumn+1, style); // It does format F10 cell though.
//populate pivotTable to the sheet
pivotTable.setRefreshDataFlag(true);
pivotTable.refreshData();
pivotTable.calculateData();
pivotTable.calculateRange();
pivotTable.setRefreshDataFlag(false);
//Saving the Excel file
workbook.save("out_test1.xlsx");
I have logged a ticket with an id “CELLSJAVA-41158” for your issue into our database. We will look into it soon.
- After an initial test, I observed the issue as you mentioned by using the following sample code. I got the issue with calculating Pivot data. I used the template file provided by you.
e.g
Sample code:
Workbook workbook = new Workbook("test.xlsx");
//Obtaining the reference of the newly added worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
PivotTableCollection pivotTables = sheet.getPivotTables();
//Accessing the instance of the newly added PivotTable
PivotTable pivotTable = pivotTables.get(0);
Style style = new Style();
style.setPattern(BackgroundType.SOLID);
style.setBackgroundColor(Color.getYellow());
//Apply formatting to the DataBodyRange of PivotTable.
CellArea dataArea = pivotTable.getDataBodyRange();
int dataAreaStartRow = dataArea.StartRow;
int dataAreaStartColumn = dataArea.StartColumn;
int dataAreaEndRow = dataArea.EndRow;
int dataAreaEndColumn = dataArea.EndColumn;
System.out.println("DataBody StartRow="+dataAreaStartRow + " StartColumn=" + dataAreaStartColumn + " EndRow=" + dataAreaEndRow + " EndColumn=" + dataAreaEndColumn ); //Ok
pivotTable.format(dataAreaStartRow, dataAreaStartColumn+1, style); // It does format F10 cell though.
//populate pivotTable to the sheet
pivotTable.setRefreshDataFlag(true);
pivotTable.refreshData();
pivotTable.calculateData();
pivotTable.calculateRange();
pivotTable.setRefreshDataFlag(false);
//It does not print expected values using the following lines of code segment
System.out.println("@@@@@@@@@@@F12 value="+sheet.getCells().get("F12").getValue());
System.out.println("@@@@@@@@@@@F13 value="+sheet.getCells().get("F13").getValue());
System.out.println("@@@@@@@@@@@G10 value="+sheet.getCells().get("G10").getValue());
System.out.println("@@@@@@@@@@@G12 value="+sheet.getCells().get("G12").getValue());
I have logged a ticket with an id “CELLSJAVA-41159” for your issue into our database. We will look into it soon as well.
Once we have any update on any of the above mentioned issues, we will let you know here.
- I am afraid, this is not possible in Ms Excel either (you may confirm it too in MS Excel manually), so you can’t add hyperlinks to pivot items values.
Thank you.
Hi,
Thanks for using Aspose.Cells.
We have fixed this issue.
Please download and try the latest fix: Aspose.Cells
for Java v8.3.1.6 and let us know your feedback.
The issues you have found earlier (filed as CELLSJAVA-41151;CELLSJAVA-41158;CELLSJAVA-41159) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.