📄 hssfcell.java
字号:
booleanValue = (( BoolErrRecord ) cval).getBooleanValue(); break; case CELL_TYPE_ERROR : errorValue = (( BoolErrRecord ) cval).getErrorValue(); break; } ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex()); setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf)); } /** * private constructor to prevent blank construction */ private HSSFCell() { } /** * used internally -- given a cell value record, figure out its type */ private int determineType(CellValueRecordInterface cval) { Record record = ( Record ) cval; int sid = record.getSid(); int retval = 0; switch (sid) { case NumberRecord.sid : retval = HSSFCell.CELL_TYPE_NUMERIC; break; case BlankRecord.sid : retval = HSSFCell.CELL_TYPE_BLANK; break; case LabelSSTRecord.sid : retval = HSSFCell.CELL_TYPE_STRING; break; case FormulaRecordAggregate.sid : retval = HSSFCell.CELL_TYPE_FORMULA; break; case BoolErrRecord.sid : BoolErrRecord boolErrRecord = ( BoolErrRecord ) record; retval = (boolErrRecord.isBoolean()) ? HSSFCell.CELL_TYPE_BOOLEAN : HSSFCell.CELL_TYPE_ERROR; break; } return retval; } /** * set the cell's number within the row (0 based) * @param num short the cell number */ public void setCellNum(short num) { cellNum = num; record.setColumn(num); } /** * get the cell's number within the row * @return short reperesenting the column number (logical!) */ public short getCellNum() { return cellNum; } /** * set the cells type (numeric, formula or string) -- DONT USE FORMULAS IN THIS RELEASE * WE'LL THROW YOU A RUNTIME EXCEPTION IF YOU DO * @see #CELL_TYPE_NUMERIC * @see #CELL_TYPE_STRING * @see #CELL_TYPE_FORMULA * @see #CELL_TYPE_BLANK * @see #CELL_TYPE_BOOLEAN * @see #CELL_TYPE_ERROR */ public void setCellType(int cellType) { setCellType(cellType, true); } /** * sets the cell type. The setValue flag indicates whether to bother about * trying to preserve the current value in the new record if one is created. * <p> * The @see #setCellValue method will call this method with false in setValue * since it will overwrite the cell value later * */ private void setCellType(int cellType, boolean setValue) { // if (cellType == CELL_TYPE_FORMULA) // { // throw new RuntimeException( // "Formulas have not been implemented in this release"); // } if (cellType > CELL_TYPE_ERROR) { throw new RuntimeException("I have no idea what type that is!"); } switch (cellType) { case CELL_TYPE_FORMULA : FormulaRecordAggregate frec = null; if (cellType != this.cellType) { frec = new FormulaRecordAggregate(new FormulaRecord(),null); } else { frec = ( FormulaRecordAggregate ) record; } frec.setColumn(getCellNum()); if (setValue) { frec.getFormulaRecord().setValue(getNumericCellValue()); } frec.setXFIndex(( short ) cellStyle.getIndex()); frec.setRow(row); record = frec; break; case CELL_TYPE_NUMERIC : NumberRecord nrec = null; if (cellType != this.cellType) { nrec = new NumberRecord(); } else { nrec = ( NumberRecord ) record; } nrec.setColumn(getCellNum()); if (setValue) { nrec.setValue(getNumericCellValue()); } nrec.setXFIndex(( short ) cellStyle.getIndex()); nrec.setRow(row); record = nrec; break; case CELL_TYPE_STRING : LabelSSTRecord lrec = null; if (cellType != this.cellType) { lrec = new LabelSSTRecord(); } else { lrec = ( LabelSSTRecord ) record; } lrec.setColumn(getCellNum()); lrec.setRow(row); lrec.setXFIndex(( short ) cellStyle.getIndex()); if (setValue) { if ((getStringCellValue() != null) && (!getStringCellValue().equals(""))) { int sst = 0; if (encoding == ENCODING_COMPRESSED_UNICODE) { sst = book.addSSTString(getStringCellValue()); } if (encoding == ENCODING_UTF_16) { sst = book.addSSTString(getStringCellValue(), true); } lrec.setSSTIndex(sst); } } record = lrec; break; case CELL_TYPE_BLANK : BlankRecord brec = null; if (cellType != this.cellType) { brec = new BlankRecord(); } else { brec = ( BlankRecord ) record; } brec.setColumn(getCellNum()); // During construction the cellStyle may be null for a Blank cell. if (cellStyle != null) { brec.setXFIndex(( short ) cellStyle.getIndex()); } else { brec.setXFIndex(( short ) 0); } brec.setRow(row); record = brec; break; case CELL_TYPE_BOOLEAN : BoolErrRecord boolRec = null; if (cellType != this.cellType) { boolRec = new BoolErrRecord(); } else { boolRec = ( BoolErrRecord ) record; } boolRec.setColumn(getCellNum()); if (setValue) { boolRec.setValue(getBooleanCellValue()); } boolRec.setXFIndex(( short ) cellStyle.getIndex()); boolRec.setRow(row); record = boolRec; break; case CELL_TYPE_ERROR : BoolErrRecord errRec = null; if (cellType != this.cellType) { errRec = new BoolErrRecord(); } else { errRec = ( BoolErrRecord ) record; } errRec.setColumn(getCellNum()); if (setValue) { errRec.setValue(getErrorCellValue()); } errRec.setXFIndex(( short ) cellStyle.getIndex()); errRec.setRow(row); record = errRec; break; } if (cellType != this.cellType) { int loc = sheet.getLoc(); sheet.replaceValueRecord(record); sheet.setLoc(loc); } this.cellType = cellType; } /** * get the cells type (numeric, formula or string) * @see #CELL_TYPE_STRING * @see #CELL_TYPE_NUMERIC * @see #CELL_TYPE_FORMULA * @see #CELL_TYPE_BOOLEAN * @see #CELL_TYPE_ERROR */ public int getCellType() { return cellType; } /** * set a numeric value for the cell * * @param value the numeric 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. */ public void setCellValue(double value) { if ((cellType != CELL_TYPE_NUMERIC) && (cellType != CELL_TYPE_FORMULA)) { setCellType(CELL_TYPE_NUMERIC, false); } (( NumberRecord ) record).setValue(value); cellValue = value; } /** * 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. */ public void setCellValue(Date value) { setCellValue(HSSFDateUtil.getExcelDate(value)); } /** * 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 othertypes we * will change the cell to a numeric cell and set its value. */ public void setCellValue(Calendar value) { setCellValue(value.getTime()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -