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

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

Introduction

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

Prototype

@Beta
public void addRowLabel(int columnIndex) 

Source Link

Document

Add a row label using data from the given column.

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();//from w  w w.  j  a v  a 2  s.  c  om

    //Create some data to build the pivot table on
    setCellData(sheet);

    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:com.springapp.mvc.CreatePivotTable.java

License:Apache License

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

    //Create some data to build the pivot table on
    setCellData(sheet2);// w ww. j  a v  a 2s .  com

    XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D5"), new CellReference("A1"),
            sheet2);
    //Configure the pivot table
    //Use first column as row label
    pivotTable.addRowLabel(0);
    pivotTable.addRowLabel(3);
    //pivotTable.addDataColumn(0, false);
    //pivotTable.addRowLabel(1);
    //pivotTable.addRowLabel(2);
    //pivotTable.addRowLabel(3);
    //pivotTable.addRowLabel(3);
    //pivotTable.addDataColumn(1, true);
    //pivotTable.addDataColumn(1, true);
    //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);
    //pivotTable.addReportFilter(0);
    //pivotTable.addReportFilter(0);
    //pivotTable.addRowLabel(0);
    //pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
    System.out.println(pivotTable.getRowLabelColumns());
    FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx");
    wb.write(fileOut);
    fileOut.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();//  w ww.java2  s  .  co m

    //Create some data to build the pivot table on
    setCellData(sheet);

    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();/*  w w  w.java  2s . co  m*/

    //Create some data to build the pivot table on
    setCellData(sheet);

    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();
}