Package org.zkoss.zss.model

Examples of org.zkoss.zss.model.Sheet


  public void testRefARange2() {
    Book book = new ExcelImporter().imports(getClass().getResource("/namedRange.xls"));
    String[] names = book.getNameRangeNames();
    System.out.println("names="+Objects.toString(names));
    Sheet sheet = (Sheet) book.getSheets().get(0);

    {
      Cell cell = sheet.getCell(0,1); //B1
      assertEquals("10", cell.getText());
    }

    {
      Cell cell = sheet.getCell(1,1); //B2
      assertEquals("2", cell.getText());
    }
  }
View Full Code Here


      if (xrng instanceof RangeRef) {
        final RangeRef rng = (RangeRef) xrng;
        orgref.addPrecedent(rng.getRef());
      }
    }
    final Sheet orgSheet = orgref.getSheet();
    if (orgSheet != null) {
      for(final Iterator it = ranges.iterator(); it.hasNext(); ) {
        final Range xrng = (Range) it.next();
        if (xrng instanceof RangeRef) {
          final RangeRef rng = (RangeRef) xrng;
View Full Code Here

   */
  private void exportEachBook(Book book, WritableWorkbook workbook) {
    List blist = book.getSheets();
    int i = 0;
    for (final Iterator it = blist.iterator(); it.hasNext();) {
      Sheet sheet = (Sheet) it.next();
      WritableSheet s = workbook.createSheet(sheet.getName(), i);
      exportEachSheet(sheet, s);
      i++;
    }
  }
View Full Code Here

    mySetFormat(format, true);
  }
 
  /*package*/void mySetFormat(Format format, boolean notify) {
    _format = format;
    final Sheet sheet = getSheet();
    if (notify) {
      sheet.getBook().fireSSDataEvent(new SSDataEvent(
        new RangeSimple(sheet, null, getColumn(), getRow(), getColumn(), getRow()),
        SSDataEvent.CONTENTS_CHANGE, SSDataEvent.MOVE_NO));
    }
  }
View Full Code Here

    assertEquals(Boolean.FALSE, result);
   
  }
 
  public void testInfoFunctions() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    //ISERROR and ISERR
    Cell cellA1 = ((SheetImpl)sheet1).setCellEditText(0,0,"#N/A"); //A1
    assertEquals(SSError.NA, cellA1.getResult());
View Full Code Here

    ((SheetImpl)sheet1).setCellEditText(0,0,"#EX!");
    assertEquals(SSError.EX, cellA1.getResult());
*/  }
 
  public void testSumproduct() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));

    Cell cellA1 = ((SheetImpl)sheet1).setCellEditText(0,0,"1"); //A1
    Cell cellA2 = ((SheetImpl)sheet1).setCellEditText(1,0,"2"); //A2
    Cell cellA3 = ((SheetImpl)sheet1).setCellEditText(2,0,"3"); //A3
View Full Code Here

    ((SheetImpl)sheet1).setCellEditText(0,2,"=SUMPRODUCT({1,3;7,2}, {2,0;0,2})");//C1
    assertEquals(6d, ((Number)cellC1.getResult()).doubleValue(), 0d);
  }
  //test SSDataListener (B1+D1)
  public void testArithmeticUpdate() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 6, 6);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));

    final SimpleSSDataListener ssl = new SimpleSSDataListener();
    _book.addSSDataListener(ssl);
    assertEquals(0, ssl.getList().size());

    ssl.getList().clear();
    ((SheetImpl)sheet1).setCellValue(5,5, new FormulaImpl("=B1+D1")); //F6

    ssl.getList().clear();
    ((SheetImpl)sheet1).setCellValue(0,1,new Integer(1)); //B1
    assertCellEquals(sheet1.getCell(0, 1), 0, 1, new Integer(1));
    assertEquals(2, ssl.getList().size());

    ssl.getList().clear();
    ((SheetImpl)sheet1).setCellValue(0,3,new Integer(3)); //D1
    assertCellEquals(sheet1.getCell(0, 3), 0, 3, new Integer(3));
    assertEquals(2, ssl.getList().size());
   
    ssl.getList().clear();
    ((SheetImpl)sheet1).setCellValue(0,2,new Integer(2)); //C1
    assertCellEquals(sheet1.getCell(0, 2), 0, 2, new Integer(2));
    assertEquals(1, ssl.getList().size());

    ssl.getList().clear();
    ((SheetImpl)sheet1).getCell(0,1).setValue(5); //change B1 (1 -> 5) => F6.
