Package org.zkoss.zss.model

Examples of org.zkoss.zss.model.Cell


   * @param src source cell
   * @param row row index of the destination cell
   * @param col column index of the destination cell
   */
  public void copyCell(Cell src, int row, int col) {
    final Cell cell = setCellValue(row, col, null);
    src.copy(cell);
  }
View Full Code Here


   * @param src source cell
   * @param row row index of the destination cell.
   * @param col column index of the destination cell.
   */
  /*package*/ void copyCellFormat(Cell src, int row, int col) {
    final Cell cell = setCellValue(row, col, null);
    ((CellImpl)src).copyFormat(cell);
  }
View Full Code Here

    }
    //for all cells
    final List cells = _matrix.getCells(left, top, right, bottom, new LinkedList());

    //First cell with value to be left-top cell
    Cell thecell = null;
    for (final Iterator it = cells.iterator(); it.hasNext();) {
      final Cell x = (Cell) it.next();
      final Object value = x.getValue();
      if (value != null) { //found
        thecell = x;
        break;
      }
    }
   
    //get the specified cell. If not exists, create one.
    if (thecell == null) {   
      thecell = _matrix.getCellIndex(top, left).getCell();
    }

    //move the reference
    final FormatImpl fmt = getFormatOrCreate(thecell);
    final int cellrow = thecell.getRow();
    final int cellcol = thecell.getColumn();
    if (cellrow != top || cellcol != left) {
      //preserve the left-top format
      final CellIndex ltci = _matrix.getCellIndexIfExists(top, left);
      final Cell ltcell = ltci != null ? ltci.getCell() : null;
      final Format ltfmt = ltcell != null ? ltcell.getFormat() : null;
 
      //move the cell to left-top
      final int coloff = left - cellcol;
      final int rowoff = top - cellrow;
      _matrix.moveRange(_matrix, cellcol, cellrow, cellcol, cellrow, rowoff, coloff);
     
      //recover the moved border if any
      final Cell x = _matrix.getCellIndex(cellrow, cellcol).getCell();
      if (cellcol == left) { //left border
        getFormatOrCreate(x).setBorderLeft(fmt.getBorderLeft());
      }
      if (cellrow == top) { //top border
        getFormatOrCreate(x).setBorderTop(fmt.getBorderTop());
      }
      if (cellcol == right) { //right border
        getFormatOrCreate(x).setBorderRight(fmt.getBorderRight());
      }
      if (cellrow == bottom) { //bottom border
        getFormatOrCreate(x).setBorderBottom(fmt.getBorderBottom());
      }
     
      //assign ltfmt border to fmt
      if (ltfmt != null) {
        fmt.setBorderLeft(ltfmt.getBorderLeft());
        fmt.setBorderTop(ltfmt.getBorderTop());
        fmt.setBorderRight(ltfmt.getBorderRight());
        fmt.setBorderBottom(ltfmt.getBorderBottom());
      } else {
        fmt.setBorderLeft(null);
        fmt.setBorderTop(null);
        fmt.setBorderRight(null);
        fmt.setBorderBottom(null);
      }
     
    }
   
    //1. copy format to all merged cells from the cell
    //2. set contents to null
    //3. check border consistency
    //4. clear interior border of the merged cells
    BorderStyle lstyle = fmt.getBorderLeft();
    BorderStyle tstyle = fmt.getBorderTop();
   
    BorderLineStyle lline = lstyle.getBorderLineStyle();
    BorderLineStyle tline = tstyle.getBorderLineStyle();
    BorderLineStyle rline = null;
    BorderLineStyle bline = null;
    String lcolor = lstyle.getBorderColor();
    String tcolor = tstyle.getBorderColor();
    String rcolor = null;
    String bcolor = null;
    boolean lequal = true;
    boolean tequal = true;
    boolean requal = true;
    boolean bequal = true;
   
    for (int row = top; row <= bottom; ++row) {
      for (int col = left; col <= right; ++col) {
        if (row == top && col == left) { //skip the first cell
          continue;
        }
        final CellImpl x = (CellImpl) _matrix.getCellIndex(row, col).getCell();
        x.mySetValue(null, false); //set content to null, but don't fire event
       
        FormatImpl xfmt;
        try {
          xfmt = (FormatImpl) fmt.clone();
        } catch (CloneNotSupportedException e) {
          throw ModelException.Aide.wrap(e);
        }
        final FormatImpl ofmt = getFormatOrCreate(x);
        //check top border
        if (row == top) {
          if (tequal) {
            final BorderStyle tborder = ofmt.getBorderTop();
            final BorderLineStyle tl  = tborder.getBorderLineStyle();
            final String tc = tborder.getBorderColor();
            if (tline != tl) {
              tequal = false;
            }
            if (!tcolor.equals(tc)) {
              tequal = false;
            }
            if (tequal) {
              xfmt.setBorderTop(tborder);
            }
          }
        } else {
          xfmt.setBorderTop(null);
        }
        //check bottom border
        if (row == bottom) {
          if (bequal) {
            final BorderStyle bborder = ofmt.getBorderBottom();
            final BorderLineStyle bl  = bborder.getBorderLineStyle();
            final String bc = bborder.getBorderColor();
            if (bline == null) {
              bline = bl;
            } else if (bline != bl) {
              bequal = false;
            }
            if (bcolor == null) {
              bcolor = bc;
            } else if (!bcolor.equals(bc)) {
              bequal = false;
            }
            if (bequal) {
              xfmt.setBorderBottom(bborder);
            }
          }
        } else {
          xfmt.setBorderBottom(null);
        }
        //check left border
        if (col == left) {
          if (lequal) {
            final BorderStyle lborder = ofmt.getBorderLeft();
            final BorderLineStyle ll  = lborder.getBorderLineStyle();
            final String lc = lborder.getBorderColor();
            if (lline != ll) {
              lequal = false;
            }
            if (!lcolor.equals(lc)) {
              lequal = false;
            }
            if (lequal) {
              xfmt.setBorderLeft(lborder);
            }
          }
        } else {
          xfmt.setBorderLeft(null);
        }
        //check right border
        if (col == right) {
          if (requal) {
            final BorderStyle rborder = ofmt.getBorderRight();
            final BorderLineStyle rl  = rborder.getBorderLineStyle();
            final String rc = rborder.getBorderColor();
            if (rline == null) {
              rline = rl;
            } else if (rline != rl) {
              requal = false;
            }
            if (rcolor == null) {
              rcolor = rc;
            } else if (!rcolor.equals(rc)) {
              requal = false;
            }
            if (requal) {
              xfmt.setBorderRight(rborder);
            }
          }
        } else {
          xfmt.setBorderRight(null);
        }
        x.mySetFormat(xfmt, false); //copy formats
      }
    }

    //handle the merged cell left/right border
    for (int row = top; row <= bottom; ++row) {
      if (!lequal) {
        final Cell x = _matrix.getCellIndex(row, left).getCell();
        final FormatImpl xfmt = getFormatOrCreate(x);
        xfmt.setBorderLeft(null);
      }
      if (!requal) {
        final Cell x = _matrix.getCellIndex(row, right).getCell();
        final FormatImpl xfmt = getFormatOrCreate(x);
        xfmt.setBorderRight(null);
      }
    }
   
    //handle the merged cell top/bottom border
    for (int col = left; col <= right; ++col) {
      if (!tequal) {
        final Cell x = _matrix.getCellIndex(top, col).getCell();
        final FormatImpl xfmt = getFormatOrCreate(x);
        xfmt.setBorderTop(null);
      }
      if (!requal) {
        final Cell x = _matrix.getCellIndex(bottom, col).getCell();
        final FormatImpl xfmt = getFormatOrCreate(x);
        xfmt.setBorderBottom(null);
      }
    }

    final Cell dstcell =  _matrix.getCellIndex(top, left).getCell();
    final RangeMerge rng = new RangeMerge(this, left, top, right, bottom);
    final Range org = ((CellImpl)dstcell).setRangeMerge(rng);
    if (org == null) { //new added merge
      _book.fireSSDataEvent(new SSDataEvent(rng, org, SSDataEvent.MERGE_ADD, SSDataEvent.MOVE_NO));
    } else { //old merge change size and move
View Full Code Here

 
  private void copyLeftFormat(int left, int top, int right, int bottom) {
    if (left > 0) { //left == 0, no need to copy format
      final List lst = _matrix.getCells(left-1, top, left-1, bottom, new LinkedList());
      for (final Iterator it = lst.iterator(); it.hasNext();) {
        final Cell cell = (Cell) it.next();
        final int row = cell.getRow();
        final Format format = cell.getFormat();
        if (format != null) {
          for(int k = left; k <= right; ++k) {
            copyCellFormat(cell, row, k);
          }
          final Range xrng = new RangeSimple(this, null, left, row, right, row);
View Full Code Here

 
  private void copyTopFormat(int left, int top, int right, int bottom) {
    if (top > 0) { //top == 0, no need to copy format
      final List lst = _matrix.getCells(left, top-1, right, top-1, new LinkedList());
      for (final Iterator it = lst.iterator(); it.hasNext();) {
        final Cell cell = (Cell) it.next();
        final int col = cell.getColumn();
        final Format format = cell.getFormat();
        if (format != null) {
          for(int r = top; r <= bottom; ++r) {
            copyCellFormat(cell, r, col);
          }
          final Range xrng = new RangeSimple(this, null, col, top, col, bottom);
View Full Code Here

  }
  public void testCrossSheetRef() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));

    Cell cell = ((SheetImpl)sheet1).setCellEditText(2,0,"=sheet2!A1"); //sheet2!A1
    assertEquals("#REF!", cell.getResult().toString());

    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"=sheet1!A1"); //A3: sheet1!A1
    assertEquals(0d, 0d, 0d);
   
    ((SheetImpl)sheet1).setCellEditText(0,0,"12345.6789"); //A1: 12345.6789
    assertEquals("12345.6789", cell.getResult().toString());

    ((SheetImpl)sheet1).setCellEditText(0,0,"12345678901234567890"); //A1: 12345.6789
    assertEquals("1.23456789012345E19", cell.getResult().toString());
  }
View Full Code Here

 
  public void testSetEditText() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    Cell cell = ((SheetImpl)sheet1).setCellEditText(2,0,"3/4/98"); //A3
    assertEquals("1998*03*04", DF.format(cell.getValue()));

    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"03/04/98"); //A3
    assertEquals("1998*03*04", DF.format(cell.getValue()));
   
    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"3/4/1998"); //A3
    assertEquals("1998*03*04", DF.format(cell.getValue()));

    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"03/04/1998"); //A3
    assertEquals("1998*03*04", DF.format(cell.getValue()));

    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"9:52 pm"); //A3
    assertEquals("21:52:00", TF.format(cell.getValue()));

    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"21:52"); //A3
    assertEquals("21:52:00", TF.format(cell.getValue()));
 
    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"21:56:34"); //A3
    assertEquals("21:56:34", TF.format(cell.getValue()));
 
    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"12345678901234567890"); //A3
    double double15 = ((Double)cell.getValue()).doubleValue();
    assertEquals(12345678901234500000d, double15, 0d);

    cell = ((SheetImpl)sheet1).setCellEditText(2,0,"-12345678901234567890"); //A3
    double15 = ((Double)cell.getValue()).doubleValue();
    assertEquals(-12345678901234500000d, double15, 0d);
  }
