Example usage for org.apache.poi.xssf.usermodel XSSFSheet createPivotTable

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet createPivotTable

Introduction

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

Prototype

@Beta
public XSSFPivotTable createPivotTable(final Table source, CellReference position) 

Source Link

Document

Create a pivot table using the Table, at the given position.

Usage

From source file:CreatePivotTable.java

License:Apache License

public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();

    //Create some data to build the pivot table on
    setCellData(sheet);/*from w w  w  . j ava 2  s.  c o  m*/

    XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D4"), new CellReference("H5"));
    //Configure the pivot table
    //Use first column as row label
    pivotTable.addRowLabel(0);
    //Sum up the second column
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
    //Set the third column as filter
    pivotTable.addColumnLabel(DataConsolidateFunction.AVERAGE, 2);
    //Add filter on forth column
    pivotTable.addReportFilter(3);

    FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}

From source file:packtest.CreatePivotTable.java

License:Apache License

public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();

    //Create some data to build the pivot table on
    setCellData(sheet);//from ww  w . j  a  va2  s  . c o  m

    XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D4"), new CellReference("H5"));
    //Configure the pivot table
    //Use first column as row label
    pivotTable.addRowLabel(0);
    //Sum up the second column
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
    //Set the third column as filter
    pivotTable.addColumnLabel(DataConsolidateFunction.AVERAGE, 2);
    //Add filter on forth column
    pivotTable.addReportFilter(3);

    FileOutputStream fileOut = new FileOutputStream(Utils.getPath("ooxml-pivottable.xlsx"));
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}

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

License:Apache License

public static void main(String[] args) throws IOException, InvalidFormatException {

    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();

    //Create some data to build the pivot table on
    setCellData(sheet);/*from w  w  w.jav  a 2  s.  c  om*/

    XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:C6", SpreadsheetVersion.EXCEL2007),
            new CellReference("E3"));

    pivotTable.addRowLabel(1); // set second column as 1-th level of rows
    setFormatPivotField(pivotTable, 1, 9); //set format numFmtId=9 0%
    pivotTable.addRowLabel(0); // set first column as 2-th level of rows
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 2); // Sum up the second column
    setFormatDataField(pivotTable, 2, 3); //numFmtId=3 # ##0

    FileOutputStream fileOut = new FileOutputStream("stackoverflow-pivottable.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}

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

License:Apache License

public CustomPivotTable(XSSFSheet sheet, String source, String place) {
    pivotTable = sheet.createPivotTable(new AreaReference(source, SpreadsheetVersion.EXCEL2007),
            new CellReference(place));
    pivotTableDefinition = pivotTable.getCTPivotTableDefinition();
    pivotCacheDefinition = pivotTable.getPivotCacheDefinition().getCTPivotCacheDefinition();
}