Example usage for org.apache.poi.xssf.usermodel XSSFPivotTable getPivotCacheDefinition

List of usage examples for org.apache.poi.xssf.usermodel XSSFPivotTable getPivotCacheDefinition

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFPivotTable getPivotCacheDefinition.

Prototype

@Beta
    public XSSFPivotCacheDefinition getPivotCacheDefinition() 

Source Link

Usage

From source file:ru.inkontext.poi.CustomPivotTable.java

License:Apache License

public CustomPivotTable safeExcludeSubTotal(XSSFPivotTable pivotTable, int fieldIndex) {
    Optional.ofNullable(pivotTable.getCTPivotTableDefinition().getPivotFields())
            .map(pivotFields -> pivotFields.getPivotFieldArray(fieldIndex))
            .ifPresent(pivotField -> Optional.ofNullable(pivotField.getItems()).ifPresent(items -> {
                for (int i = 0; i < 2; i++) {
                    items.getItemArray(i).unsetT();
                    items.getItemArray(i).setX((long) i);
                }//from w w  w .ja va  2  s . c o  m
                for (int i = items.sizeOfItemArray() - 1; i > 1; i--)
                    items.removeItem(i);
                items.setCount(2);

                Optional.ofNullable(
                        pivotTable.getPivotCacheDefinition().getCTPivotCacheDefinition().getCacheFields())
                        .map(CTCacheFields::getCacheFieldArray)
                        .ifPresent(ctCacheFields -> Optional.ofNullable(ctCacheFields[fieldIndex])
                                .map(CTCacheField::getSharedItems).ifPresent(ctSharedItems -> {
                                    ctSharedItems.addNewS().setV(" ");
                                    ctSharedItems.addNewS().setV("  ");
                                }));

                pivotField.setDefaultSubtotal(false);
            }));
    return this;
}