View Full Code Here

  public void testPercentage() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    Cell cellA1 = ((SheetImpl)sheet1).setCellEditText(0,0,"64493.7"); //A1
    Cell cellA2 = ((SheetImpl)sheet1).setCellEditText(1,0,"0"); //A2
    Cell cellA3 = ((SheetImpl)sheet1).setCellEditText(2,0,"=A1-A2"); //A3
    Cell cellA4 = ((SheetImpl)sheet1).setCellEditText(3,0,"=A1/A3"); //A4
    FormatImpl format = new FormatImpl();
    format.setFormatCodes("0.00%");
    cellA4.setFormat(format);
    String result = cellA4.getText();
    assertEquals("100.00%", result);
   
  }
View Full Code Here

 
  public void testErrors() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    Cell cellA1 = ((SheetImpl)sheet1).setCellEditText(0,0,"#NULL!"); //A1
    assertEquals(SSError.NULL, cellA1.getResult());
   
    Cell cellA2 = ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(1), cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(0,0,"#DIV/0!"); //A1
    assertEquals(SSError.DIV0, cellA1.getResult());
   
    ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(2), cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(1,0,"=A1+2"); //A2
    assertEquals(SSError.DIV0, cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(0,0,"#VALUE!"); //A1
    assertEquals(SSError.VALUE, cellA1.getResult());

    ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(3), cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(0,0,"#REF!");
    assertEquals(SSError.REF, cellA1.getResult());
   
    ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(4), cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(0,0,"#NAME?");
    assertEquals(SSError.NAME, cellA1.getResult());

    ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(5), cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(0,0,"#NUM!");
    assertEquals(SSError.NUM, cellA1.getResult());

    ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(6), cellA2.getResult());

    ((SheetImpl)sheet1).setCellEditText(0,0,"#N/A");
    assertEquals(SSError.NA, cellA1.getResult());

    ((SheetImpl)sheet1).setCellEditText(1,0,"=ERROR.TYPE(A1)"); //A2
    assertEquals(new Integer(7), cellA2.getResult());
  }
View Full Code Here

  public void testCell1() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    ((SheetImpl)sheet1).setCellValue(2,0,null); //A3
    final Cell cell = sheet1.getCell(2,0);
    assertCellEquals(cell, 2, 0, null);
   
    ((SheetImpl)sheet1).setCellValue(0,1,new Integer(1)); //B1
    assertCellEquals(sheet1.getCell(0, 1), 0, 1, new Integer(1));

    ((SheetImpl)sheet1).setCellValue(0,2,new Integer(2)); //C1
    assertCellEquals(sheet1.getCell(0, 2), 0, 2, new Integer(2));
   
    ((SheetImpl)sheet1).setCellValue(0,3,new Integer(3)); //D1
    assertCellEquals(sheet1.getCell(0, 3), 0, 3, new Integer(3));
   

    cell.setFormula("=SUM(B1)");
    Object result = cell.getResult();
    assertEquals(new Integer(1).doubleValue(), ((Number)result).doubleValue(), 0d);
   
    cell.setFormula("=SUM(C1)");
    result = cell.getResult();
    assertEquals(new Integer(2).doubleValue(), ((Number)result).doubleValue(), 0d);

    cell.setFormula("=SUM(D1)");
    result = cell.getResult();
    assertEquals(new Integer(3).doubleValue(), ((Number)result).doubleValue(), 0d);

    cell.setFormula("=SUM(E1)");
    result = cell.getResult();
    assertEquals(new Integer(0).doubleValue(), ((Number)result).doubleValue(), 0d);

    //given String and do SUM()
    ((SheetImpl)sheet1).setCellValue(0,1,"1"); //B1
    assertCellEquals(sheet1.getCell(0, 1), 0, 1, "1");

    ((SheetImpl)sheet1).setCellValue(0,2,"2"); //C1
    assertCellEquals(sheet1.getCell(0, 2), 0, 2, "2");
   
    ((SheetImpl)sheet1).setCellValue(0,3,"3"); //D1
    assertCellEquals(sheet1.getCell(0, 3), 0, 3, "3");

    cell.setFormula("=SUM(B1)");
    result = cell.getResult();
    assertEquals(1d, ((Number)result).doubleValue(), 0d);
   
    cell.setFormula("=SUM(C1)");
    result = cell.getResult();
    assertEquals(2d, ((Number)result).doubleValue(), 0d);

    cell.setFormula("=SUM(D1)");
    result = cell.getResult();
    assertEquals(3d, ((Number)result).doubleValue(), 0d);
   
    //test one dimension range
    cell.setFormula("=SUM(B1:D1)");
    result = cell.getResult();
    assertEquals(0d, ((Number)result).doubleValue(), 0d);
   
    cell.setFormula("=SUM(B1:D1,\"1\")");
    result = cell.getResult();
    assertEquals(1d, ((Number)result).doubleValue(), 0d);

    cell.setFormula("=SUM(B1:D1,TRUE)");
    result = cell.getResult();
    assertEquals(1d, ((Number)result).doubleValue(), 0d);

    ((SheetImpl)sheet1).setCellValue(0,3, new Integer(3)); //D1
    assertCellEquals(sheet1.getCell(0, 3), 0, 3, new Integer(3));

    cell.setFormula("=SUM(B1:D1)");
    result = cell.getResult();
    assertEquals(3d, ((Number)result).doubleValue(), 0d);

    ((SheetImpl)sheet1).setCellValue(0,2, new Integer(2)); //C1
    assertCellEquals(sheet1.getCell(0, 2), 0, 2, new Integer(2));

    cell.setFormula("=SUM(B1:D1)");
    result = cell.getResult();
    assertEquals(5d, ((Number)result).doubleValue(), 0d);

    ((SheetImpl)sheet1).setCellValue(0,1, Boolean.TRUE); //B1
    assertCellEquals(sheet1.getCell(0, 1), 0, 1, Boolean.TRUE);

    cell.setFormula("=SUM(B1:D1)");
    result = cell.getResult();
    assertEquals(5d, ((Number)result).doubleValue(), 0d);

    ((SheetImpl)sheet1).setCellValue(0,1, new Integer(1)); //B1
    assertCellEquals(sheet1.getCell(0, 1), 0, 1, new Integer(1));

    cell.setFormula("=SUM(B1:D1)");
    result = cell.getResult();
    assertEquals(6d, ((Number)result).doubleValue(), 0d);

    //test one row range
    cell.setFormula("=SUM(1:1)");
    result = cell.getResult();
    assertEquals(6d, ((Number)result).doubleValue(), 0d);
   
    //test two dimension range
    ((SheetImpl)sheet1).setCellValue(1,3,new Integer(100)); //D2
    assertCellEquals(sheet1.getCell(1, 3), 1, 3, new Integer(100));

    ((SheetImpl)sheet1).setCellValue(2,3,new Integer(50)); //D3
    assertCellEquals(sheet1.getCell(2, 3), 2, 3, new Integer(50));
   
    cell.setFormula("=SUM(B1:D3)");
    result = cell.getResult();
    assertEquals(156d, ((Number)result).doubleValue(), 0d);

    ((SheetImpl)sheet1).setCellValue(1, 10,""); //K2
    cell.setFormula("=SUM(B1:D3)-K2");
    result = cell.getResult();
    assertEquals(156d, ((Number)result).doubleValue(), 0d);
   
   
    //test range3d
    Sheet sheet2 = ((BookImpl)_book).addSheet("sheet2", 256, 64*1024);
   
    ((SheetImpl)sheet2).setCellValue(0,1,new Integer(10)); //B1
    assertCellEquals(sheet2.getCell(0, 1), 0, 1, new Integer(10));

    ((SheetImpl)sheet2).setCellValue(0,2,new Integer(20)); //C1
    assertCellEquals(sheet2.getCell(0, 2), 0, 2, new Integer(20));
   
    ((SheetImpl)sheet2).setCellValue(0,3,new Integer(30)); //D1
    assertCellEquals(sheet2.getCell(0, 3), 0, 3, new Integer(30));

    cell.setFormula("=SUM(sheet1:sheet2!B1:D1)");
    result = cell.getResult();
    assertEquals(66d, ((Number)result).doubleValue(), 0d);
   
    //test cascaded formula (a formula refer to a cell with formula)
    ((SheetImpl)sheet2).setCellValue(0, 0, new Integer(1)); //A1
    ((SheetImpl)sheet2).setCellValue(1, 0, new Integer(2)); //A2
    ((SheetImpl)sheet2).setCellValue(2, 0, new FormulaImpl("=SUM(A1,A2)")); //A3
