Package org.zkoss.poi.ss.usermodel

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


            hidden = true;
            break;
          }
        }
        if (hidden) { //to be hidden
          final Row rowobj = _sheet.getRow(r);
          if (rowobj == null || !rowobj.getZeroHeight()) { //a non-hidden row
            new RangeImpl(r, col1, _sheet, _sheet).getRows().setHidden(true);
          }
        } else { //to be shown
          final Row rowobj = _sheet.getRow(r);
          if (rowobj != null && rowobj.getZeroHeight()) { //a hidden row
            final int left = rowobj.getFirstCellNum();
            final int right = rowobj.getLastCellNum() - 1;
            final RangeImpl rng = (RangeImpl) new RangeImpl(r, left, r, right, _sheet, _sheet);
            all.addAll(rng.getRefs());
            rng.getRows().setHidden(false); //unhide
          }
        }
View Full Code Here


      final Set<Ref> all = new HashSet<Ref>();
      for (int r = row; r <= row2; ++r) {
        final Cell cell = BookHelper.getCell(_sheet, r, col);
        final String val = BookHelper.isBlankCell(cell) ? "=" : BookHelper.getCellText(cell); //"=" means blank!
        if (cr1 != null && !cr1.isEmpty() && !cr1.contains(val)) { //to be hidden
          final Row rowobj = _sheet.getRow(r);
          if (rowobj == null || !rowobj.getZeroHeight()) { //a non-hidden row
            new RangeImpl(r, col, _sheet, _sheet).getRows().setHidden(true);
          }
        } else { //candidate to be shown (other FieldColumn might still hide this row!
          final Row rowobj = _sheet.getRow(r);
          if (rowobj != null && rowobj.getZeroHeight() && canUnhide(af, fc, r, col1)) { //a hidden row and no other hidden filtering
            final int left = rowobj.getFirstCellNum();
            final int right = rowobj.getLastCellNum() - 1;
            final RangeImpl rng = (RangeImpl) new RangeImpl(r, left, r, right, _sheet, _sheet);
            all.addAll(rng.getRefs());
            rng.getRows().setHidden(false); //unhide
          }
        }
View Full Code Here

  public boolean isCustomHeight() {
    Ref ref = _refs != null && !_refs.isEmpty() ? _refs.iterator().next() : null;
    if (ref != null) {
      final int tRow = ref.getTopRow();
      final RefSheet refSheet = ref.getOwnerSheet();
      final Row row = getRow(tRow, refSheet);
      if (row != null) {
        return row.isCustomHeight();
      }
    }
    return false;
  }
View Full Code Here

   * @param rowIndex the row index of the cell
   * @param colIndex the column index of the cell
   * @return or create if not exist the {@link Cell} per the given sheet, row index, and column index.
   */
  public static Cell getOrCreateCell(Worksheet sheet,int rowIndex, int colIndex){
    Row row = getOrCreateRow(sheet, rowIndex);
    Cell cell = row.getCell(colIndex);
    if (cell == null) {
      cell = row.createCell(colIndex);
    }
    return cell;
  }
View Full Code Here

    }
    return cell;
  }
 
  public static Row getOrCreateRow(Worksheet sheet, int rowIndex) {
    Row row = sheet.getRow(rowIndex);
    if (row == null) {
      row = sheet.createRow(rowIndex);
    }
    return row;
  }
View Full Code Here

   * @param rowIndex the row index of the cell
   * @param colIndex the column index of the cell
   * @return the {@link Cell} per the given sheet, row index, and column index; return null if cell not exists.
   */
  public static Cell getCell(Worksheet sheet,int rowIndex, int colIndex){
    final Row row = sheet.getRow(rowIndex);
    return row != null ? row.getCell(colIndex) : null;
  }
View Full Code Here

        if (wholeRow) {
          for(int[] pair : removePairs) {
            final int start = Math.max(0, pair[0]);
            final int end = Math.min(SpreadsheetVersion.EXCEL2007.getLastRowIndex() + 1, pair[1]);
            for(int j=start; j < end; ++j) {
              Row row = getRow(j);
              if (row != null) {
                removeRow(row);
              }
            }
          }
        } else { //clear cells between lCol and rCol
          for(int[] pair : removePairs) {
            final int start = Math.max(0, pair[0]);
            final int end = pair[1];
            for(int j=start; j < end; ++j) {
              Row row = getRow(j);
              if (row != null) {
                removeCells(row, lCol, rCol);
              }
            }
          }
        }
       
        //really update the row's cells
        for (Entry<Integer, TreeMap<Integer, XSSFCell>> entry : rowCells.entrySet()) {
          final int rownum = entry.getKey().intValue();
          final TreeMap<Integer, XSSFCell> cells = entry.getValue();
          XSSFRow row = getRow(rownum);
          if (row == null) {
            row = createRow(rownum);
          } else {
            removeCells(row, lCol, rCol);
          }
          for(Entry<Integer, XSSFCell> cellentry : cells.entrySet()) {
            final int colnum = cellentry.getKey().intValue();
            final XSSFCell srcCell = cellentry.getValue();
            BookHelper.assignCell(srcCell, row.createCell(colnum));
          }
        }
       
        //handle inserted rows
        if (srcRow != null) {
          final int row2 = Math.min(startRow + n - 1, SpreadsheetVersion.EXCEL2007.getLastRowIndex());
          for ( int rownum = startRow; rownum <= row2; ++rownum) {
            XSSFRow row = getRow(rownum);
            if (row == null) {
              row = createRow(rownum);
            }
            row.setHeight(srcHeight); //height
//            if (srcStyle != null) {
//              row.setRowStyle((HSSFCellStyle)copyFromStyleExceptBorder(srcStyle));//style
//            }
            if (srcCells != null) {
              for (Entry<Integer, Cell> cellEntry : srcCells.entrySet()) {
                final Cell srcCell = cellEntry.getValue();
                final CellStyle cellStyle = srcCell.getCellStyle();
                final int c = cellEntry.getKey().intValue();
                Cell cell = row.getCell(c);
                if (cell == null) {
                  cell = row.createCell(c);
                }
                cell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), cellStyle));
              }
            }
          }
View Full Code Here

      final int tgtrCol = Math.min(maxcol, rCol + nCol);
      for(int[] pair : removePairs) {
        final int start = Math.max(0, pair[0]);
        final int end = pair[1];
        for(int j=start; j < end; ++j) {
          Row row = getRow(j);
          if (row != null) {
            removeCells(row, tgtlCol, tgtrCol);
          }
        }
      }

        //really update the row's cells
        for (Entry<Integer, TreeMap<Integer, XSSFCell>> entry : rowCells.entrySet()) {
          final int rownum = entry.getKey().intValue();
          final TreeMap<Integer, XSSFCell> cells = entry.getValue();
          XSSFRow row = getRow(rownum);
          if (row == null) {
            row = createRow(rownum);
          } else {
            removeCells(row, tgtlCol, tgtrCol);
          }
          for(Entry<Integer, XSSFCell> cellentry : cells.entrySet()) {
            final int colnum = cellentry.getKey().intValue() + nCol;
            if (colnum < 0) { //out of bound
              continue;
            }
            if (colnum > maxcol) {
              break;
            }
            final XSSFCell srcCell = cellentry.getValue();
            BookHelper.assignCell(srcCell, row.createCell(colnum));
          }
        }
     
        // Move comments from the source column to the
        //  destination column. Note that comments can
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

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.