Package org.zkoss.poi.ss.usermodel

Examples of org.zkoss.poi.ss.usermodel.Row


  }
 
  @Test
  public void testInsertRangeC1_C4() {
    Worksheet sheet1 = _workbook.getWorksheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    Row row4 = sheet1.getRow(3);
    Row row5 = sheet1.getRow(4);
    Row row6 = sheet1.getRow(5);
    assertEquals(1, row1.getCell(5).getNumericCellValue(), 0.0000000000000001); //F1: 1
    assertEquals(2, row2.getCell(5).getNumericCellValue(), 0.0000000000000001)//F2: 2
    assertEquals(3, row3.getCell(5).getNumericCellValue(), 0.0000000000000001); //F3: 3
    assertEquals(7, row4.getCell(0).getNumericCellValue(), 0.0000000000000001); //A4: 7
    assertEquals(9, row1.getCell(2).getNumericCellValue(), 0.0000000000000001); //C1: 9
    assertEquals(11, row1.getCell(3).getNumericCellValue(), 0.0000000000000001); //D1: 11
   
    //A1: =SUM(F1:F3)
    Cell cellA1 = row1.getCell(0); //A1: =SUM(F1:F3)
    CellValue valueA1 = _evaluator.evaluate(cellA1);
    assertEquals(6, valueA1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA1.getCellType());
    testToFormulaString(cellA1, "SUM(F1:F3)");
   
    //A2: =SUM(D2:IV2) IV: 256
    Cell cellA2 = row2.getCell(0); //A2: =SUM(D2:IV2) IV: 256
    CellValue valueA2 = _evaluator.evaluate(cellA2);
    assertEquals(2, valueA2.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA2.getCellType());
    testToFormulaString(cellA2, "SUM(D2:IV2)");

    //A3: =SUM(IU3:IV3) IU: 255, IV: 256
    Cell cellA3 = row3.getCell(0); //A3: =SUM(IU3:IV3)
    CellValue valueA3 = _evaluator.evaluate(cellA3);
    assertEquals(0, valueA3.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA3.getCellType());
    testToFormulaString(cellA3, "SUM(IU3:IV3)");
   
    //A5: =SUM(C1:D1)
    Cell cellA5 = row5.getCell(0);
    CellValue valueA5 = _evaluator.evaluate(cellA5);
    assertEquals(20, valueA5.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA5.getCellType());
    testToFormulaString(cellA5, "SUM(C1:D1)");
   
    //A6: =SUM(B1:D1)
    Cell cellA6 = row6.getCell(0);
    CellValue valueA6 = _evaluator.evaluate(cellA6);
    assertEquals(20, valueA6.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA6.getCellType());
    testToFormulaString(cellA6, "SUM(B1:D1)");
   
    //H1: =SUM(F1:F3)
    Cell cellH1 = row1.getCell(7);
    CellValue valueH1 = _evaluator.evaluate(cellH1);
    assertEquals(6, valueH1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueH1.getCellType());
    testToFormulaString(cellH1, "SUM(F1:F3)");

    //H4: =A4
    Cell cellH4 = row4.getCell(7);
    CellValue valueH4 = _evaluator.evaluate(cellH4);
    assertEquals(7, valueH4.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueH4.getCellType());
    testToFormulaString(cellH4, "A4");
   
    //Insert C1:C4
    BookHelper.insertRange(sheet1, 0, 2, 3, 2, true, Range.FORMAT_LEFTABOVE);
    _evaluator.notifySetFormula(cellA1);
    _evaluator.notifySetFormula(cellA2);
    _evaluator.notifySetFormula(cellA3);
    _evaluator.notifySetFormula(cellA5);
    _evaluator.notifySetFormula(cellA6);
   
    assertEquals(1, row1.getCell(6).getNumericCellValue(), 0.0000000000000001); //G1: 1
    assertEquals(2, row2.getCell(6).getNumericCellValue(), 0.0000000000000001)//G2: 2
    assertEquals(3, row3.getCell(6).getNumericCellValue(), 0.0000000000000001); //G3: 3
    assertEquals(7, row4.getCell(0).getNumericCellValue(), 0.0000000000000001); //A4: 7
    assertEquals(9, row1.getCell(3).getNumericCellValue(), 0.0000000000000001); //D1: 9
    assertEquals(11, row1.getCell(4).getNumericCellValue(), 0.0000000000000001); //E1: 11

    //A1: =SUM(G1:G3)
    valueA1 = _evaluator.evaluate(cellA1);
    assertEquals(6, valueA1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA1.getCellType());
    testToFormulaString(cellA1, "SUM(G1:G3)");
   
    //A2: =SUM(E2:IV2) IV: 256
    valueA2 = _evaluator.evaluate(cellA2);
    assertEquals(2, valueA2.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA2.getCellType());
    testToFormulaString(cellA2, "SUM(E2:IV2)");

    //A3: =SUM(IV3:IV3) IV: 256
    cellA3 = row3.getCell(0); //A3: =SUM(IU3:IV3)
    valueA6 = _evaluator.evaluate(cellA3);
    assertEquals(0, valueA6.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA6.getCellType());
    testToFormulaString(cellA3, "SUM(IV3:IV3)");
   
    //A5: =SUM(C1:D1) -> =SUM(D1:E1)
    cellA5 = row5.getCell(0);
    valueA5 = _evaluator.evaluate(cellA5);
    assertEquals(20, valueA5.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA5.getCellType());
    testToFormulaString(cellA5, "SUM(D1:E1)");
   
    //A6: =SUM(B1:D1) -> =SUM(B1:E1)
    cellA6 = row6.getCell(0);
    valueA6 = _evaluator.evaluate(cellA6);
    assertEquals(20, valueA6.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueA6.getCellType());
    testToFormulaString(cellA6, "SUM(B1:E1)");
   
View Full Code Here


  }
 
  @Test
  public void testLoadHyperlinks() {
    Worksheet sheet1 = (Worksheet)_workbook.getSheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    Row row4 = sheet1.getRow(3);
    Row row5 = sheet1.getRow(4);
    Row row6 = sheet1.getRow(5);
    Row row7 = sheet1.getRow(6);
   
    Cell cellA1 = row1.getCell(0);
    Cell cellA2 = row2.getCell(0);
    Cell cellA3 = row3.getCell(0);
    Cell cellA4 = row4.getCell(0);
    Cell cellA5 = row5.getCell(0);
    Cell cellA6 = row6.getCell(0);
    Cell cellA7 = row7.getCell(0);
   
//    BookHelper.evaluate((Book)_workbook, cellA2);
    Hyperlink hlinkA1 = Utils.getHyperlink(cellA1);
    Hyperlink hlinkA2 = Utils.getHyperlink(cellA2);
    Hyperlink hlinkA3 = Utils.getHyperlink(cellA3);
View Full Code Here

  }
 
  @Test
  public void testSortByColumns() {
    Worksheet sheet1 = (Worksheet)_workbook.getSheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    Row row4 = sheet1.getRow(3);
    Row row5 = sheet1.getRow(4);
    Row row6 = sheet1.getRow(5);
    Row row7 = sheet1.getRow(6);
    Row row8 = sheet1.getRow(7);
    Row row9 = sheet1.getRow(8);
    Row row10 = sheet1.getRow(9);
    Row row11 = sheet1.getRow(10);
    Row row12 = sheet1.getRow(11);
    Row row13 = sheet1.getRow(12);
   
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row2.getCell(0).getNumericCellValue(), 0.0000000000000001)//A2: 2
    assertEquals(3, row3.getCell(0).getNumericCellValue(), 0.0000000000000001); //A3: 3
    assertEquals("a", row4.getCell(0).getStringCellValue()); //A4: "a"
    assertEquals("b", row5.getCell(0).getStringCellValue()); //A5: "b"
    assertEquals("c", row6.getCell(0).getStringCellValue()); //A6: "c"
    assertEquals(ErrorConstants.ERROR_VALUE, row7.getCell(0).getErrorCellValue()); //A7: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row8.getCell(0).getErrorCellValue()); //A8: #REF!
    assertNull(row9.getCell(0)); //A9: null
    assertEquals(ErrorConstants.ERROR_VALUE, row10.getCell(0).getErrorCellValue()); //A10: #VALUE!
    assertEquals(true, row11.getCell(0).getBooleanCellValue()); //A11: TRUE
    assertEquals(false, row12.getCell(0).getBooleanCellValue()); //A12: FALSE
   
    assertEquals(1, row1.getCell(1).getNumericCellValue(), 0.0000000000000001); //B1: 1
    assertEquals(2, row2.getCell(1).getNumericCellValue(), 0.0000000000000001)//B2: 2
    assertEquals(3, row3.getCell(1).getNumericCellValue(), 0.0000000000000001); //B3: 3
    assertEquals(4, row4.getCell(1).getNumericCellValue(), 0.0000000000000001); //B4: 4
    assertEquals(5, row5.getCell(1).getNumericCellValue(), 0.0000000000000001)//B5: 5
    assertEquals(6, row6.getCell(1).getNumericCellValue(), 0.0000000000000001); //B6: 6
    assertEquals(7, row7.getCell(1).getNumericCellValue(), 0.0000000000000001); //B7: 7
    assertEquals(8, row8.getCell(1).getNumericCellValue(), 0.0000000000000001)//B8: 8
    assertEquals(9, row9.getCell(1).getNumericCellValue(), 0.0000000000000001); //B9: 9
    assertEquals(10, row10.getCell(1).getNumericCellValue(), 0.0000000000000001); //B10: 10
    assertEquals(11, row11.getCell(1).getNumericCellValue(), 0.0000000000000001)//B11: 11
    assertEquals(12, row12.getCell(1).getNumericCellValue(), 0.0000000000000001); //B12: 12
   
    //C9: =B8
    Cell cellC9 = row9.getCell(2);
    CellValue valueC9 = _evaluator.evaluate(cellC9);
    assertEquals(8, valueC9.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC9.getCellType());
    testToFormulaString(cellC9, "B8");
   
    //C13: =B12
    Cell cellC13 = row13.getCell(2);
    CellValue valueC13 = _evaluator.evaluate(cellC13);
    assertEquals(12, valueC13.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC13.getCellType());
    testToFormulaString(cellC13, "B12");
   
    //Sort A1:C12
    ChangeInfo info = BookHelper.sort(sheet1, 0, 0, 11, 2, ((RangeImpl)Utils.getRange(sheet1, 0, 0)).getRefs().iterator().next(), false,
        null, 0, false, null, false, BookHelper.SORT_HEADER_NO, 0, false, false, 0,
        BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT);
    Set<Ref> last = info.getToEval();
    Set<Ref> all = info.getAffected();
    _evaluator.notifySetFormula(cellC13);

    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row2.getCell(0).getNumericCellValue(), 0.0000000000000001)//A2: 2
    assertEquals(3, row3.getCell(0).getNumericCellValue(), 0.0000000000000001); //A3: 3
    assertEquals("a", row4.getCell(0).getStringCellValue()); //A4: "a"
    assertEquals("b", row5.getCell(0).getStringCellValue()); //A5: "b"
    assertEquals("c", row6.getCell(0).getStringCellValue()); //A6: "c"
    assertEquals(false, row7.getCell(0).getBooleanCellValue()); //A7: FALSE
    assertEquals(true, row8.getCell(0).getBooleanCellValue()); //A8: TRUE
    assertEquals(ErrorConstants.ERROR_VALUE, row9.getCell(0).getErrorCellValue()); //A9: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row10.getCell(0).getErrorCellValue()); //A10: #REF!
    assertEquals(ErrorConstants.ERROR_VALUE, row11.getCell(0).getErrorCellValue()); //A11: #VALUE!
    assertNull(row12.getCell(0)); //A9: null
   
    assertEquals(1, row1.getCell(1).getNumericCellValue(), 0.0000000000000001); //B1: 1
    assertEquals(2, row2.getCell(1).getNumericCellValue(), 0.0000000000000001)//B2: 2
    assertEquals(3, row3.getCell(1).getNumericCellValue(), 0.0000000000000001); //B3: 3
    assertEquals(4, row4.getCell(1).getNumericCellValue(), 0.0000000000000001); //B4: 4
    assertEquals(5, row5.getCell(1).getNumericCellValue(), 0.0000000000000001)//B5: 5
    assertEquals(6, row6.getCell(1).getNumericCellValue(), 0.0000000000000001); //B6: 6
    assertEquals(12, row7.getCell(1).getNumericCellValue(), 0.0000000000000001); //B7: 12
    assertEquals(11, row8.getCell(1).getNumericCellValue(), 0.0000000000000001); //B8: 11
    assertEquals(7, row9.getCell(1).getNumericCellValue(), 0.0000000000000001); //B9: 7
    assertEquals(8, row10.getCell(1).getNumericCellValue(), 0.0000000000000001); //B10: 8
    assertEquals(10, row11.getCell(1).getNumericCellValue(), 0.0000000000000001); //B11: 10
    assertEquals(9, row12.getCell(1).getNumericCellValue(), 0.0000000000000001); //B12: 9

    //C9 -> C12: =B8 -> B11
    Cell cellC12 = row12.getCell(2);
    CellValue valueC12 = _evaluator.evaluate(cellC12);
    assertEquals(10, valueC12.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC12.getCellType());
    testToFormulaString(cellC12, "B11");
   
    //C13: =B12
    cellC13 = row13.getCell(2);
    valueC13 = _evaluator.evaluate(cellC13);
    assertEquals(9, valueC13.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC13.getCellType());
    testToFormulaString(cellC13, "B12");
  }
View Full Code Here

  }
 
  @Test
  public void testSortByRows() {
    Worksheet sheet1 = (Worksheet)_workbook.getSheet("Sheet1");
    Row row15 = sheet1.getRow(14);
    Row row16 = sheet1.getRow(15);
    Row row17 = sheet1.getRow(16);
   
    assertEquals(1, row15.getCell(0).getNumericCellValue(), 0.0000000000000001); //A15: 1
    assertEquals(2, row15.getCell(1).getNumericCellValue(), 0.0000000000000001); //B15: 2
    assertEquals(3, row15.getCell(2).getNumericCellValue(), 0.0000000000000001); //C15: 3
    assertEquals("a", row15.getCell(3).getStringCellValue()); //D15: "a"
    assertEquals("b", row15.getCell(4).getStringCellValue()); //E15: "b"
    assertEquals("c", row15.getCell(5).getStringCellValue()); //F15: "c"
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(6).getErrorCellValue()); //G15: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row15.getCell(7).getErrorCellValue()); //H15: #REF!
    assertNull(row15.getCell(8)); //I15: null
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(9).getErrorCellValue()); //J15: #VALUE!
    assertEquals(true, row15.getCell(10).getBooleanCellValue()); //K15: TRUE
    assertEquals(false, row15.getCell(11).getBooleanCellValue()); //L15: FALSE
   
    assertEquals("A", row16.getCell(0).getStringCellValue()); //A16: "A"
    assertEquals("B", row16.getCell(1).getStringCellValue()); //B16: "B"
    assertEquals("C", row16.getCell(2).getStringCellValue()); //C16: "C"
    assertEquals("D", row16.getCell(3).getStringCellValue()); //D16: "D"
    assertEquals("E", row16.getCell(4).getStringCellValue()); //E16: "E"
    assertEquals("F", row16.getCell(5).getStringCellValue()); //F16: "F"
    assertEquals("G", row16.getCell(6).getStringCellValue()); //G16: "G"
    assertEquals("H", row16.getCell(7).getStringCellValue()); //H16: "H"
    assertEquals("I", row16.getCell(8).getStringCellValue()); //I16: "I"
    assertEquals("J", row16.getCell(9).getStringCellValue()); //J16: "J"
    assertEquals("K", row16.getCell(10).getStringCellValue()); //K16: "K"
    assertEquals("L", row16.getCell(11).getStringCellValue()); //L16: "L"
   
    //I17: =H16
    Cell cellI17 = row17.getCell(8);
    CellValue valueI17 = _evaluator.evaluate(cellI17);
    assertEquals("H", valueI17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueI17.getCellType());
    testToFormulaString(cellI17, "H16");
   
    //M17: =L16
    Cell cellM17 = row17.getCell(12);
    CellValue valueM17 = _evaluator.evaluate(cellM17);
    assertEquals("L", valueM17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueM17.getCellType());
    testToFormulaString(cellM17, "L16");
   
    /*sort(Sheet sheet, int tRow, int lCol, int bRow, int rCol,
        Ref key1, boolean desc1, Ref key2, int type, boolean desc2, Ref key3, boolean desc3, int header, int orderCustom,
        boolean matchCase, boolean sortByRows, int sortMethod, int dataOption1, int dataOption2, int dataOption3) */

    //Sort A15:L17
    ChangeInfo info = BookHelper.sort(sheet1, 14, 0, 16, 11, ((RangeImpl)Utils.getRange(sheet1, 14, 0)).getRefs().iterator().next(), false,
        null, 0, false, null, false, BookHelper.SORT_HEADER_NO, 0, false, true, 0,
        BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT);
    Set<Ref> last = info.getToEval();
    Set<Ref> all = info.getAffected();
    _evaluator.notifySetFormula(cellM17);

    assertEquals(1, row15.getCell(0).getNumericCellValue(), 0.0000000000000001); //A15: 1
    assertEquals(2, row15.getCell(1).getNumericCellValue(), 0.0000000000000001); //B15: 2
    assertEquals(3, row15.getCell(2).getNumericCellValue(), 0.0000000000000001); //C15: 3
    assertEquals("a", row15.getCell(3).getStringCellValue()); //D15: "a"
    assertEquals("b", row15.getCell(4).getStringCellValue()); //E15: "b"
    assertEquals("c", row15.getCell(5).getStringCellValue()); //F15: "c"
    assertEquals(false, row15.getCell(6).getBooleanCellValue()); //G15: FALSE
    assertEquals(true, row15.getCell(7).getBooleanCellValue()); //H15: TRUE
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(8).getErrorCellValue()); //I15: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row15.getCell(9).getErrorCellValue()); //J15: #REF!
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(10).getErrorCellValue()); //K15: #VALUE!
    assertNull(row15.getCell(11)); //L15: null
   
    assertEquals("A", row16.getCell(0).getStringCellValue()); //A16: "A"
    assertEquals("B", row16.getCell(1).getStringCellValue()); //B16: "B"
    assertEquals("C", row16.getCell(2).getStringCellValue()); //C16: "C"
    assertEquals("D", row16.getCell(3).getStringCellValue()); //D16: "D"
    assertEquals("E", row16.getCell(4).getStringCellValue()); //E16: "E"
    assertEquals("F", row16.getCell(5).getStringCellValue()); //F16: "F"
    assertEquals("L", row16.getCell(6).getStringCellValue()); //G16: "L"
    assertEquals("K", row16.getCell(7).getStringCellValue()); //H16: "K"
    assertEquals("G", row16.getCell(8).getStringCellValue()); //I16: "G"
    assertEquals("H", row16.getCell(9).getStringCellValue()); //J16: "H"
    assertEquals("J", row16.getCell(10).getStringCellValue()); //K16: "J"
    assertEquals("I", row16.getCell(11).getStringCellValue()); //L16: "I"
   
    //I17 -> L17: =H16 -> K16
    Cell cellL17 = row17.getCell(11);
    CellValue valueL17 = _evaluator.evaluate(cellL17);
    assertEquals("J", valueL17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueL17.getCellType());
    testToFormulaString(cellL17, "K16");
   
    //M17: =L16
    cellM17 = row17.getCell(12);
    valueM17 = _evaluator.evaluate(cellM17);
    assertEquals("I", valueM17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueM17.getCellType());
    testToFormulaString(cellM17, "L16");
  }