/*    ((SheetImpl)sheet2).setCellValue(3, 0, new FormulaImpl("=SUM(A2,A3)")); //A4
    ((SheetImpl)sheet2).setCellValue(4, 0, new FormulaImpl("=SUM(A3,A4)")); //A5
    ((SheetImpl)sheet2).setCellValue(5, 0, new FormulaImpl("=SUM(A4,A5)")); //A6
    ((SheetImpl)sheet2).setCellValue(6, 0, new FormulaImpl("=SUM(A5,A6)")); //A7
    ((SheetImpl)sheet2).setCellValue(7, 0, new FormulaImpl("=SUM(A6,A7)")); //A8
    ((SheetImpl)sheet2).setCellValue(8, 0, new FormulaImpl("=SUM(A7,A8)")); //A9
    ((SheetImpl)sheet2).setCellValue(9, 0, new FormulaImpl("=SUM(A8,A9)")); //A10
    ((SheetImpl)sheet2).setCellValue(10, 0, new FormulaImpl("=SUM(A9,A10)")); //A11
*/
    ((SheetImpl)sheet2).setCellValue(3, 0, null); //A4
    ((SheetImpl)sheet2).setCellValue(4, 0, null); //A5
    ((SheetImpl)sheet2).setCellValue(5, 0, null); //A6
    ((SheetImpl)sheet2).setCellValue(6, 0, null); //A7
    ((SheetImpl)sheet2).setCellValue(7, 0, null); //A8
    ((SheetImpl)sheet2).setCellValue(8, 0, null); //A9
    ((SheetImpl)sheet2).setCellValue(9, 0, null); //A10
    ((SheetImpl)sheet2).setCellValue(10, 0, null); //A11
   
    //test Range.copy()
    new RangeSimple(sheet2, null, 0, 2, 0, 2).copy(new RangeSimple(sheet2, null, 0, 3, 0, 10)); //A3 -> A4:A11
