Package org.apache.poi.ss.usermodel

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


            }
        }

        @Override
        public void timeProperty(PropertyName name, Context context) {
            Cell cell = context.nextCell();
            cell.setCellStyle(info.timeDataStyle);
            Calendar value = (Calendar) context.getValue(name);
            if (value != null) {
                cell.setCellValue(value);
            }
        }
View Full Code Here


            }
        }

        @Override
        public void datetimeProperty(PropertyName name, Context context) {
            Cell cell = context.nextCell();
            cell.setCellStyle(info.datetimeDataStyle);
            Calendar value = (Calendar) context.getValue(name);
            if (value != null) {
                cell.setCellValue(value);
            }
        }
View Full Code Here

            }
        }

        @Override
        public void anyProperty(PropertyName name, Context context) {
            Cell cell = context.nextCell();
            Object value = context.getValue(name);
            if (value != null) {
                cell.setCellValue(value.toString());
            }
        }
View Full Code Here

            this.info = info;
            this.column = 0;
        }

        public Cell nextCell() {
            Cell cell = row.createCell(column++);
            cell.setCellStyle(info.dataStyle);
            return cell;
        }
View Full Code Here

   * This method is used for creating cells in an excel file.
   * Alignment of the cell is automatically adjusted by calling the setAlignment() method for horizontal alignment,
   * and the setVerticalAlignment() method for vertical alignment of the cell.
   */
  private void createCell(Workbook wb, Row row, int column, String cellValue, short halign, short valign) {
    Cell cell = row.createCell(column);
    cell.setCellValue(cellValue);
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cell.setCellStyle(cellStyle);
  }
View Full Code Here

      Sheet sheet = workbook.getSheetAt(testListPosition);
      Row row = sheet.createRow(assigNumber);
     
      int lastColumn = sheet.getRow(0).getPhysicalNumberOfCells();     
      for (int cn=0; cn<lastColumn; cn++) {
        Cell cell = row.getCell(cn, Row.RETURN_BLANK_AS_NULL);
        if (cell == null) {
          cell = row.createCell(cn);
          cell.setCellType(Cell.CELL_TYPE_STRING);
          cell.setCellValue(argument[cn]);
        }
      }
     
      FileOutputStream fileOutput = new FileOutputStream(file);
      workbook.write(fileOutput);
View Full Code Here

    final Column[] columns = getColumns();
    for (int i = 0; i < columns.length; i++) {
      Object value = values[i];
      if (value != null) {
        int columnNumber = columns[i].getColumnNumber();
        Cell cell = row.createCell(columnNumber);

        // use a lazyref and the isFetched method to only create style
        // if nescesary
        LazyRef<CellStyle> cellStyle = new LazyRef<CellStyle>() {
          @Override
          protected CellStyle fetch() {
            return getUpdateCallback().createCellStyle();
          }
        };

        if (value instanceof Number) {
          cell.setCellValue(((Number) value).doubleValue());
        } else if (value instanceof Boolean) {
          cell.setCellValue((Boolean) value);
        } else if (value instanceof Date) {
          cell.setCellValue((Date) value);
        } else {
          cell.setCellValue(value.toString());
        }

        Style style = styles[i];
        if (style != null && !Style.NO_STYLE.equals(style)) {
          LazyRef<Font> font = new LazyRef<Font>() {
            @Override
            protected Font fetch() {
              return getUpdateCallback().createFont();
            }

          };
          if (style.isBold()) {
            font.get().setBoldweight(Font.BOLDWEIGHT_BOLD);
          }
          if (style.isItalic()) {
            font.get().setItalic(true);
          }
          if (style.isUnderline()) {
            font.get().setUnderline(Font.U_SINGLE);
          }
          if (style.getFontSize() != null) {
            Integer fontSize = style.getFontSize();
            SizeUnit sizeUnit = style.getFontSizeUnit();
            if (sizeUnit == SizeUnit.PERCENT) {
              fontSize = convertFontPercentageToPt(fontSize);
            }
            font.get().setFontHeightInPoints(fontSize.shortValue());
          }
          Color foregroundColor = style.getForegroundColor();
          if (foregroundColor != null) {
            short index = getUpdateCallback().getColorIndex(
                foregroundColor);
            font.get().setColor(index);
          }
          if (font.isFetched()) {
            cellStyle.get().setFont(font.get());
          }
          if (style.getAlignment() != null) {
            cellStyle.get().setAlignment(
                getAlignment(style.getAlignment()));
          }

          final Color backgroundColor = style.getBackgroundColor();
          if (backgroundColor != null) {
            cellStyle.get().setFillPattern(
                CellStyle.SOLID_FOREGROUND);
            cellStyle.get().setFillForegroundColor(
                getUpdateCallback().getColorIndex(
                    backgroundColor));
          }
        }

        if (value instanceof Date) {
          if (cellStyle.isFetched()) {
            cellStyle.get().setDataFormat(
                getUpdateCallback().getDateCellFormat());
          } else {
            cellStyle = new LazyRef<CellStyle>() {
              @Override
              protected CellStyle fetch() {
                return getUpdateCallback().getDateCellStyle();
              }
            };
            // trigger the fetch
            cellStyle.get();
          }
        }

        if (cellStyle.isFetched()) {
          cell.setCellStyle(cellStyle.get());
        }
      }
    }
  }
View Full Code Here

        final int offset = getColumnOffset(row);

        // build columns based on cell values.
        for (int j = offset; j < rowLength; j++) {
            Cell cell = row.getCell(j);
            String columnName = ExcelUtils.getCellValue(wb, cell);
            if (columnName == null || "".equals(columnName)) {
                columnName = "[Column " + (j + 1) + "]";
            }
            Column column = new MutableColumn(columnName, ColumnType.VARCHAR, table, j, true);
View Full Code Here

            }

            final FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();

            // calculates the formula and puts it's value back into the cell
            final Cell evaluatedCell = evaluator.evaluateInCell(cell);

            return getCellValue(wb, evaluatedCell);
        } catch (RuntimeException e) {
            logger.warn("Exception occurred while evaluating formula at position ({},{}): {}", new Object[] { cell.getRowIndex(),
                    cell.getColumnIndex(), e.getMessage() });
View Full Code Here

        final String[] values = new String[size];
        final Style[] styles = new Style[size];
        if (row != null) {
            for (int i = 0; i < size; i++) {
                final int columnNumber = header.getSelectItem(i).getColumn().getColumnNumber();
                final Cell cell = row.getCell(columnNumber);
                final String value = ExcelUtils.getCellValue(workbook, cell);
                final Style style = ExcelUtils.getCellStyle(workbook, cell);
                values[i] = value;
                styles[i] = style;
            }
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.