View Full Code Here

  }
 
  @Test
  public void testCopyCell() {
    Worksheet sheet1 = _workbook.getWorksheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row1.getCell(1).getNumericCellValue(), 0.0000000000000001)//B1: 2
    assertEquals(3, row2.getCell(0).getNumericCellValue(), 0.0000000000000001); //A2: 3
    assertEquals(4, row2.getCell(1).getNumericCellValue(), 0.0000000000000001); //B2: 4
   
    //C3: =A1+7
    Cell cellC3 = row3.getCell(2);
    CellValue valueC3 = _evaluator.evaluate(cellC3);
    assertEquals(8, valueC3.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC3.getCellType());
    testToFormulaString(cellC3, "A1+7");
   
    //Copy cell (C3 -> D4)
    BookHelper.copyCell(cellC3, sheet1, 3, 3, Range.PASTE_ALL, Range.PASTEOP_NONE, false);
    _evaluator.notifySetFormula(cellC3);

    //A1,A2,A2,B2 stay as is
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row1.getCell(1).getNumericCellValue(), 0.0000000000000001)//B1: 2
    assertEquals(3, row2.getCell(0).getNumericCellValue(), 0.0000000000000001); //A2: 3
    assertEquals(4, row2.getCell(1).getNumericCellValue(), 0.0000000000000001); //B2: 4
   
    //C3 stay as is
    valueC3 = _evaluator.evaluate(cellC3);
    assertEquals(8, valueC3.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC3.getCellType());
    testToFormulaString(cellC3, "A1+7");
   
    //D4: =B2+7
    Row row4 = sheet1.getRow(3);
    Cell cellD4 = row4.getCell(3);
    CellValue valueD4 = _evaluator.evaluate(cellD4);
    assertEquals(11, valueD4.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueD4.getCellType());
    testToFormulaString(cellD4, "B2+7");
  }
