📄 hssfcell.java
字号:
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)
* @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());
}
/**
* set a string value for the cell. Please note that if you are using
* full 16 bit unicode you should call <code>setEncoding()</code> first.
*
* @param value value to set the cell to. For formulas we'll set the formula
* string, for String cells we'll set its value. For other types we will
* change the cell to a string cell and set its value.
* If value is null then we will change the cell to a Blank cell.
*/
public void setCellValue(String value)
{
if (value == null)
{
setCellType(CELL_TYPE_BLANK, false);
}
else
{
if ((cellType != CELL_TYPE_STRING ) && ( cellType != CELL_TYPE_FORMULA))
{
setCellType(CELL_TYPE_STRING, false);
}
int index = 0;
if (encoding == ENCODING_COMPRESSED_UNICODE)
{
index = book.addSSTString(value);
}
if (encoding == ENCODING_UTF_16)
{
index = book.addSSTString(value, true);
}
(( LabelSSTRecord ) record).setSSTIndex(index);
stringValue = value;
}
}
public void setCellFormula(String formula) {
//Workbook.currentBook=book;
if (formula==null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -