/** * Creates new Cell - Should only be called by HSSFRow. This creates a cell * from scratch. * * @param book - Workbook record of the workbook containing this cell * @param sheet - Sheet record of the sheet containing this cell * @param row - the row of this cell * @param col - the column for this cell * @param type - Type of cell * @see org.apache.poi.hssf.usermodel.HSSFRow#createCell(int,CellType) */ protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col, CellType type) { checkBounds(col); _cellType = CellType._NONE; // Force 'setCellType' to create a first Record _stringValue = null; _book = book; _sheet = sheet; short xfindex = sheet.getSheet().getXFIndexForColAt(col); setCellType(type,false,row,col,xfindex); }
/** * Creates new Cell - Should only be called by HSSFRow. This creates a cell * from scratch. * <p> * When the cell is initially created it is set to {@link CellType#BLANK}. Cell types * can be changed/overwritten by calling setCellValue with the appropriate * type as a parameter although conversions from one type to another may be * prohibited. * * @param book - Workbook record of the workbook containing this cell * @param sheet - Sheet record of the sheet containing this cell * @param row - the row of this cell * @param col - the column for this cell * * @see org.apache.poi.hssf.usermodel.HSSFRow#createCell(int) */ protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col) { checkBounds(col); _stringValue = null; _book = book; _sheet = sheet; // Relying on the fact that by default the cellType is set to 0 which // is different to {@link CellType#BLANK} hence the following method call correctly // creates a new blank cell. short xfindex = sheet.getSheet().getXFIndexForColAt(col); setCellType(CellType.BLANK, false, row, col,xfindex); }
/** * Set the cells type (numeric, formula or string). * If the cell currently contains a value, the value will * be converted to match the new type, if possible. */ @Override public void setCellType(CellType cellType) { notifyFormulaChanging(); if(isPartOfArrayFormulaGroup()){ notifyArrayFormulaChanging(); } int row=_record.getRow(); short col=_record.getColumn(); short styleIndex=_record.getXFIndex(); setCellType(cellType, true, row, col, styleIndex); }
void setCellArrayFormula(CellRangeAddress range) { int row = _record.getRow(); short col = _record.getColumn(); short styleIndex = _record.getXFIndex(); setCellType(CellType.FORMULA, false, row, col, styleIndex); // Billet for formula in rec Ptg[] ptgsForCell = {new ExpPtg(range.getFirstRow(), range.getFirstColumn())}; FormulaRecordAggregate agg = (FormulaRecordAggregate) _record; agg.setParsedExpression(ptgsForCell); }
/** * set a boolean value for the cell * * @param value the boolean value to set this cell to. For formulas we'll set the * precalculated value, for booleans we'll set its value. For other types we * will change the cell to a boolean cell and set its value. */ @SuppressWarnings("fallthrough") public void setCellValue(boolean value) { int row=_record.getRow(); short col=_record.getColumn(); short styleIndex=_record.getXFIndex(); switch (_cellType) { default: setCellType(CellType.BOOLEAN, false, row, col, styleIndex); // fall through case BOOLEAN: (( BoolErrRecord ) _record).setValue(value); break; case FORMULA: ((FormulaRecordAggregate)_record).setCachedBooleanResult(value); break; } }
setCellType(CellType.NUMERIC, false, row, col, styleIndex);
/** * set a error value for the cell * * @param error the error value to set this cell to. For formulas we'll set the * precalculated value , for errors we'll set * its value. For other types we will change the cell to an error * cell and set its value. */ @SuppressWarnings("fallthrough") public void setCellErrorValue(FormulaError error) { int row=_record.getRow(); short col=_record.getColumn(); short styleIndex=_record.getXFIndex(); switch (_cellType) { default: setCellType(CellType.ERROR, false, row, col, styleIndex); // fall through case ERROR: (( BoolErrRecord ) _record).setValue(error); break; case FORMULA: ((FormulaRecordAggregate)_record).setCachedErrorResult(error.getCode()); break; } }
public void setCellFormula(String formula) { if(isPartOfArrayFormulaGroup()){ notifyArrayFormulaChanging(); } int row=_record.getRow(); short col=_record.getColumn(); short styleIndex=_record.getXFIndex(); if (formula==null) { notifyFormulaChanging(); setCellType(CellType.BLANK, false, row, col, styleIndex); return; } int sheetIndex = _book.getSheetIndex(_sheet); Ptg[] ptgs = HSSFFormulaParser.parse(formula, _book, FormulaType.CELL, sheetIndex); setCellType(CellType.FORMULA, false, row, col, styleIndex); FormulaRecordAggregate agg = (FormulaRecordAggregate) _record; FormulaRecord frec = agg.getFormulaRecord(); frec.setOptions((short) 2); frec.setValue(0); //only set to default if there is no extended format index already set if (agg.getXFIndex() == (short)0) { agg.setXFIndex((short) 0x0f); } agg.setParsedExpression(ptgs); } /**
setCellType(CellType.BLANK, false, row, col, styleIndex); return; setCellType(CellType.STRING, false, row, col, styleIndex);
newCell.setCellType(oldCell.getCellType());
HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short) 0); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); SimpleDateFormat datetemp = new SimpleDateFormat("yyyy-MM-dd"); Date cellValue = datetemp.parse("1994-01-01 12:00"); cell.setCellValue(cellValue); //binds the style you need to the cell. HSSFCellStyle dateCellStyle = wb.createCellStyle(); short df = wb.createDataFormat().getFormat("dd-mmm"); dateCellStyle.setDataFormat(df); cell.setCellStyle(dateCellStyle);
setCellType(CellType.BLANK, false, row, col, styleIndex); return; } else {
HSSFCell cellE1 = row1.getCell((short) 4); cellE1.setCellType(HSSFCell.CELL_TYPE_NUMERIC); Double e1Val = cellE1.getNumericCellValue(); BigDecimal bd = new BigDecimal(e1Val.toString()); long lonVal = bd.longValue(); System.out.println(lonVal);
/** * Convenient method to set a String as text content in a cell. * @param cell the cell in which the text must be put * @param text the text to put in the cell */ protected void setText(HSSFCell cell, String text) { cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(text); }
HSSFRow row = sheet.getRow(rowIdx); HSSFCell cell = row.getCell(colIdx); //if its a string.. otherwise choose the correct cell type cell.setCellType(HSSFCell..CELL_TYPE_STRING); cell.setCellValue(new HSSFRichTextString(data));
@Override public SpreadsheetExporter addRow(String... values) { HSSFRow dataRow = dataSheet.createRow(rowCount++); for (int i = 0; i < values.length; i++) { HSSFCell cell = dataRow.createCell(i); cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue(values[i]); } return this; }
private void addCell(HSSFRow row, int i, String text, HSSFCellStyle style) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style); cell.setCellType(HSSFCell.CELL_TYPE_STRING); if (text == null) { text = ""; } cell.setCellValue(new HSSFRichTextString(text)); }
void setCellArrayFormula(CellRangeAddress range) { int row = _record.getRow(); short col = _record.getColumn(); short styleIndex = _record.getXFIndex(); setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex); // Billet for formula in rec Ptg[] ptgsForCell = {new ExpPtg(range.getFirstRow(), range.getFirstColumn())}; FormulaRecordAggregate agg = (FormulaRecordAggregate) _record; agg.setParsedExpression(ptgsForCell); }
void setCellArrayFormula(CellRangeAddress range) { int row = _record.getRow(); short col = _record.getColumn(); short styleIndex = _record.getXFIndex(); setCellType(CellType.FORMULA, false, row, col, styleIndex); // Billet for formula in rec Ptg[] ptgsForCell = {new ExpPtg(range.getFirstRow(), range.getFirstColumn())}; FormulaRecordAggregate agg = (FormulaRecordAggregate) _record; agg.setParsedExpression(ptgsForCell); }
void setCellArrayFormula(CellRangeAddress range) { int row = _record.getRow(); short col = _record.getColumn(); short styleIndex = _record.getXFIndex(); setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex); // Billet for formula in rec Ptg[] ptgsForCell = {new ExpPtg(range.getFirstRow(), range.getFirstColumn())}; FormulaRecordAggregate agg = (FormulaRecordAggregate) _record; agg.setParsedExpression(ptgsForCell); }