View Full Code Here

  }
 
  @Test
  public void testCopyCellRefError2() {
    Worksheet sheet1 = _workbook.getWorksheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row1.getCell(1).getNumericCellValue(), 0.0000000000000001)//B1: 2
    assertEquals(3, row2.getCell(0).getNumericCellValue(), 0.0000000000000001); //A2: 3
    assertEquals(4, row2.getCell(1).getNumericCellValue(), 0.0000000000000001); //B2: 4
   
    //C3: =A1+7
    Cell cellC3 = row3.getCell(2);
    CellValue valueC3 = _evaluator.evaluate(cellC3);
    assertEquals(8, valueC3.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC3.getCellType());
    testToFormulaString(cellC3, "A1+7");
   
View Full Code Here

  }
 
  @Test
  public void testCopyCellRefError3() {
    Worksheet sheet1 = _workbook.getWorksheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row1.getCell(1).getNumericCellValue(), 0.0000000000000001)//B1: 2
    assertEquals(3, row2.getCell(0).getNumericCellValue(), 0.0000000000000001); //A2: 3
    assertEquals(4, row2.getCell(1).getNumericCellValue(), 0.0000000000000001); //B2: 4
    assertEquals(5, row1.getCell(4).getNumericCellValue(), 0.0000000000000001); //E1: 5
    assertEquals(6, row1.getCell(5).getNumericCellValue(), 0.0000000000000001); //F1: 6
   
    //D3: =SUM(E1:F1)
    Cell cellD3 = row3.getCell(3);
    CellValue valueD3 = _evaluator.evaluate(cellD3);
    assertEquals(11, valueD3.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueD3.getCellType());
    testToFormulaString(cellD3, "SUM(E1:F1)");
   
    //Copy cell (D3 -> XFD3)
    BookHelper.copyCell(cellD3, sheet1, 2, 16383, Range.PASTE_ALL, Range.PASTEOP_NONE, false);
    _evaluator.notifySetFormula(cellD3);

    //A1,A2,A2,B2,E1,F1 stay as is
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row1.getCell(1).getNumericCellValue(), 0.0000000000000001)//B1: 2
    assertEquals(3, row2.getCell(0).getNumericCellValue(), 0.0000000000000001); //A2: 3
    assertEquals(4, row2.getCell(1).getNumericCellValue(), 0.0000000000000001); //B2: 4
    assertEquals(5, row1.getCell(4).getNumericCellValue(), 0.0000000000000001); //E1: 5
    assertEquals(6, row1.getCell(5).getNumericCellValue(), 0.0000000000000001); //F1: 6
   
    //D3 stay as is
    valueD3 = _evaluator.evaluate(cellD3);
    assertEquals(11, valueD3.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueD3.getCellType());
    testToFormulaString(cellD3, "SUM(E1:F1)");
   
    //XFD3: #REF!
    Cell cellXFD3 = row3.getCell(16383);
    CellValue valueIV3 = _evaluator.evaluate(cellXFD3);
    assertEquals(ErrorConstants.ERROR_REF, valueIV3.getErrorValue());
    assertEquals(Cell.CELL_TYPE_ERROR, valueIV3.getCellType());
    testToFormulaString(cellXFD3, "SUM(#REF!)");
  }
