use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems in project poi by apache.
the class XSSFPivotTable method addRowLabel.
/**
* Add a row label using data from the given column.
* @param columnIndex the index of the source column to be used as row label.
* {@code columnIndex} is 0-based indexed and relative to the first column in the source.
*/
@Beta
public void addRowLabel(int columnIndex) {
checkColumnIndex(columnIndex);
AreaReference pivotArea = getPivotArea();
final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
CTItems items = pivotField.addNewItems();
pivotField.setAxis(STAxis.AXIS_ROW);
pivotField.setShowAll(false);
for (int i = 0; i <= lastRowIndex; i++) {
items.addNewItem().setT(STItemType.DEFAULT);
}
items.setCount(items.sizeOfItemArray());
pivotFields.setPivotFieldArray(columnIndex, pivotField);
CTRowFields rowFields;
if (pivotTableDefinition.getRowFields() != null) {
rowFields = pivotTableDefinition.getRowFields();
} else {
rowFields = pivotTableDefinition.addNewRowFields();
}
rowFields.addNewField().setX(columnIndex);
rowFields.setCount(rowFields.sizeOfFieldArray());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems in project poi by apache.
the class XSSFPivotTable method addReportFilter.
/**
* Add filter for the column with the corresponding index and cell value
* @param columnIndex index of column to filter on
*/
@Beta
public void addReportFilter(int columnIndex) {
checkColumnIndex(columnIndex);
AreaReference pivotArea = getPivotArea();
int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
CTItems items = pivotField.addNewItems();
pivotField.setAxis(STAxis.AXIS_PAGE);
pivotField.setShowAll(false);
for (int i = 0; i <= lastRowIndex; i++) {
items.addNewItem().setT(STItemType.DEFAULT);
}
items.setCount(items.sizeOfItemArray());
pivotFields.setPivotFieldArray(columnIndex, pivotField);
CTPageFields pageFields;
if (pivotTableDefinition.getPageFields() != null) {
pageFields = pivotTableDefinition.getPageFields();
//Another filter has already been created
pivotTableDefinition.setMultipleFieldFilters(true);
} else {
pageFields = pivotTableDefinition.addNewPageFields();
}
CTPageField pageField = pageFields.addNewPageField();
pageField.setHier(-1);
pageField.setFld(columnIndex);
pageFields.setCount(pageFields.sizeOfPageFieldArray());
pivotTableDefinition.getLocation().setColPageCount(pageFields.getCount());
}
Aggregations