Package org.apache.poi.ss.usermodel

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


  }
 
  public static void copySheet(Sheet sheet, Sheet newSheet){
    int maxCol = 0;
    for(int row = 0; row <= sheet.getLastRowNum(); row++){
      Row oldRow = sheet.getRow(row);
      if(oldRow == null) continue;
      Row newRow = newSheet.getRow(row);
      if(newRow == null) newRow = newSheet.createRow(row);
      if(oldRow.getHeight() >= 0) newRow.setHeight(oldRow.getHeight());
      maxCol = (maxCol >= oldRow.getLastCellNum() - 1? maxCol : oldRow.getLastCellNum() -1 );
      for(int col = 0; col < oldRow.getLastCellNum(); col ++){
        Cell oldCell = oldRow.getCell(col);
        if(oldCell == null) continue;
        Cell newCell = newRow.getCell(col);
        if(newCell == null) newCell = newRow.createCell(col);       
        copyCell(oldCell, newCell, true);
      }
    }
    for(int col=0; col<=maxCol; col++){
      if(sheet.getColumnWidth(col) >=0)
View Full Code Here


  }
 
  public static void copyBlock(Sheet sheet, int startRow, int startCol, int endRow, int endCol,
      boolean copyStyle, int rowOffset, int colOffset, List<CellRangeAddress> mergedRegions){
    for(int row=startRow; row<=endRow; row++){         
      Row oldRow = sheet.getRow(row);
      if(oldRow == null) continue;
      Row newRow = sheet.getRow(row + rowOffset);
      if(newRow == null) newRow = sheet.createRow(row + rowOffset);     
      if(oldRow.getHeight() >= 0) newRow.setHeight(oldRow.getHeight());
      if(logger.isDebugEnabled()){
        logger.debug("copy row {} to {}", row, row+rowOffset);
        logger.debug("Set row height :{}", newRow.getHeightInPoints());
      }
      for(int col=startCol; col<=endCol; col++){
        Cell oldCell = oldRow.getCell(col);
        if(oldCell == null) continue;
        Cell newCell = newRow.getCell(col + colOffset);
        if(newCell == null) newCell = newRow.createCell(col + colOffset);       
        copyCell(oldCell, newCell, copyStyle, rowOffset,colOffset);
      }
    }
    for(int col=startCol; col<=endCol; col++){
      if(sheet.getColumnWidth(col) >=0)
View Full Code Here

    //Simple Block will only care about cells in these Block
    Sheet sheet = wb.getSheetAt(sheetNo);
    FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
   
    for(ExcelCell cellDefinition: blockDefinition.getCells()){
      Row row = sheet.getRow(cellDefinition.getRow());
      Cell cell = row == null ? null : row.getCell(cellDefinition.getCol());     
      try{
        Object value = getCellValue(cell,evaluator);
        value = checkValue(sheetNo, ExcelUtil.getCellIndex(cellDefinition.getRow(),cellDefinition.getCol()),
            value, cellDefinition,
            getPropertyType(stack.peek(), cellDefinition));
View Full Code Here

    if(blockDefinition.getLoopClass() == null){
      Map<String, Object> result = new HashMap<String, Object>();
     
      for(ExcelCell cellDefinition: blockDefinition.getCells()){   
        int rowOffSet = cellDefinition.getRow() - blockDefinition.getStartRow();
        Row row = sheet.getRow(startRow + rowOffSet);
        Cell cell = row == null ? null: row.getCell(cellDefinition.getCol());     
        try{
          Object value = getCellValue(cell,evaluator);
          value = checkValue(sheetNo, ExcelUtil.getCellIndex(startRow + rowOffSet ,cellDefinition.getCol()),
              value, cellDefinition,
              getPropertyType(result, cellDefinition));
          logger.debug("{}[Checked]:{}", ExcelUtil.getCellIndex(startRow + rowOffSet ,cellDefinition.getCol()), value);         
          result.put(cellDefinition.getDataName(), value);
        }catch(ExcelManipulateException e){
          if(readStatus.getStatus() == ReadStatus.STATUS_SUCCESS)
            readStatus.setStatus(ReadStatus.STATUS_DATA_COLLECTION_ERROR);
          readStatus.addException(e);
        }     
      }
      return result;
    }else{
      Object result = blockDefinition.getLoopClass().newInstance();   
      OgnlStack ognlStack = new OgnlStack(result);
      for(ExcelCell cellDefinition: blockDefinition.getCells()){   
        int rowOffSet = cellDefinition.getRow() - blockDefinition.getStartRow();
        Row row = sheet.getRow(startRow + rowOffSet);
        Cell cell = row == null ? null: row.getCell(cellDefinition.getCol());     
        try{
          Object value = getCellValue(cell,evaluator);
          value = checkValue(sheetNo, ExcelUtil.getCellIndex(startRow + rowOffSet ,cellDefinition.getCol()),
              value, cellDefinition,
              getPropertyType(result, cellDefinition));
View Full Code Here

        LoopBreakCondition condition){
    //no break condition defined   
    if(sheet.getLastRowNum() < row)
      return true;
    if(condition != null){
      Row hrow = sheet.getRow(row + condition.getRowOffset());
      if(hrow == null) return false;
      Cell cell = hrow.getCell(col + condition.getColOffset());     
      if(cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_STRING) return false;
      if(condition.getFlagString().equals(cell.getRichStringCellValue().getString()))
        return true;     
    }
    return false;
View Full Code Here

        styleMap.containsKey(style.getCellIndex())) return;
    int[] position = ExcelUtil.getCellPosition(style.getCellIndex());
    int rows = style.getEndRow() - style.getStartRow();
    int cols = style.getEndCol() - style.getStartCol();
    for(int i= position[0]; i<= position[0] + rows; i++){
      Row row = styleSheet.getRow(i);
      if(row == null) return;
      for(int j= position[1]; j<= position[1] + cols; j++){
        Cell cell = row.getCell(j);
        if(cell == null) return;
        styleMap.put(ExcelUtil.getCellIndex(i, j), cell.getCellStyle());
        if(logger.isDebugEnabled()){
          logger.debug("Condition Style [{}]", ExcelUtil.getCellIndex(i, j));
        }
View Full Code Here

  }
 
  private void setBlockStyle(Sheet sheet, int startRowIndex, int endRowIndex,
      int startColIndex, int endColIndex, String cellIndex, Map<String, CellStyle> styleMap){
    for(int rowIndex = startRowIndex; rowIndex <= endRowIndex; rowIndex++){     
      Row row = sheet.getRow(rowIndex);
      if(row == null) row = sheet.createRow(rowIndex);
      for(int c = startColIndex; c <= endColIndex; c ++){
        String cIdx = ExcelUtil.offsetCellIndex(cellIndex, rowIndex-startRowIndex, c - startColIndex);
        CellStyle style = styleMap.get(cIdx);
        if(style == null) continue;
        Cell cell = row.getCell(c);
        if(cell == null) cell = row.createCell(c)
        cell.setCellStyle(style);
      }
    }
  }
View Full Code Here

    }
  }
 
  private void setCellStyle(Sheet sheet, int rowIndex, int cellIndex, CellStyle style){
    if(style == null) return;
    Row row = sheet.getRow(rowIndex);
    if(row == null) row = sheet.createRow(rowIndex);
    Cell cell = row.getCell(cellIndex);
    if(cell == null) cell = row.createCell(cellIndex);     
    if(cell.getCellStyle() == null || (cell.getCellType() != Cell.CELL_TYPE_NUMERIC)
        || (!DateUtil.isCellDateFormatted(cell))
        || DateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString()))
      cell.setCellStyle(style);
    else{     
View Full Code Here

    }
  }
 
  private void setCellValue(Sheet sheet, int rowIndex, int cellIndex, String dataName, OgnlStack stack){
    if(dataName.equals("#")) return;
    Row row = sheet.getRow(rowIndex);
    if(row == null) row = sheet.createRow(rowIndex);
    Cell cell = row.getCell(cellIndex);
    if(cell == null) cell = row.createCell(cellIndex);   
    if(dataName.startsWith("=")){
      //formula
      cell.setCellFormula(dataName.substring(1));
    }else{
      //data
View Full Code Here

    Assert.assertEquals(0, sheet.getFirstRowNum());
    Assert.assertEquals(data.getRowCount() - 1, sheet.getLastRowNum());

    for (int r = 0; r < data.getRowCount(); r += 1)
    {
      Row row = sheet.getRow(r);
      for (int c = 0; c < data.getColumnCount(); c += 1)
      {
        Cell cell = row.getCell(c);

        Object valueAt = data.getValueAt(r, c);
        if (valueAt == null)
        {
          if (cell != null)
View Full Code Here

TOP

Related Classes of org.apache.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.