Package org.apache.poi.ss.usermodel

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


            for (Object rawR : sheet) {
                xhtml.startElement("tr");
                Row row = (Row) rawR;
                for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
                    xhtml.startElement("td");
                    Cell cell = ri.next();

                    int type = cell.getCellType();
                    if (type == Cell.CELL_TYPE_FORMULA) {
                        type = cell.getCachedFormulaResultType();
                    }
                    if (type == Cell.CELL_TYPE_STRING) {
                        xhtml.characters(cell.getRichStringCellValue()
                                .getString());
                    } else if (type == Cell.CELL_TYPE_NUMERIC) {
                      CellStyle style = cell.getCellStyle();
                      xhtml.characters(
                        formatter.formatRawCellContents(cell.getNumericCellValue(),
                              style.getDataFormat(),
                              style.getDataFormatString()));
                    } else {
                        XSSFCell xc = (XSSFCell) cell;
                        String rawValue = xc.getRawValue();
                        if (rawValue != null) {
                            xhtml.characters(rawValue);
                        }

                    }

                    // Output the comment in the same cell as the content
                    Comment comment = cell.getCellComment();
                    if (comment != null) {
                        xhtml.characters(comment.getString().getString());
                    }

                    xhtml.endElement("td");
View Full Code Here


      // Rows and cells
      for (Object rawR : sheet) {
        Row row = (Row)rawR;
        for(Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
          Cell cell = ri.next();
         
          // Is it a formula one?
          if(cell.getCellType() == Cell.CELL_TYPE_FORMULA && formulasNotResults) {
            text.append(cell.getCellFormula());
          } else if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
            text.append(cell.getRichStringCellValue().getString());
          } else {
            XSSFCell xc = (XSSFCell)cell;
            text.append(xc.getRawValue());
          }
         
          // Output the comment, if requested and exists
            Comment comment = cell.getCellComment();
          if(includeCellComments && comment != null) {
              // Replace any newlines with spaces, otherwise it
              //  breaks the output
              String commentText = comment.getString().getString().replace('\n', ' ');
              text.append(" Comment by "+comment.getAuthor()+": "+commentText);
View Full Code Here

    Comment cc5 = r5.getCell(2).getCellComment();
    cc5.setAuthor("Apache POI");
    cc5.setString(new XSSFRichTextString("Hello!"));
   
    Row r2s2 = sheet2.createRow(2);
    Cell c1r2s2 = r2s2.createCell(1);
    assertNull(c1r2s2.getCellComment());
   
    Comment cc2 = sheet2.createComment();
    cc2.setAuthor("Also POI");
    cc2.setString(new XSSFRichTextString("A new comment"));
    c1r2s2.setCellComment(cc2);
   
   
    // Save, and re-load the file
        workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
View Full Code Here

            for (Object rawR : sheet) {
                xhtml.startElement("tr");
                Row row = (Row) rawR;
                for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
                    xhtml.startElement("td");
                    Cell cell = ri.next();

                    int type = cell.getCellType();
                    if (type == Cell.CELL_TYPE_FORMULA) {
                        type = cell.getCachedFormulaResultType();
                    }
                    if (type == Cell.CELL_TYPE_STRING) {
                        xhtml.characters(cell.getRichStringCellValue()
                                .getString());
                    } else if (type == Cell.CELL_TYPE_NUMERIC) {
                      CellStyle style = cell.getCellStyle();
                      xhtml.characters(
                        formatter.formatRawCellContents(cell.getNumericCellValue(),
                              style.getDataFormat(),
                              style.getDataFormatString()));
                    } else {
                        XSSFCell xc = (XSSFCell) cell;
                        String rawValue = xc.getRawValue();
                        if (rawValue != null) {
                            xhtml.characters(rawValue);
                        }

                    }

                    // Output the comment in the same cell as the content
                    Comment comment = cell.getCellComment();
                    if (comment != null) {
                        xhtml.characters(comment.getString().getString());
                    }

                    xhtml.endElement("td");
View Full Code Here

        CellRangeAddress[] ranges = new CellRangeAddress[1];

        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();
        Cell cell = sheet.createRow(2).createCell(2);
        ranges[0] = new CellRangeAddress(2, 7, 2, 5);
        cell.setCellValue(FIRST_CELL_CONTENT);

        cell = sheet.createRow(7).createCell(5);
        cell.setCellValue(LAST_CELL_VALUE);

        cell = sheet.createRow(1).createCell(1);
        assertNull(parser.getRangeIfMerged(cell, ranges));

        cell = sheet.getRow(2).createCell(5);
        cell.setCellValue("wrong");

        CellRangeAddress rangeIfMerged = parser.getRangeIfMerged(cell, ranges);
        assertEquals(FIRST_CELL_CONTENT, sheet.getRow(rangeIfMerged.getFirstRow()).getCell(rangeIfMerged.getFirstColumn()).getStringCellValue());
    }
View Full Code Here

      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++){
View Full Code Here

      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++){
View Full Code Here

    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

      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

    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

TOP

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