Search in sources :

Example 1 with CTCacheField

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheField in project poi by apache.

the class XSSFPivotCacheDefinition method createCacheFields.

/**
     * Generates a cache field for each column in the reference area for the pivot table.
     * @param sheet The sheet where the data i collected from
     */
@Beta
protected void createCacheFields(Sheet sheet) {
    //Get values for start row, start and end column
    AreaReference ar = getPivotArea(sheet.getWorkbook());
    CellReference firstCell = ar.getFirstCell();
    CellReference lastCell = ar.getLastCell();
    int columnStart = firstCell.getCol();
    int columnEnd = lastCell.getCol();
    Row row = sheet.getRow(firstCell.getRow());
    CTCacheFields cFields;
    if (ctPivotCacheDefinition.getCacheFields() != null) {
        cFields = ctPivotCacheDefinition.getCacheFields();
    } else {
        cFields = ctPivotCacheDefinition.addNewCacheFields();
    }
    //For each column, create a cache field and give it en empty sharedItems
    for (int i = columnStart; i <= columnEnd; i++) {
        CTCacheField cf = cFields.addNewCacheField();
        if (i == columnEnd) {
            cFields.setCount(cFields.sizeOfCacheFieldArray());
        }
        //General number format
        cf.setNumFmtId(0);
        Cell cell = row.getCell(i);
        cell.setCellType(CellType.STRING);
        cf.setName(row.getCell(i).getStringCellValue());
        cf.addNewSharedItems();
    }
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTCacheField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheField) Row(org.apache.poi.ss.usermodel.Row) CellReference(org.apache.poi.ss.util.CellReference) Cell(org.apache.poi.ss.usermodel.Cell) CTCacheFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheFields) Beta(org.apache.poi.util.Beta)

Aggregations

Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 AreaReference (org.apache.poi.ss.util.AreaReference)1 CellReference (org.apache.poi.ss.util.CellReference)1 Beta (org.apache.poi.util.Beta)1 CTCacheField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheField)1 CTCacheFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheFields)1