System.out.println(Objects.toString(ssl.getList()));
    assertEquals(2, ssl.getList().size());
   
    for(final Iterator it = ssl.getList().iterator(); it.hasNext();) {
      final SSDataEvent evt = (SSDataEvent) it.next();
      final Range rng = evt.getRange();
      if (rng.getLeft() == 1 && rng.getTop() == 0) {
        assertEquals(5d, ((Number)sheet1.getCell(0,1).getResult()).doubleValue(), 0d);
      } else  if (rng.getLeft() == 5 && rng.getTop() == 5) {
        assertEquals(8d, ((Number)sheet1.getCell(5,5).getResult()).doubleValue(), 0d);
      } else {
        assertFalse("should not come here", false);
      }
    }
  }
View Full Code Here

      }
    }
  }

  public void testDouble15() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 6, 6);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    ((SheetImpl)sheet1).setCellValue(5,5, new FormulaImpl("=761.6+2732+20836.1+7262+48.1-10.3")); //F6
    final Cell cell = sheet1.getCell(5,5);
    final Object result = cell.getResult(); //F6
    assertEquals(31629.5d, ((Double)result).doubleValue(), 0d);
  }
View Full Code Here

    final Object result = cell.getResult(); //F6
    assertEquals(31629.5d, ((Double)result).doubleValue(), 0d);
  }
 
  public void testCell2() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 6, 6);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    ((SheetImpl)sheet1).setCellValue(5,5, new FormulaImpl("=SUM(A1:E6)")); //F6
    final Cell cell = sheet1.getCell(5,5);
   
    ((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));

    final Object result = cell.getResult(); //F6
    assertEquals(6d, ((Double)result).doubleValue(), 0d);
   
    //test RefCell and Function
    final SimpleSSDataListener ssl = new SimpleSSDataListener();
    _book.addSSDataListener(ssl);
    assertEquals(0, ssl.getList().size());

    ((SheetImpl)sheet1).getCell(0,1).setValue(5); //change B1 (1 -> 5) => F6.
System.out.println(Objects.toString(ssl.getList()));
    assertEquals(2, ssl.getList().size());

    for(final Iterator it = ssl.getList().iterator(); it.hasNext();) {
      final SSDataEvent evt = (SSDataEvent) it.next();
      final Range rng = evt.getRange();
      if (rng.getLeft() == 1 && rng.getTop() == 0) {
        assertEquals(5d, ((Number)sheet1.getCell(0,1).getResult()).doubleValue(), 0d);
      } else  if (rng.getLeft() == 5 && rng.getTop() == 5) {
        assertEquals(10d, ((Number)sheet1.getCell(5,5).getResult()).doubleValue(), 0d);
      } else {
        assertFalse("should not come here", false);
      }
    }
   
View Full Code Here

    ((SheetImpl)sheet1).getCell(0,1).setValue(5); //make cascade dependent change B1 (10 -> 5) => F6.
    assertEquals(10d, ((Number)sl.getValue()).doubleValue(), 0d);
  }
 
  public void testMerge() {
    Sheet sheet1 = ((BookImpl)_book).addSheet("sheet1", 256, 64*1024);
    assertEquals(sheet1, _book.lookupSheet("sheet1"));
   
    sheet1.mergeCells(0, 0, 1, 0); //A1:B1
    sheet1.mergeCells(0, 1, 2, 1); //A2:C2
   
    try {
      sheet1.mergeCells(1, 0, 2, 0);
      assertTrue("Shall throw ModelException for cross merging.", false);
    } catch(ModelException ex) {
      //ignore
    }
  }
View Full Code Here

TOP

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

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.