/*    CellImpl cella3 = (CellImpl)sheet2.getCell(2,0);
    cella3.copy(sheet2.getCell(3,0)); //A4
    cella3.copy(sheet2.getCell(4,0)); //A5
    cella3.copy(sheet2.getCell(5,0)); //A6
    cella3.copy(sheet2.getCell(6,0)); //A7
    cella3.copy(sheet2.getCell(7,0)); //A8
    cella3.copy(sheet2.getCell(8,0)); //A9
    cella3.copy(sheet2.getCell(9,0)); //A10
    cella3.copy(sheet2.getCell(10,0)); //A11
*/   

    ((SheetImpl)sheet2).setCellValue(0, 1, new FormulaImpl("=SUM(A1,A2)")); //B1
    new RangeSimple(sheet2, null, 1, 0, 1, 0).copy(new RangeSimple(sheet2, null, 1, 1, 1, 10)); //B1 -> B2:B11
/*    ((SheetImpl)sheet2).setCellValue(1, 1, new FormulaImpl("=SUM(A2,A3)")); //B2
    ((SheetImpl)sheet2).setCellValue(2, 1, new FormulaImpl("=SUM(A3,A4)")); //B3
    ((SheetImpl)sheet2).setCellValue(3, 1, new FormulaImpl("=SUM(A4,A5)")); //B4
    ((SheetImpl)sheet2).setCellValue(4, 1, new FormulaImpl("=SUM(A5,A6)")); //B5
    ((SheetImpl)sheet2).setCellValue(5, 1, new FormulaImpl("=SUM(A6,A7)")); //B6
    ((SheetImpl)sheet2).setCellValue(6, 1, new FormulaImpl("=SUM(A7,A8)")); //B7
    ((SheetImpl)sheet2).setCellValue(7, 1, new FormulaImpl("=SUM(A8,A9)")); //B8
    ((SheetImpl)sheet2).setCellValue(8, 1, new FormulaImpl("=SUM(A9,A10)")); //B9
    ((SheetImpl)sheet2).setCellValue(9, 1, new FormulaImpl("=SUM(A10,A11)")); //B10
    ((SheetImpl)sheet2).setCellValue(10, 1, new FormulaImpl("=SUM(A11,A12)")); //B11
*/   
    //A1 B1 ~ A11 B11
    result = sheet2.getCell(0, 0).getResult(); //A1
    assertEquals(1d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(0, 1).getResult(); //B1
    assertEquals(3d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(1, 0).getResult(); //A2
    assertEquals(2d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(1, 1).getResult(); //B2
    assertEquals(5d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(2, 0).getResult(); //A3
    assertEquals(3d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(2, 1).getResult(); //B3
    assertEquals(8d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(3, 0).getResult(); //A4
    assertEquals(5d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(3, 1).getResult(); //B4
    assertEquals(13d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(4, 0).getResult(); //A5
    assertEquals(8d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(4, 1).getResult(); //B5
    assertEquals(21d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(5, 0).getResult(); //A6
    assertEquals(13d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(5, 1).getResult(); //B6
    assertEquals(34d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(6, 0).getResult(); //A7
    assertEquals(21d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(6, 1).getResult(); //B7
    assertEquals(55d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(7, 0).getResult(); //A8
    assertEquals(34d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(7, 1).getResult(); //B8
    assertEquals(89d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(8, 0).getResult(); //A9
    assertEquals(55d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(8, 1).getResult(); //B9
    assertEquals(144d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(9, 0).getResult(); //A10
    assertEquals(89d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(9, 1).getResult(); //B10
    assertEquals(233d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(10, 0).getResult(); //A11
    assertEquals(144d, ((Number)result).doubleValue(), 0d);
    result = sheet2.getCell(10, 1).getResult(); //B11
    assertEquals(144d, ((Number)result).doubleValue(), 0d);

    //A1 ~ A11
    result = sheet2.getCell(0, 0).getResult(); //A1
    assertEquals(1d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(1, 0).getResult(); //A2
    assertEquals(2d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(2, 0).getResult(); //A3
    assertEquals(3d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(3, 0).getResult(); //A4
    assertEquals(5d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(4, 0).getResult(); //A5
    assertEquals(8d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(5, 0).getResult(); //A6
    assertEquals(13d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(6, 0).getResult(); //A7
    assertEquals(21d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(7, 0).getResult(); //A8
    assertEquals(34d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(8, 0).getResult(); //A9
    assertEquals(55d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(9, 0).getResult(); //A10
    assertEquals(89d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(10, 0).getResult(); //A11
    assertEquals(144d, ((Number)result).doubleValue(), 0d);

    //B1 ~ B11
    result = sheet2.getCell(0, 1).getResult(); //B1
    assertEquals(3d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(1, 1).getResult(); //B2
    assertEquals(5d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(2, 1).getResult(); //B3
    assertEquals(8d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(3, 1).getResult(); //B4
    assertEquals(13d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(4, 1).getResult(); //B5
    assertEquals(21d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(5, 1).getResult(); //B6
    assertEquals(34d, ((Number)result).doubleValue(), 0d);
   
    result = sheet2.getCell(6, 1).getResult(); //B7
    assertEquals(55d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(7, 1).getResult(); //B8
    assertEquals(89d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(8, 1).getResult(); //B9
    assertEquals(144d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(9, 1).getResult(); //B10
    assertEquals(233d, ((Number)result).doubleValue(), 0d);

    result = sheet2.getCell(10, 1).getResult(); //B11
    assertEquals(144d, ((Number)result).doubleValue(), 0d);
   
    //test Range.cut()
    new RangeSimple(sheet2, null, 1, 0, 1, 0).cut(new RangeSimple(sheet2, null, 2, 1, 2, 1)); //B1 -> C2
    result = sheet2.getCell(1, 2).getResult(); //C2 == B1
    assertEquals(3d, ((Number)result).doubleValue(), 0d);
    assertNotNull(((SheetImpl)sheet2).getMatrix().getRef(sheet2, null, 2,1,2,1));
    assertNull(sheet2.getCell(0, 1)); //B1 -> no cell
   
   
    //test dependent graph
    sheet2.getCell(0, 0).setValue(new Integer(5));
   
    //test logic functions
    cell.setFormula("=TRUE()");
    result = cell.getResult();
    assertEquals(Boolean.TRUE, result);
   
    cell.setFormula("=FALSE()");
    result = cell.getResult();
    assertEquals(Boolean.FALSE, result);
   
    cell.setFormula("=NOT(0=0)");
    result = cell.getResult();
    assertEquals(Boolean.FALSE, result);

    cell.setFormula("=IF(TRUE, 1, -1)");
    result = cell.getResult();
    assertEquals(1d, ((Number)result).doubleValue(), 0);

    cell.setFormula("=IF(FALSE, 1, -1)");
    result = cell.getResult();
    assertEquals(-1d, ((Number)result).doubleValue(), 0);
   
    cell.setFormula("=AND(TRUE, TRUE, FALSE)");
    result = cell.getResult();
    assertEquals(Boolean.FALSE, result);
   
    cell.setFormula("=AND(TRUE, TRUE, TRUE)");
    result = cell.getResult();
    assertEquals(Boolean.TRUE, result);

    cell.setFormula("=OR(FALSE, TRUE, FALSE)");
    result = cell.getResult();
    assertEquals(Boolean.TRUE, result);
   
    cell.setFormula("=OR(FALSE, FALSE, FALSE)");
    result = cell.getResult();
    assertEquals(Boolean.FALSE, result);
   
  }
View Full Code Here

TOP

Related Classes of org.zkoss.zss.model.Cell

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.