Hello,
Hi,
Hi,
for (ReportParameters parameter : parameters) {
int index = parameters.indexOf(parameter);
outputPath = outputPath.charAt(outputPath.length() - 1) == '/' ? outputPath
: outputPath + "/";
System.out.println("Printing " + outputPath
+ parameter.getReportFileName());
System.out.println("Index is: " + index + " options size is: " + options.size());
xlsxHandler.useAllPivotFieldAsMultipleValue();
for (ReportCellChanges change : changes) {
String sheetName = change.getSheetName();
String pivotTableName = change.getPivoteTableName();
String filterName = change.getCellAttributeName();
String value = parameter.getParameter(change
.getCellAttributeValue());
System.out.println("sheetName: " + sheetName + ", pivotTableName: " + pivotTableName + " filterName: " + filterName + ", value: " + value);
xlsxHandler.setValueOnFilter(sheetName, pivotTableName,
filterName, value);
}
xlsxHandler.updatePivotTables();
xlsxHandler.updateSheet();
// Prints the final pdf file
try {
String path = outputPath
+ parameter.getReportFileName();
ReportPrintOptions opts = options.get(index);
System.out.println("Orientation: " + opts.getOrientation());
System.out.println("Pages height: " + opts.getPagesHeight());
System.out.println("Pages width: " + opts.getPagesWidth());
System.out.println("From: " + opts.getFrom());
System.out.println("To: " + opts.getTo());
xlsxHandler.printSheet(path, options.get(index).getSheet(),
FileFormatType.PDF, options.get(index));
System.out.println("");
} catch (Exception e) {
System.out.println("Error printing "
+ parameter.getReportFileName() + "\n"
+ e.getMessage());
for (StackTraceElement element: e.getStackTrace()) {
System.out.println(element);
}
System.exit(5);
}
public void setValueOnFilter(String sheetName, String pivotTableName,
String filterName, String value) {
PivotTable table = sheets.get(sheetName).getPivotTables()
.get(pivotTableName);
PivotFieldHelper helper = new PivotFieldHelper(table);
helper.setFilterOptionByString(filterName, value);
try {
table.calculateData();
table.refreshData();
table.setRefreshDataOnOpeningFile(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
PivotFieldHelper ----
public void setFilterOptionByString(String filterName, String value){
PivotField field = table.getPageFields().get(filterName);
HashSet values = new HashSet(Arrays.asList(value.split(":")));
field.setMultipleItemSelectionAllowed(true);
PivotItemCollection collection = field.getPivotItems();
for(int i=0; i < collection.getCount(); i++){
PivotItem item = collection.get(i);
String itemValue = item.getStringValue();
if(value.equals("(All)")){
item.setHidden(false);
}
else {
if(values.contains(itemValue)){
item.setHidden(false);
System.out.println("\t" + filterName+": "+itemValue);
}
else {
item.setHidden(true);
}
}
}
}
Hi,
Hi,
Hi,
Hi,
Hello,
public void useAllPivotFieldAsMultipleValue() {
for (int i = 0; i < sheets.getCount(); i++) {
for (int j = 0; j < sheets.get(i).getPivotTables().getCount(); j++) {
PivotTable table = sheets.get(i).getPivotTables().get(j);
PivotFieldHelper helper = new PivotFieldHelper(table);
helper.usePivotFieldAsMultipleValue();
}
}
}
public void usePivotFieldAsMultipleValue(){
for(int i = 0; i < table.getPageFields().getCount(); i++){
PivotField field = table.getPageFields().get(i);
field.setMultipleItemSelectionAllowed(true);
PivotItemCollection collection = field.getPivotItems();
for(int j=0; j < collection.getCount(); j++){
PivotItem item = collection.get(j);
item.setHidden(false);
}
}
}
/**
* Recalculate all pivot tables of the workbook
*/
public void updatePivotTables() {
for (int i = 0; i < sheets.getCount(); i++) {
@SuppressWarnings("unchecked")
Iterator iterator = sheets.get(i).getPivotTables()
.iterator();
while (iterator.hasNext()) {
PivotTable it = iterator.next();
System.out.println("Updating: " + it.getName());
updatePivotTable(it);
}
}
}
/**
* Recalculate a pivot table values after a pivot table filter changes
*
* @param table
*/
public void updatePivotTable(PivotTable table) {
try {
table.refreshData();
table.calculateData();
table.setRefreshDataOnOpeningFile(true);
} catch (Exception e) {
e.printStackTrace();
}
}
ReportCellChanges is just a container of the pivoting to do on the table.
Hi,
Hi,
@abaltra,
Please try our latest version/fix: Aspose.Cells for .NET v21.6.3 (attached)
Aspose.Cells21.6.3 For .Net2_AuthenticodeSigned.Zip (5.5 MB)
Aspose.Cells21.6.3 For .Net4.0.Zip (5.5 MB)
Aspose.Cells21.6.3 For .NetStandard20.Zip (5.5 MB)
Your issue should be fixed in it.
Let us know your feedback.