Package org.apache.poi.xssf.model

Examples of org.apache.poi.xssf.model.CalculationChain


    }


    public void test49966() {
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49966.xlsx");
        CalculationChain calcChain = wb.getCalculationChain();
        assertNotNull(wb.getCalculationChain());
        assertEquals(3, calcChain.getCTCalcChain().sizeOfCArray());

        XSSFSheet sheet = wb.getSheetAt(0);
        XSSFRow row = sheet.getRow(0);

        sheet.removeRow(row);
        assertEquals("XSSFSheet#removeRow did not clear calcChain entries",
                0, calcChain.getCTCalcChain().sizeOfCArray());

        //calcChain should be gone
        wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
        assertNull(wb.getCalculationChain());
View Full Code Here


    public void test49966() throws Exception {
       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("shared_formulas.xlsx");
       XSSFSheet sheet = wb.getSheetAt(0);
      
       // CalcChain has lots of entries
       CalculationChain cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
       assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
       assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
       assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
       assertEquals("A8", cc.getCTCalcChain().getCArray(6).getR());
       assertEquals(40, cc.getCTCalcChain().sizeOfCArray());

       // Try various ways of changing the formulas
       // If it stays a formula, chain entry should remain
       // Otherwise should go
       sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
       sheet.getRow(2).getCell(0).setCellFormula(null)// go
       sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
       sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING)// go
       sheet.getRow(5).removeCell(
             sheet.getRow(5).getCell(0// go
       );
        sheet.getRow(6).getCell(0).setCellType(Cell.CELL_TYPE_BLANK)// go
        sheet.getRow(7).getCell(0).setCellValue((String)null)// go

       // Save and check
       wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
       assertEquals(35, cc.getCTCalcChain().sizeOfCArray());

       cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A9", cc.getCTCalcChain().getCArray(2).getR());

    }
View Full Code Here

    public void test49966() throws Exception {
       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("shared_formulas.xlsx");
       XSSFSheet sheet = wb.getSheetAt(0);
      
       // CalcChain has lots of entries
       CalculationChain cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
       assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
       assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
       assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
       assertEquals("A8", cc.getCTCalcChain().getCArray(6).getR());
       assertEquals(40, cc.getCTCalcChain().sizeOfCArray());

       // Try various ways of changing the formulas
       // If it stays a formula, chain entry should remain
       // Otherwise should go
       sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
       sheet.getRow(2).getCell(0).setCellFormula(null)// go
       sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
       sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING)// go
       sheet.getRow(5).removeCell(
             sheet.getRow(5).getCell(0// go
       );
        sheet.getRow(6).getCell(0).setCellType(Cell.CELL_TYPE_BLANK)// go
        sheet.getRow(7).getCell(0).setCellValue((String)null)// go

       // Save and check
       wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
       assertEquals(35, cc.getCTCalcChain().sizeOfCArray());

       cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A9", cc.getCTCalcChain().getCArray(2).getR());

    }
View Full Code Here

     *
     * @param n the number of rows to move
     */
    protected void shift(int n) {
        int rownum = getRowNum() + n;
        CalculationChain calcChain = sheet.getWorkbook().getCalculationChain();
        int sheetId = (int)sheet.sheet.getSheetId();
        for(Cell c : this){
            XSSFCell cell = (XSSFCell)c;

            //remove the reference in the calculation chain
            if(calcChain != null) calcChain.removeItem(sheetId, cell.getReference());

            CTCell ctCell = cell.getCTCell();
            String r = new CellReference(rownum, cell.getColumnIndex()).formatAsString();
            ctCell.setR(r);
        }
View Full Code Here

     *
     * @param n the number of rows to move
     */
    protected void shift(int n) {
        int rownum = getRowNum() + n;
        CalculationChain calcChain = _sheet.getWorkbook().getCalculationChain();
        int sheetId = (int)_sheet.sheet.getSheetId();
        for(Cell c : this){
            XSSFCell cell = (XSSFCell)c;

            //remove the reference in the calculation chain
            if(calcChain != null) calcChain.removeItem(sheetId, cell.getReference());

            CTCell ctCell = cell.getCTCell();
            String r = new CellReference(rownum, cell.getColumnIndex()).formatAsString();
            ctCell.setR(r);
        }
View Full Code Here

     *
     * @param n the number of rows to move
     */
    protected void shift(int n) {
        int rownum = getRowNum() + n;
        CalculationChain calcChain = _sheet.getWorkbook().getCalculationChain();
        int sheetId = (int)_sheet.sheet.getSheetId();
        String msg = "Row[rownum="+getRowNum()+"] contains cell(s) included in a multi-cell array formula. " +
                "You cannot change part of an array.";
        for(Cell c : this){
            XSSFCell cell = (XSSFCell)c;
            if(cell.isPartOfArrayFormulaGroup()){
                cell.notifyArrayFormulaChanging(msg);
            }

            //remove the reference in the calculation chain
            if(calcChain != null) calcChain.removeItem(sheetId, cell.getReference());

            CTCell ctCell = cell.getCTCell();
            String r = new CellReference(rownum, cell.getColumnIndex()).formatAsString();
            ctCell.setR(r);
        }
View Full Code Here

        XSSFSheet sheet = wb.getSheetAt(0);

        Workbook wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        // CalcChain has lots of entries
        CalculationChain cc = wb.getCalculationChain();
        assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
        assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
        assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
        assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
        assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
        assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
        assertEquals("A8", cc.getCTCalcChain().getCArray(6).getR());
        assertEquals(40, cc.getCTCalcChain().sizeOfCArray());
        wbRead.close();
       
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        // Try various ways of changing the formulas
        // If it stays a formula, chain entry should remain
        // Otherwise should go
        sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
        sheet.getRow(2).getCell(0).setCellFormula(null); // go
        sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);
        sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING); // go
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        validateCells(sheet);
        sheet.getRow(5).removeCell(sheet.getRow(5).getCell(0)); // go
        validateCells(sheet);
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);
       
        sheet.getRow(6).getCell(0).setCellType(Cell.CELL_TYPE_BLANK); // go
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);
        sheet.getRow(7).getCell(0).setCellValue((String) null); // go
        wbRead.close();

        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        // Save and check
        wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
        assertEquals(35, cc.getCTCalcChain().sizeOfCArray());

        cc = wb.getCalculationChain();
        assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
        assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
        assertEquals("A9", cc.getCTCalcChain().getCArray(2).getR());
        wbRead.close();
    }
