| Constructor: |
protected HSSFCell(Workbook book,
Sheet sheet,
short row,
CellValueRecordInterface cval) {
cellNum = cval.getColumn();
record = cval;
this.row = row;
cellType = determineType(cval);
cellStyle = null;
stringValue = null;
this.book = book;
this.sheet = sheet;
switch (cellType)
{
case CELL_TYPE_NUMERIC :
cellValue = (( NumberRecord ) cval).getValue();
break;
case CELL_TYPE_STRING :
stringValue =
book
.getSSTString((( LabelSSTRecord ) cval).getSSTIndex());
break;
case CELL_TYPE_BLANK :
break;
case CELL_TYPE_FORMULA :
break;
}
ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex());
setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf));
}
Creates an HSSFCell from a CellValueRecordInterface. HSSFSheet uses this when
reading in cells from an existing sheet. Parameters:
book - - Workbook record of the workbook containing this cell
sheet - - Sheet record of the sheet containing this cell
cval - - the Cell Value Record we wish to represent
|
protected HSSFCell(Workbook book,
Sheet sheet,
short row,
short col,
int type) {
cellNum = col;
this.row = row;
cellType = type;
cellStyle = null;
cellValue = 0;
stringValue = null;
this.book = book;
this.sheet = sheet;
switch (type)
{
case CELL_TYPE_NUMERIC :
record = new NumberRecord();
(( NumberRecord ) record).setColumn(col);
(( NumberRecord ) record).setRow(row);
(( NumberRecord ) record).setValue(( short ) 0);
(( NumberRecord ) record).setXFIndex(( short ) 0);
break;
case CELL_TYPE_STRING :
record = new LabelSSTRecord();
(( LabelSSTRecord ) record).setColumn(col);
(( LabelSSTRecord ) record).setRow(row);
(( LabelSSTRecord ) record).setXFIndex(( short ) 0);
break;
case CELL_TYPE_BLANK :
record = new BlankRecord();
(( BlankRecord ) record).setColumn(col);
(( BlankRecord ) record).setRow(row);
(( BlankRecord ) record).setXFIndex(( short ) 0);
break;
}
ExtendedFormatRecord xf = book.getExFormatAt(0xf);
setCellStyle(new HSSFCellStyle(( short ) 0xf, xf));
}
Creates new Cell - Should only be called by HSSFRow. This creates a cell
from scratch. Parameters:
book - - Workbook record of the workbook containing this cell
sheet - - Sheet record of the sheet containing this cell
row - - the row of this cell
col - - the column for this cell
type - - CELL_TYPE_NUMERIC, CELL_TYPE_STRING, CELL_TYPE_FORMULA, CELL_TYPE_BLANK -
Type of cell
Also see:
- org.apache.cocoon.poi.hssf.usermodel.HSSFRow#createCell(short,int)
|
| Method from org.apache.cocoon.poi.hssf.usermodel.HSSFCell Detail: |
public short getCellNum() {
return cellNum;
}
get the cell's number within the row |
public HSSFCellStyle getCellStyle() {
return cellStyle;
}
get the style for the cell. This is a reference to a cell style contained in the workbook
object. |
public int getCellType() {
return cellType;
}
get the cells type (numeric, formula or string) |
protected CellValueRecordInterface getCellValueRecord() {
return record;
}
Should only be used by HSSFSheet and friends. Returns the low level CellValueRecordInterface record |
public short getEncoding() {
return encoding;
}
used for internationalization, currently 0 for compressed unicode or 1 for 16-bit |
public double getNumericCellValue() {
if (cellType == CELL_TYPE_BLANK)
{
return 0;
}
if (cellType == CELL_TYPE_STRING)
{
throw new NumberFormatException(
"You cannot get a numeric value from a String based cell");
}
return cellValue;
}
get the value of the cell as a number. For strings we throw an exception.
For blank cells we return a 0. |
public String getStringCellValue() {
if (cellType == CELL_TYPE_BLANK)
{
return "";
}
if (cellType == CELL_TYPE_NUMERIC)
{
throw new NumberFormatException(
"You cannot get a string value from a numeric cell");
}
return stringValue;
}
get the value of the cell as a string - for numeric cells we throw an exception.
For blank cells we return an empty string. |
public void setCellNum(short num) {
cellNum = num;
record.setColumn(num);
}
set the cell's number within the row (0 based) |
public void setCellStyle(HSSFCellStyle style) {
cellStyle = style;
record.setXFIndex(style.getIndex());
}
set the style for the cell. The style should be an HSSFCellStyle created/retreived from
the HSSFWorkbook. |
public void setCellType(int cellType) {
if (cellType == CELL_TYPE_FORMULA)
{
throw new RuntimeException(
"Formulas have not been implemented in this release");
}
if (cellType > CELL_TYPE_FORMULA)
{
throw new RuntimeException("I have no idea what type that is!");
}
switch (cellType)
{
case CELL_TYPE_FORMULA :
break;
case CELL_TYPE_NUMERIC :
NumberRecord nrec = null;
if (cellType != this.cellType)
{
nrec = new NumberRecord();
}
else
{
nrec = ( NumberRecord ) record;
}
nrec.setColumn(getCellNum());
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 ((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());
brec.setXFIndex(( short ) cellStyle.getIndex());
brec.setRow(row);
record = brec;
break;
}
if (cellType != this.cellType)
{
int loc = sheet.getLoc();
sheet.replaceValueRecord(record);
sheet.setLoc(loc);
}
this.cellType = cellType;
}
set the cells type (numeric, formula or string) -- DONT USE FORMULAS IN THIS RELEASE
WE'LL THROW YOU A RUNTIME EXCEPTION IF YOU DO |
public void setCellValue(double value) {
if (cellType == CELL_TYPE_BLANK)
{
throw new NumberFormatException(
"Blank cells cannot contain values");
}
if (cellType == CELL_TYPE_STRING)
{
throw new NumberFormatException(
"String cells cannot contain numbers");
}
(( NumberRecord ) record).setValue(value);
cellValue = value;
}
set a numeric value for the cell |
public void setCellValue(String value) {
if (cellType == CELL_TYPE_BLANK)
{
throw new NumberFormatException(
"Blank cells cannot contain values");
}
if (cellType == CELL_TYPE_NUMERIC)
{
throw new NumberFormatException(
"Numeric cells cannot contain strings");
}
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;
}
set a string value for the cell. |
public void setEncoding(short encoding) {
this.encoding = encoding;
}
set the encoding to either 8 or 16 bit. (US/UK use 8-bit, rest of the western world use 16bit) |