/** * Set the cells type (numeric, formula or string) * * @throws IllegalArgumentException if the specified cell type is invalid */ @Override public void setCellType(CellType cellType) { setCellType(cellType, null); }
protected void setCellType(Cell cell, CellType cellType) { if (cell instanceof XSSFCell) { EvaluationWorkbook evaluationWorkbook = getEvaluationWorkbook(); BaseXSSFEvaluationWorkbook xewb = BaseXSSFEvaluationWorkbook.class.isAssignableFrom(evaluationWorkbook.getClass()) ? (BaseXSSFEvaluationWorkbook) evaluationWorkbook : null; ((XSSFCell) cell).setCellType(cellType, xewb); } else { // could be an SXSSFCell cell.setCellType(cellType); } } }
@Override public CellRange<XSSFCell> removeArrayFormula(Cell cell) { if (cell.getSheet() != this) { throw new IllegalArgumentException("Specified cell does not belong to this sheet."); } for (CellRangeAddress range : arrayFormulas) { if (range.isInRange(cell)) { arrayFormulas.remove(range); CellRange<XSSFCell> cr = getCellRange(range); for (XSSFCell c : cr) { c.setCellType(CellType.BLANK); } return cr; } } String ref = ((XSSFCell)cell).getCTCell().getR(); throw new IllegalArgumentException("Cell " + ref + " is not part of an array formula."); }
/** * Use this to create new cells within the row and return it. * * @param columnIndex - the column number this cell represents * @param type - the cell's data type * @return XSSFCell a high level representation of the created cell. * @throws IllegalArgumentException if the specified cell type is invalid, columnIndex < 0 * or greater than 16384, the maximum number of columns supported by the SpreadsheetML format (.xlsx) */ @Override public XSSFCell createCell(int columnIndex, CellType type) { // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory final Integer colI = Integer.valueOf(columnIndex); // NOSONAR CTCell ctCell; XSSFCell prev = _cells.get(colI); if(prev != null){ ctCell = prev.getCTCell(); ctCell.set(CTCell.Factory.newInstance()); } else { ctCell = _row.addNewC(); } XSSFCell xcell = new XSSFCell(this, ctCell); xcell.setCellNum(columnIndex); if (type != CellType.BLANK) { xcell.setCellType(type); } _cells.put(colI, xcell); return xcell; } /**
/** * Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as * a date. * * @param value the date value to set this cell to. For formulas we'll set the * precalculated value, for numerics we'll set its value. For other types we * will change the cell to a numeric cell and set its value. */ @Override public void setCellValue(Date value) { if(value == null) { setCellType(CellType.BLANK); return; } boolean date1904 = getSheet().getWorkbook().isDate1904(); setCellValue(DateUtil.getExcelDate(value, date1904)); }
/** * Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as * a date. * <p> * This will set the cell value based on the Calendar's timezone. As Excel * does not support timezones this means that both 20:00+03:00 and * 20:00-03:00 will be reported as the same value (20:00) even that there * are 6 hours difference between the two times. This difference can be * preserved by using <code>setCellValue(value.getTime())</code> which will * automatically shift the times to the default timezone. * </p> * * @param value the date value to set this cell to. For formulas we'll set the * precalculated value, for numerics we'll set its value. For othertypes we * will change the cell to a numeric cell and set its value. */ @Override public void setCellValue(Calendar value) { if(value == null) { setCellType(CellType.BLANK); return; } boolean date1904 = getSheet().getWorkbook().isDate1904(); setCellValue( DateUtil.getExcelDate(value, date1904 )); }
public void setCellValue(RichTextString str) { if(str == null || str.getString() == null){ setCellType(CellType.BLANK); return;
XSSFCell cell = row.getCell(cellRef.getCol()); if (cell != null) { cell.setCellType(CellType.BLANK); cell.setCellStyle(null);
/** * Set the cells type (numeric, formula or string) * * @throws IllegalArgumentException if the specified cell type is invalid */ @Override public void setCellType(CellType cellType) { setCellType(cellType, null); }
**XSSFCell cell = row.createCell(1); if (cell == Cell.CELL_TYPE_BLANK){ cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue("Apple"); }
for(i=0;i<numrow;i++){ String[] newArray=new String[numcol]; for (j=0;j<numcol;j++ ){ if(xlsh.getRow(i).getCell(j)!=null){ XSSFCell cellval=xlsh.getRow(i).getCell(j); cellval.setCellType(Cell.CELL_TYPE_STRING); newArray[j] = cellval.toString(); } else{ newArray[j] = ""; } } xldata[i][0] = newArray; } return xldata;
protected void setCellType(Cell cell, CellType cellType) { if (cell instanceof XSSFCell) { EvaluationWorkbook evaluationWorkbook = getEvaluationWorkbook(); BaseXSSFEvaluationWorkbook xewb = BaseXSSFEvaluationWorkbook.class.isAssignableFrom(evaluationWorkbook.getClass()) ? (BaseXSSFEvaluationWorkbook) evaluationWorkbook : null; ((XSSFCell) cell).setCellType(cellType, xewb); } else { // could be an SXSSFCell cell.setCellType(cellType); } } }
@Override public CellRange<XSSFCell> removeArrayFormula(Cell cell) { if (cell.getSheet() != this) { throw new IllegalArgumentException("Specified cell does not belong to this sheet."); } for (CellRangeAddress range : arrayFormulas) { if (range.isInRange(cell)) { arrayFormulas.remove(range); CellRange<XSSFCell> cr = getCellRange(range); for (XSSFCell c : cr) { c.setCellType(CellType.BLANK); } return cr; } } String ref = ((XSSFCell)cell).getCTCell().getR(); throw new IllegalArgumentException("Cell " + ref + " is not part of an array formula."); }
public CellRange<XSSFCell> removeArrayFormula(Cell cell) { if (cell.getSheet() != this) { throw new IllegalArgumentException("Specified cell does not belong to this sheet."); } for (CellRangeAddress range : arrayFormulas) { if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { arrayFormulas.remove(range); CellRange<XSSFCell> cr = getCellRange(range); for (XSSFCell c : cr) { c.setCellType(Cell.CELL_TYPE_BLANK); } return cr; } } String ref = ((XSSFCell)cell).getCTCell().getR(); throw new IllegalArgumentException("Cell " + ref + " is not part of an array formula."); }
@Override public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) { XSSFWorkbook wb = cell.getSheet().getWorkbook(); cell.setCellStyle(cellStyle); cell.setCellValue(wb.getCreationHelper().createRichTextString(value.toString())); cell.setCellType(XSSFCell.CELL_TYPE_STRING); } }
/** * Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as * a date. * * @param value the date value to set this cell to. For formulas we'll set the * precalculated value, for numerics we'll set its value. For other types we * will change the cell to a numeric cell and set its value. */ @Override public void setCellValue(Date value) { if(value == null) { setCellType(CellType.BLANK); return; } boolean date1904 = getSheet().getWorkbook().isDate1904(); setCellValue(DateUtil.getExcelDate(value, date1904)); }
@Override public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) { XSSFWorkbook wb = cell.getSheet().getWorkbook(); cell.setCellStyle(cellStyle); cell.setCellValue(wb.getCreationHelper().createRichTextString(getString(tableModel, value, row, col))); cell.setCellType(XSSFCell.CELL_TYPE_STRING); }
@Override public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) { String string = getString((LocalTime) value); XSSFWorkbook wb = cell.getSheet().getWorkbook(); cell.setCellStyle(cellStyle); cell.setCellType(XSSFCell.CELL_TYPE_STRING); if (string != null) { cell.setCellValue(wb.getCreationHelper().createRichTextString(string)); } }
private void createExcelHeader(XSSFWorkbook workbook, XSSFSheet tableSheet) throws Exception { XSSFFont f = workbook.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); XSSFDataFormat df = workbook.createDataFormat(); XSSFCellStyle cs = workbook.createCellStyle(); cs.setFont(f); cs.setDataFormat(df.getFormat("text")); cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); cs.setWrapText(true); XSSFCreationHelper createHelper = workbook.getCreationHelper(); XSSFRow rh = tableSheet.createRow(0); for (int i = 0; i < table.getColumnCount(); i++) { XSSFCell c1 = rh.createCell(i); c1.setCellStyle(cs); c1.setCellValue(createHelper.createRichTextString(table.getColumnName(i))); c1.setCellType(XSSFCell.CELL_TYPE_STRING); } }
protected void createExcelHeader(XSSFWorkbook workbook, XSSFSheet tableSheet) throws Exception { XSSFFont f = workbook.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); XSSFDataFormat df = workbook.createDataFormat(); XSSFCellStyle cs = workbook.createCellStyle(); cs.setFont(f); cs.setDataFormat(df.getFormat("text")); cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); cs.setWrapText(true); XSSFCreationHelper createHelper = workbook.getCreationHelper(); XSSFRow rh = tableSheet.createRow(0); for (int i = 0; i < table.getColumnCount(); i++) { XSSFCell c1 = rh.createCell(i); c1.setCellStyle(cs); c1.setCellValue(createHelper.createRichTextString(table.getColumnName(i))); c1.setCellType(XSSFCell.CELL_TYPE_STRING); } }