View Full Code Here

  }
 
  @Test
  public void testSortByColumns() {
    Worksheet sheet1 = (Worksheet)_workbook.getSheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    Row row2 = sheet1.getRow(1);
    Row row3 = sheet1.getRow(2);
    Row row4 = sheet1.getRow(3);
    Row row5 = sheet1.getRow(4);
    Row row6 = sheet1.getRow(5);
    Row row7 = sheet1.getRow(6);
    Row row8 = sheet1.getRow(7);
    Row row9 = sheet1.getRow(8);
    Row row10 = sheet1.getRow(9);
    Row row11 = sheet1.getRow(10);
    Row row12 = sheet1.getRow(11);
    Row row13 = sheet1.getRow(12);
   
    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row2.getCell(0).getNumericCellValue(), 0.0000000000000001)//A2: 2
    assertEquals(3, row3.getCell(0).getNumericCellValue(), 0.0000000000000001); //A3: 3
    assertEquals("a", row4.getCell(0).getStringCellValue()); //A4: "a"
    assertEquals("b", row5.getCell(0).getStringCellValue()); //A5: "b"
    assertEquals("c", row6.getCell(0).getStringCellValue()); //A6: "c"
    assertEquals(ErrorConstants.ERROR_VALUE, row7.getCell(0).getErrorCellValue()); //A7: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row8.getCell(0).getErrorCellValue()); //A8: #REF!
    assertNull(row9.getCell(0)); //A9: null
    assertEquals(ErrorConstants.ERROR_VALUE, row10.getCell(0).getErrorCellValue()); //A10: #VALUE!
    assertEquals(true, row11.getCell(0).getBooleanCellValue()); //A11: TRUE
    assertEquals(false, row12.getCell(0).getBooleanCellValue()); //A12: FALSE
   
    assertEquals(1, row1.getCell(1).getNumericCellValue(), 0.0000000000000001); //B1: 1
    assertEquals(2, row2.getCell(1).getNumericCellValue(), 0.0000000000000001)//B2: 2
    assertEquals(3, row3.getCell(1).getNumericCellValue(), 0.0000000000000001); //B3: 3
    assertEquals(4, row4.getCell(1).getNumericCellValue(), 0.0000000000000001); //B4: 4
    assertEquals(5, row5.getCell(1).getNumericCellValue(), 0.0000000000000001)//B5: 5
    assertEquals(6, row6.getCell(1).getNumericCellValue(), 0.0000000000000001); //B6: 6
    assertEquals(7, row7.getCell(1).getNumericCellValue(), 0.0000000000000001); //B7: 7
    assertEquals(8, row8.getCell(1).getNumericCellValue(), 0.0000000000000001)//B8: 8
    assertEquals(9, row9.getCell(1).getNumericCellValue(), 0.0000000000000001); //B9: 9
    assertEquals(10, row10.getCell(1).getNumericCellValue(), 0.0000000000000001); //B10: 10
    assertEquals(11, row11.getCell(1).getNumericCellValue(), 0.0000000000000001)//B11: 11
    assertEquals(12, row12.getCell(1).getNumericCellValue(), 0.0000000000000001); //B12: 12
   
    //C9: =B8
    Cell cellC9 = row9.getCell(2);
    CellValue valueC9 = _evaluator.evaluate(cellC9);
    assertEquals(8, valueC9.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC9.getCellType());
    testToFormulaString(cellC9, "B8");
   
    //C13: =B12
    Cell cellC13 = row13.getCell(2);
    CellValue valueC13 = _evaluator.evaluate(cellC13);
    assertEquals(12, valueC13.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC13.getCellType());
    testToFormulaString(cellC13, "B12");
   
    //Sort A1:C12
    ChangeInfo info = BookHelper.sort(sheet1, 0, 0, 11, 2, ((RangeImpl)Utils.getRange(sheet1, 0, 0)).getRefs().iterator().next(), false,
        null, 0, false, null, false, BookHelper.SORT_HEADER_NO, 0, false, false, 0,
        BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT);
    Set<Ref> last = info.getToEval();
    Set<Ref> all = info.getAffected();
    _evaluator.notifySetFormula(cellC13);

    assertEquals(1, row1.getCell(0).getNumericCellValue(), 0.0000000000000001); //A1: 1
    assertEquals(2, row2.getCell(0).getNumericCellValue(), 0.0000000000000001)//A2: 2
    assertEquals(3, row3.getCell(0).getNumericCellValue(), 0.0000000000000001); //A3: 3
    assertEquals("a", row4.getCell(0).getStringCellValue()); //A4: "a"
    assertEquals("b", row5.getCell(0).getStringCellValue()); //A5: "b"
    assertEquals("c", row6.getCell(0).getStringCellValue()); //A6: "c"
    assertEquals(false, row7.getCell(0).getBooleanCellValue()); //A7: FALSE
    assertEquals(true, row8.getCell(0).getBooleanCellValue()); //A8: TRUE
    assertEquals(ErrorConstants.ERROR_VALUE, row9.getCell(0).getErrorCellValue()); //A9: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row10.getCell(0).getErrorCellValue()); //A10: #REF!
    assertEquals(ErrorConstants.ERROR_VALUE, row11.getCell(0).getErrorCellValue()); //A11: #VALUE!
    assertNull(row12.getCell(0)); //A9: null
   
    assertEquals(1, row1.getCell(1).getNumericCellValue(), 0.0000000000000001); //B1: 1
    assertEquals(2, row2.getCell(1).getNumericCellValue(), 0.0000000000000001)//B2: 2
    assertEquals(3, row3.getCell(1).getNumericCellValue(), 0.0000000000000001); //B3: 3
    assertEquals(4, row4.getCell(1).getNumericCellValue(), 0.0000000000000001); //B4: 4
    assertEquals(5, row5.getCell(1).getNumericCellValue(), 0.0000000000000001)//B5: 5
    assertEquals(6, row6.getCell(1).getNumericCellValue(), 0.0000000000000001); //B6: 6
    assertEquals(12, row7.getCell(1).getNumericCellValue(), 0.0000000000000001); //B7: 12
    assertEquals(11, row8.getCell(1).getNumericCellValue(), 0.0000000000000001); //B8: 11
    assertEquals(7, row9.getCell(1).getNumericCellValue(), 0.0000000000000001); //B9: 7
    assertEquals(8, row10.getCell(1).getNumericCellValue(), 0.0000000000000001); //B10: 8
    assertEquals(10, row11.getCell(1).getNumericCellValue(), 0.0000000000000001); //B11: 10
    assertEquals(9, row12.getCell(1).getNumericCellValue(), 0.0000000000000001); //B12: 9

    //C9 -> C12: =B8 -> B11
    Cell cellC12 = row12.getCell(2);
    CellValue valueC12 = _evaluator.evaluate(cellC12);
    assertEquals(10, valueC12.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC12.getCellType());
    testToFormulaString(cellC12, "B11");
   
    //C13: =B12
    cellC13 = row13.getCell(2);
    valueC13 = _evaluator.evaluate(cellC13);
    assertEquals(9, valueC13.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC13.getCellType());
    testToFormulaString(cellC13, "B12");
  }
