Package org.zkoss.poi.ss.util

Examples of org.zkoss.poi.ss.util.CellRangeAddress


  }
 
  @Test
  public void testgetRepeatingRowsAndColumns() {
    //$A:$C, $1:$4
    CellRangeAddress addr1 = _workbook.getRepeatingRowsAndColumns(0);
    assertEquals(0, addr1.getFirstColumn());
    assertEquals(2, addr1.getLastColumn());
    assertEquals(0, addr1.getFirstRow());
    assertEquals(3, addr1.getLastRow());
   
    //N/A, $6:$7
    CellRangeAddress addr2 = _workbook.getRepeatingRowsAndColumns(1);
    assertEquals(-1, addr2.getFirstColumn());
    assertEquals(-1, addr2.getLastColumn());
    assertEquals(5, addr2.getFirstRow());
    assertEquals(6, addr2.getLastRow());
   
    //$D:$E, $6:$7
    CellRangeAddress addr3 = _workbook.getRepeatingRowsAndColumns(2);
    assertEquals(3, addr3.getFirstColumn());
    assertEquals(4, addr3.getLastColumn());
    assertEquals(-1, addr3.getFirstRow());
    assertEquals(-1, addr3.getLastRow());
   
    //N/A,N/A
    CellRangeAddress addr4 = _workbook.getRepeatingRowsAndColumns(3);
    assertEquals(-1, addr4.getFirstColumn());
    assertEquals(-1, addr4.getLastColumn());
    assertEquals(-1, addr4.getFirstRow());
    assertEquals(-1, addr4.getLastRow());
  }
View Full Code Here


  }
 
  @Test
  public void testgetRepeatingRowsAndColumns() {
    //$A:$C, $1:$4
    CellRangeAddress addr1 = _workbook.getRepeatingRowsAndColumns(0);
    assertEquals(0, addr1.getFirstColumn());
    assertEquals(2, addr1.getLastColumn());
    assertEquals(0, addr1.getFirstRow());
    assertEquals(3, addr1.getLastRow());
   
    //N/A, $6:$7
    CellRangeAddress addr2 = _workbook.getRepeatingRowsAndColumns(1);
    assertEquals(-1, addr2.getFirstColumn());
    assertEquals(-1, addr2.getLastColumn());
    assertEquals(5, addr2.getFirstRow());
    assertEquals(6, addr2.getLastRow());
   
    //$D:$E, $6:$7
    CellRangeAddress addr3 = _workbook.getRepeatingRowsAndColumns(2);
    assertEquals(3, addr3.getFirstColumn());
    assertEquals(4, addr3.getLastColumn());
    assertEquals(-1, addr3.getFirstRow());
    assertEquals(-1, addr3.getLastRow());
   
    //N/A,N/A
    CellRangeAddress addr4 = _workbook.getRepeatingRowsAndColumns(3);
    assertEquals(-1, addr4.getFirstColumn());
    assertEquals(-1, addr4.getLastColumn());
    assertEquals(-1, addr4.getFirstRow());
    assertEquals(-1, addr4.getLastRow());
  }
View Full Code Here

    String name = fsaw_filename.getValue();

    Name namevar = book.createName();
    namevar.setNameName(name);
    namevar.setSheetIndex(sheetindex);
    CellRangeAddress cra = new CellRangeAddress(top, bottom, left, right);
    namevar.setRefersToFormula(cra.formatAsString());
   
    Window rangeAddWin = (Window) Path.getComponent("//p1/rangeAddWin");
    rangeAddWin.detach();
  }
View Full Code Here

      Name range;
      Rect rect;
      if (st != null) {
        String rangeName = st.getLabel();
        range = book.getName(rangeName);
        CellRangeAddress cra = CellRangeAddress.valueOf(range.getRefersToFormula());
        rect = new Rect(cra.getFirstColumn(), cra.getFirstRow(),
            cra.getLastColumn(), cra.getLastRow());
        spreadsheet.setSelection(rect);
      }

      Window rangeChooseWin = (Window) Path
          .getComponent("//p1/rangeChooseWin");