View Full Code Here

    public void test49966() throws Exception {
       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("shared_formulas.xlsx");
       XSSFSheet sheet = wb.getSheetAt(0);
      
       // CalcChain has lots of entries
       CalculationChain cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
       assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
       assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
       assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
       assertEquals("A8", cc.getCTCalcChain().getCArray(6).getR());
       assertEquals(40, cc.getCTCalcChain().sizeOfCArray());

       // Try various ways of changing the formulas
       // If it stays a formula, chain entry should remain
       // Otherwise should go
       sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
       sheet.getRow(2).getCell(0).setCellFormula(null)// go
       sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
       sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING)// go
       sheet.getRow(5).removeCell(
             sheet.getRow(5).getCell(0// go
       );
        sheet.getRow(6).getCell(0).setCellType(Cell.CELL_TYPE_BLANK)// go
        sheet.getRow(7).getCell(0).setCellValue((String)null)// go

       // Save and check
       wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
       assertEquals(35, cc.getCTCalcChain().sizeOfCArray());

       cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A9", cc.getCTCalcChain().getCArray(2).getR());

    }
View Full Code Here

    public void bug49966() throws Exception {
       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("shared_formulas.xlsx");
       XSSFSheet sheet = wb.getSheetAt(0);
      
       // CalcChain has lots of entries
       CalculationChain cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
       assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
       assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
       assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
       assertEquals("A8", cc.getCTCalcChain().getCArray(6).getR());
       assertEquals(40, cc.getCTCalcChain().sizeOfCArray());

       // Try various ways of changing the formulas
       // If it stays a formula, chain entry should remain
       // Otherwise should go
       sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
       sheet.getRow(2).getCell(0).setCellFormula(null)// go
       sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
       sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING)// go
       sheet.getRow(5).removeCell(
             sheet.getRow(5).getCell(0// go
       );
        sheet.getRow(6).getCell(0).setCellType(Cell.CELL_TYPE_BLANK)// go
        sheet.getRow(7).getCell(0).setCellValue((String)null)// go

       // Save and check
       wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
       assertEquals(35, cc.getCTCalcChain().sizeOfCArray());

       cc = wb.getCalculationChain();
       assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
       assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
       assertEquals("A9", cc.getCTCalcChain().getCArray(2).getR());

    }
View Full Code Here

     *
     * @param n the number of rows to move
     */
    protected void shift(int n) {
        int rownum = getRowNum() + n;
        CalculationChain calcChain = _sheet.getWorkbook().getCalculationChain();
        int sheetId = (int)_sheet.sheet.getSheetId();
        String msg = "Row[rownum="+getRowNum()+"] contains cell(s) included in a multi-cell array formula. " +
                "You cannot change part of an array.";
        for(Cell c : this){
            XSSFCell cell = (XSSFCell)c;
            if(cell.isPartOfArrayFormulaGroup()){
                cell.notifyArrayFormulaChanging(msg);
            }

            //remove the reference in the calculation chain
            if(calcChain != null) calcChain.removeItem(sheetId, cell.getReference());

            CTCell ctCell = cell.getCTCell();
            String r = new CellReference(rownum, cell.getColumnIndex()).formatAsString();
            ctCell.setR(r);
        }
View Full Code Here

TOP

Related Classes of org.apache.poi.xssf.model.CalculationChain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.