View Full Code Here

  }
 
  @Test
  public void testSortByRows() {
    Worksheet sheet1 = (Worksheet)_workbook.getSheet("Sheet1");
    Row row15 = sheet1.getRow(14);
    Row row16 = sheet1.getRow(15);
    Row row17 = sheet1.getRow(16);
   
    assertEquals(1, row15.getCell(0).getNumericCellValue(), 0.0000000000000001); //A15: 1
    assertEquals(2, row15.getCell(1).getNumericCellValue(), 0.0000000000000001); //B15: 2
    assertEquals(3, row15.getCell(2).getNumericCellValue(), 0.0000000000000001); //C15: 3
    assertEquals("a", row15.getCell(3).getStringCellValue()); //D15: "a"
    assertEquals("b", row15.getCell(4).getStringCellValue()); //E15: "b"
    assertEquals("c", row15.getCell(5).getStringCellValue()); //F15: "c"
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(6).getErrorCellValue()); //G15: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row15.getCell(7).getErrorCellValue()); //H15: #REF!
    assertNull(row15.getCell(8)); //I15: null
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(9).getErrorCellValue()); //J15: #VALUE!
    assertEquals(true, row15.getCell(10).getBooleanCellValue()); //K15: TRUE
    assertEquals(false, row15.getCell(11).getBooleanCellValue()); //L15: FALSE
   
    assertEquals("A", row16.getCell(0).getStringCellValue()); //A16: "A"
    assertEquals("B", row16.getCell(1).getStringCellValue()); //B16: "B"
    assertEquals("C", row16.getCell(2).getStringCellValue()); //C16: "C"
    assertEquals("D", row16.getCell(3).getStringCellValue()); //D16: "D"
    assertEquals("E", row16.getCell(4).getStringCellValue()); //E16: "E"
    assertEquals("F", row16.getCell(5).getStringCellValue()); //F16: "F"
    assertEquals("G", row16.getCell(6).getStringCellValue()); //G16: "G"
    assertEquals("H", row16.getCell(7).getStringCellValue()); //H16: "H"
    assertEquals("I", row16.getCell(8).getStringCellValue()); //I16: "I"
    assertEquals("J", row16.getCell(9).getStringCellValue()); //J16: "J"
    assertEquals("K", row16.getCell(10).getStringCellValue()); //K16: "K"
    assertEquals("L", row16.getCell(11).getStringCellValue()); //L16: "L"
   
    //I17: =H16
    Cell cellI17 = row17.getCell(8);
    CellValue valueI17 = _evaluator.evaluate(cellI17);
    assertEquals("H", valueI17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueI17.getCellType());
    testToFormulaString(cellI17, "H16");
   
    //M17: =L16
    Cell cellM17 = row17.getCell(12);
    CellValue valueM17 = _evaluator.evaluate(cellM17);
    assertEquals("L", valueM17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueM17.getCellType());
    testToFormulaString(cellM17, "L16");
   
    /*sort(Sheet sheet, int tRow, int lCol, int bRow, int rCol,
        Ref key1, boolean desc1, Ref key2, int type, boolean desc2, Ref key3, boolean desc3, int header, int orderCustom,
        boolean matchCase, boolean sortByRows, int sortMethod, int dataOption1, int dataOption2, int dataOption3) */

    //Sort A15:L17
    ChangeInfo info = BookHelper.sort(sheet1, 14, 0, 16, 11, ((RangeImpl)Utils.getRange(sheet1, 14, 0)).getRefs().iterator().next(), false,
        null, 0, false, null, false, BookHelper.SORT_HEADER_NO, 0, false, true, 0,
        BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT, BookHelper.SORT_NORMAL_DEFAULT);
    Set<Ref> last = info.getToEval();
    Set<Ref> all = info.getAffected();
    _evaluator.notifySetFormula(cellM17);

    assertEquals(1, row15.getCell(0).getNumericCellValue(), 0.0000000000000001); //A15: 1
    assertEquals(2, row15.getCell(1).getNumericCellValue(), 0.0000000000000001); //B15: 2
    assertEquals(3, row15.getCell(2).getNumericCellValue(), 0.0000000000000001); //C15: 3
    assertEquals("a", row15.getCell(3).getStringCellValue()); //D15: "a"
    assertEquals("b", row15.getCell(4).getStringCellValue()); //E15: "b"
    assertEquals("c", row15.getCell(5).getStringCellValue()); //F15: "c"
    assertEquals(false, row15.getCell(6).getBooleanCellValue()); //G15: FALSE
    assertEquals(true, row15.getCell(7).getBooleanCellValue()); //H15: TRUE
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(8).getErrorCellValue()); //I15: #VALUE!
    assertEquals(ErrorConstants.ERROR_REF, row15.getCell(9).getErrorCellValue()); //J15: #REF!
    assertEquals(ErrorConstants.ERROR_VALUE, row15.getCell(10).getErrorCellValue()); //K15: #VALUE!
    assertNull(row15.getCell(11)); //L15: null
   
    assertEquals("A", row16.getCell(0).getStringCellValue()); //A16: "A"
    assertEquals("B", row16.getCell(1).getStringCellValue()); //B16: "B"
    assertEquals("C", row16.getCell(2).getStringCellValue()); //C16: "C"
    assertEquals("D", row16.getCell(3).getStringCellValue()); //D16: "D"
    assertEquals("E", row16.getCell(4).getStringCellValue()); //E16: "E"
    assertEquals("F", row16.getCell(5).getStringCellValue()); //F16: "F"
    assertEquals("L", row16.getCell(6).getStringCellValue()); //G16: "L"
    assertEquals("K", row16.getCell(7).getStringCellValue()); //H16: "K"
    assertEquals("G", row16.getCell(8).getStringCellValue()); //I16: "G"
    assertEquals("H", row16.getCell(9).getStringCellValue()); //J16: "H"
    assertEquals("J", row16.getCell(10).getStringCellValue()); //K16: "J"
    assertEquals("I", row16.getCell(11).getStringCellValue()); //L16: "I"
   
    //I17 -> L17: =H16 -> K16
    Cell cellL17 = row17.getCell(11);
    CellValue valueL17 = _evaluator.evaluate(cellL17);
    assertEquals("J", valueL17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueL17.getCellType());
    testToFormulaString(cellL17, "K16");
   
    //M17: =L16
    cellM17 = row17.getCell(12);
    valueM17 = _evaluator.evaluate(cellM17);
    assertEquals("I", valueM17.getStringValue());
    assertEquals(Cell.CELL_TYPE_STRING, valueM17.getCellType());
    testToFormulaString(cellM17, "L16");
  }
View Full Code Here

  }
 
  @Test
  public void testGetBgColor() {
    Worksheet sheet1 = _workbook.getWorksheet("Sheet1");
    Row row1 = sheet1.getRow(0);
    assertEquals("FFFF0000", ((XSSFColor)row1.getCell(0).getCellStyle().getFillForegroundColorColor()).getARGBHex()); //A1: Red
  }
View Full Code Here

TOP

Related Classes of org.zkoss.poi.ss.usermodel.Row

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.