View Full Code Here

      Name range;
      Rect rect;
      if (st != null) {
        String rangeName = st.getLabel();
        range = book.getName(rangeName);
        CellRangeAddress cra = CellRangeAddress.valueOf(range.getRefersToFormula());
        rect = new Rect(cra.getFirstColumn(), cra.getFirstRow(),
            cra.getLastColumn(), cra.getLastRow());
        spreadsheet.setHighlight(rect);
      }

    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

        if (everTab.booleanValue()) { //shift + Tab
          col = col - 1;
          if (col < 0) {
            col = 0;
          } else {
            final CellRangeAddress merged = sheet != null ? ((SheetCtrl)sheet).getMerged(row, col) : null;
            if (merged != null) {
              col = merged.getFirstColumn();
            }
          }
        } else { //Tab
          final CellRangeAddress merged = sheet != null ? ((SheetCtrl)sheet).getMerged(row, col) : null;
          col = merged == null ? col + 1 : merged.getLastColumn() + 1;
          if (bookCtrl.getMaxcolumns() <= col) {
            col = bookCtrl.getMaxcolumns() - 1;
            final CellRangeAddress newmerged = sheet != null ? ((SheetCtrl)sheet).getMerged(row, col) : null;
            if (newmerged != null) {
              col = newmerged.getFirstColumn();
            }
          }
        }
        bookCtrl.focusTo(row, col, true);
      } else if (everFocusCell) { //click on the same cell, shall enter edit mode, something like press F2
View Full Code Here

    Worksheet sheet = event.getSheet();
    lastRow = event.getRow();
    lastCol = event.getColumn();
    Label lbpos = (Label)getFellow("lbpos");
    Textbox tbxval = (Textbox)getFellow("tbxval");
    CellRangeAddress addr = new CellRangeAddress(lastRow, lastRow, lastCol, lastCol);
    Cell cell = Utils.getCell(sheet, lastRow, lastCol);
    lbpos.setValue(addr.formatAsString());
    tbxval.setValue(cell == null ? "" : Utils.getEditText(cell));
  }
