use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotCacheDefinition method commit.
@Beta
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
//Sets the pivotCacheDefinition tag
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotCacheDefinition.type.getName().getNamespaceURI(), "pivotCacheDefinition"));
ctPivotCacheDefinition.save(out, xmlOptions);
out.close();
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotCacheDefinition method getPivotArea.
/**
* Find the 2D base data area for the pivot table, either from its direct reference or named table/range.
* @return AreaReference representing the current area defined by the pivot table
* @throws IllegalArgumentException if the ref attribute is not contiguous or the name attribute is not found.
*/
@Beta
public AreaReference getPivotArea(Workbook wb) throws IllegalArgumentException {
final CTWorksheetSource wsSource = ctPivotCacheDefinition.getCacheSource().getWorksheetSource();
final String ref = wsSource.getRef();
final String name = wsSource.getName();
if (ref == null && name == null) {
throw new IllegalArgumentException("Pivot cache must reference an area, named range, or table.");
}
// this is the XML format, so tell the reference that.
if (ref != null) {
return new AreaReference(ref, SpreadsheetVersion.EXCEL2007);
}
assert (name != null);
// named range or table?
final Name range = wb.getName(name);
if (range != null) {
return new AreaReference(range.getRefersToFormula(), SpreadsheetVersion.EXCEL2007);
}
// not a named range, check for a table.
// do this second, as tables are sheet-specific, but named ranges are not, and may not have a sheet name given.
final XSSFSheet sheet = (XSSFSheet) wb.getSheet(wsSource.getSheet());
for (XSSFTable table : sheet.getTables()) {
// TODO: case-sensitive?
if (name.equals(table.getName())) {
return new AreaReference(table.getStartCellReference(), table.getEndCellReference());
}
}
throw new IllegalArgumentException("Name '" + name + "' was not found.");
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotTable method commit.
@Beta
@Override
protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
//Sets the pivotTableDefinition tag
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotTableDefinition.type.getName().getNamespaceURI(), "pivotTableDefinition"));
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
pivotTableDefinition.save(out, xmlOptions);
out.close();
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotTable method addDataColumn.
/**
* Add column containing data from the referenced area.
* @param columnIndex the index of the column containing the data
* @param isDataField true if the data should be displayed in the pivot table.
*/
@Beta
public void addDataColumn(int columnIndex, boolean isDataField) {
checkColumnIndex(columnIndex);
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
pivotField.setDataField(isDataField);
pivotField.setShowAll(false);
pivotFields.setPivotFieldArray(columnIndex, pivotField);
}
use of org.apache.poi.util.Beta 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());
}
Aggregations