View Full Code Here

    testToFormulaString(cellC1, "SUM(B8:B10)");
   
    //6 merge area
    assertEquals(6, sheet1.getNumMergedRegions());
    for (int j = 0; j < 6; ++j) {
      CellRangeAddress rng = sheet1.getMergedRegion(j);
      switch(j) {
      case 0:
        assertEquals("E6:F8", rng.formatAsString());
        break;
      case 1:
        assertEquals("E10:F12", rng.formatAsString());
        break;
      case 2:
        assertEquals("G5:H5", rng.formatAsString());
        break;
      case 3:
        assertEquals("E3:F4", rng.formatAsString());
        break;
      case 4:
        assertEquals("I3:J7", rng.formatAsString());
        break;
      case 5:
        assertEquals("E14:F15", rng.formatAsString());
        break;
      }
    }
 
    //remove rows 4 ~ 6
    BookHelper.deleteRows(sheet1, 3, 3); //remove rows 4 ~ 6
    _evaluator.notifySetFormula(cellA1);
    _evaluator.notifySetFormula(cellB1);
    _evaluator.notifySetFormula(cellC1);
   
    //B4: 5, B5:7, C5: empty, B6: 9, B7: 11, row 8 ~ row 10 empty
    Row row4 = sheet1.getRow(3);
    row5 = sheet1.getRow(4);
    row6 = sheet1.getRow(5);
    row7 = sheet1.getRow(6);
   
    row8 = sheet1.getRow(7);
    row9 = sheet1.getRow(8);
    row10 = sheet1.getRow(9);
   
    assertNull(row5.getCell(2)); //C5 not exist
    assertNull(row8.getCell(1));
    assertNull(row9.getCell(1));
    assertNull(row10);
   
    assertEquals(5, row4.getCell(1).getNumericCellValue(), 0.0000000000000001);
    assertEquals(7, row5.getCell(1).getNumericCellValue(), 0.0000000000000001);
    assertEquals(9, row6.getCell(1).getNumericCellValue(), 0.0000000000000001);
    assertEquals(11, row7.getCell(1).getNumericCellValue(), 0.0000000000000001);
   
    //C1: =SUM(B5:B7)
    valueC1 = _evaluator.evaluate(cellC1);
    assertEquals(27, valueC1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC1.getCellType());
    testToFormulaString(cellC1, "SUM(B5:B7)");
   
    //B1: =SUM(B4:B7)
    valueB1 = _evaluator.evaluate(cellB1);
    assertEquals(32, valueB1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueB1.getCellType());
    testToFormulaString(cellB1, "SUM(B4:B7)");
   
    //A1: =SUM(#REF!)
    valueA1 = _evaluator.evaluate(cellA1);
    assertEquals(Cell.CELL_TYPE_ERROR, valueA1.getCellType());
    testToFormulaString(cellA1, "SUM(#REF!)");
   
    //5 merge area
    assertEquals(5, sheet1.getNumMergedRegions()); //G5:H5 unmerged
    for (int j = 0; j < 5; ++j) {
      CellRangeAddress rng = sheet1.getMergedRegion(j);
      switch(j) {
      case 0:
        assertEquals("E4:F5", rng.formatAsString()); //E6:F8 -> E4:F5
        break;
      case 1:
        assertEquals("E7:F9", rng.formatAsString()); //E10:F12 -> E7:F9
        break;
      case 2:
        assertEquals("E3:F3", rng.formatAsString()); //E3:F4 -> E3:F3
        break;
      case 3:
        assertEquals("I3:J4", rng.formatAsString()); //I3:J7 -> I3:J4
        break;
      case 4:
        assertEquals("E11:F12", rng.formatAsString()); //E14:F15 -> E11:F12
      }
    }
  }
View Full Code Here

    testToFormulaString(cellC1, "SUM(B8:B10)");
   
    //6 merge area
    assertEquals(6, sheet1.getNumMergedRegions());
    for (int j = 0; j < 6; ++j) {
      CellRangeAddress rng = sheet1.getMergedRegion(j);
      switch(j) {
      case 0:
        assertEquals("E6:F8", rng.formatAsString());
        break;
      case 1:
        assertEquals("E10:F12", rng.formatAsString());
        break;
      case 2:
        assertEquals("G5:H5", rng.formatAsString());
        break;
      case 3:
        assertEquals("E3:F4", rng.formatAsString());
        break;
      case 4:
        assertEquals("I3:J7", rng.formatAsString());
        break;
      case 5:
        assertEquals("E14:F15", rng.formatAsString());
        break;
      }
    }
 
    //remove A4:J6
    BookHelper.deleteRange(sheet1, 3, 0, 5, 9, false);
    _evaluator.notifySetFormula(cellA1);
    _evaluator.notifySetFormula(cellB1);
    _evaluator.notifySetFormula(cellC1);
   
    //B4: 5, B5:7, C5: empty, B6: 9, B7: 11, row 8 ~ row 10 empty
    Row row4 = sheet1.getRow(3);
    row5 = sheet1.getRow(4);
    row6 = sheet1.getRow(5);
    row7 = sheet1.getRow(6);
   
    row8 = sheet1.getRow(7);
    row9 = sheet1.getRow(8);
    row10 = sheet1.getRow(9);
   
    assertNull(row5.getCell(2)); //C5 not exist
    assertNull(row8.getCell(1));
    assertNull(row9.getCell(1));
    assertNull(row10.getCell(1));
   
    assertEquals(5, row4.getCell(1).getNumericCellValue(), 0.0000000000000001);
    assertEquals(7, row5.getCell(1).getNumericCellValue(), 0.0000000000000001);
    assertEquals(9, row6.getCell(1).getNumericCellValue(), 0.0000000000000001);
    assertEquals(11, row7.getCell(1).getNumericCellValue(), 0.0000000000000001);
   
    //C1: =SUM(B5:B7)
    valueC1 = _evaluator.evaluate(cellC1);
    assertEquals(27, valueC1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueC1.getCellType());
    testToFormulaString(cellC1, "SUM(B5:B7)");
   
    //B1: =SUM(B4:B7)
    valueB1 = _evaluator.evaluate(cellB1);
    assertEquals(32, valueB1.getNumberValue(), 0.0000000000000001);
    assertEquals(Cell.CELL_TYPE_NUMERIC, valueB1.getCellType());
    testToFormulaString(cellB1, "SUM(B4:B7)");
   
    //A1: =SUM(#REF!)
    valueA1 = _evaluator.evaluate(cellA1);
    assertEquals(Cell.CELL_TYPE_ERROR, valueA1.getCellType());
    testToFormulaString(cellA1, "SUM(#REF!)");
   
    //5 merge area
    assertEquals(5, sheet1.getNumMergedRegions()); //G5:H5 unmerged
    for (int j = 0; j < 5; ++j) {
      CellRangeAddress rng = sheet1.getMergedRegion(j);
      switch(j) {
      case 0:
        assertEquals("E4:F5", rng.formatAsString()); //E6:F8 -> E4:F5
        break;
      case 1:
        assertEquals("E7:F9", rng.formatAsString()); //E10:F12 -> E7:F9
        break;
      case 2:
        assertEquals("E3:F3", rng.formatAsString()); //E3:F4 -> E3:F3
        break;
      case 3:
        assertEquals("I3:J4", rng.formatAsString()); //I3:J7 -> I3:J4
        break;
      case 4:
        assertEquals("E11:F12", rng.formatAsString()); //E14:F15 -> E11:F12
      }
    }
  }
View Full Code Here

        final int dstbRow = bRow + nRow;
        final int dstlCol = lCol + nCol;
        final int dstrCol = rCol + nCol;
       
        for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
          CellRangeAddress merged = sheet.getMergedRegion(i);
         
          int firstRow = merged.getFirstRow();
          int lastRow = merged.getLastRow();
          int firstCol = merged.getFirstColumn();
          int lastCol = merged.getLastColumn();
          if (firstCol >= lCol && lastCol <= rCol && firstRow >= tRow && lastRow <= bRow) { //source total cover
                CellRangeAddress[] rngs = new CellRangeAddress[2]; //[0] old, [1] new
             merged.setFirstColumn(firstCol  + nCol);
             merged.setLastColumn(lastCol + nCol);
             merged.setFirstRow(firstRow + nRow);
             merged.setLastRow(lastRow + nRow);
          rngs[1] = merged;
             rngs[0] = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
          shiftedRegions.add(rngs);
             sheet.removeMergedRegion(i);
             i = i - 1; //back up now since we removed one
            continue;
          }
         
          if (firstCol >= dstlCol && lastCol <= dstrCol && firstRow >= dsttRow && lastRow <= dstbRow) { //destination total cover
                CellRangeAddress[] rngs = new CellRangeAddress[2]; //[0] old, [1] null
             rngs[0] = merged;
          shiftedRegions.add(rngs);
             sheet.removeMergedRegion(i);
             i = i - 1; //back up now since we removed one
            continue;
          }
         
          //destination partial cover (not allowed)
          if (firstRow <= dstbRow && lastRow >= dsttRow && firstCol <= dstrCol && lastCol >= dstlCol) {
            throw new RuntimeException("Cannot change part of a merged cell.");
          }
        }
     
        //read so it doesn't get shifted again
        Iterator<CellRangeAddress[]> iterator = shiftedRegions.iterator();
        while (iterator.hasNext()) {
            CellRangeAddress region = iterator.next()[1];
            if (region != null) {
              sheet.addMergedRegion(region);
            }
        }
       
View Full Code Here

TOP

Related Classes of org.zkoss.poi.ss.util.CellRangeAddress

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.