com.csam.dif
Class DIFCell
- java.lang.Object
-
- com.csam.dif.DIFCell
-
public final class DIFCell extends java.lang.ObjectThis class represents a single data cell in the spreadsheet. It is comprised primarily of a type marker and a value holder.
Any of the
setXXXmethods will also set the cell's type to more closely represent the data within the cell. However, this dynamic typing of the data does mean that usingsetCellTypemay lead to unexpected behavior, as this method makes no attempt at type-casting of any existing values.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classDIFCell.CellTypeenum of the available cell types supported
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleangetBooleanCellValue()Returns the value of this cell expressed as abooleanvalue.intgetCellNumber()Returns the physical cell number within the row where this cell exists.DIFCell.CellTypegetCellType()Returns an indication of the type of data stored in this cell.java.sql.DategetDateCellValue()Returns theDatevalue stored at this cell.doublegetDoubleCellValue()Identical togetNumericCellValue()except the result is expressed as a nativedoubletype.longgetIntCellValue()Identical togetNumericCellValue()except the result is expressed as a nativedoubletypelonggetLongCellValue()Identical togetNumericCellValue()except the result is expressed as a nativedoubletypejava.math.BigDecimalgetNumericCellValue()Returns the value of this cell expressed as a numeric value (enclosed in aBigDecimal).intgetRowNumber()Returns the physical row number within the sheet where this cell exists (seeDIFRow.getRowNumber()for a detailed description of this).java.lang.StringgetStringCellValue()Returns the value of this cell expressed as a numeric.voidsetCellType(DIFCell.CellType cellType)Sets the current cell type.voidsetCellValue(java.math.BigDecimal value)Sets this cell's value, and changes theCellTypetoNUMERICvoidsetCellValue(boolean value)Sets this cell's value, and changes theCellTypetoBOOLEANvoidsetCellValue(java.sql.Date value)Sets this cell's value, and changes theCellTypetoDATEvoidsetCellValue(double value)Identical tosetCellValue(BigDecimal), except using a native data type ofdouble.voidsetCellValue(int value)Identical tosetCellValue(BigDecimal), except using a native data type ofint.voidsetCellValue(long value)Identical tosetCellValue(BigDecimal), except using a native data type oflong.voidsetCellValue(java.lang.String value)Sets this cell's value, and changes theCellTypetoSTRING
-
-
-
Method Detail
-
setCellType
public void setCellType(DIFCell.CellType cellType)
Sets the current cell type. This method should generally be avoided, as no type-conversion takes place when the cell type is being set. If there is already data stored in the cell, the results of accessing this object will become unreliable.- Parameters:
cellType-CellTypeof data in this cell.
-
getCellType
public DIFCell.CellType getCellType()
Returns an indication of the type of data stored in this cell.- Returns:
- type of data stored in this cell.
-
getRowNumber
public int getRowNumber()
Returns the physical row number within the sheet where this cell exists (seeDIFRow.getRowNumber()for a detailed description of this).- Returns:
introw number
-
getCellNumber
public int getCellNumber()
Returns the physical cell number within the row where this cell exists. A "physical" number is defined as the visual position of the cell as opposed to a "logical" position. What this means in real-terms is that in any given row, several cells may be "empty". Thus, these cells may not be represented in the row model. If the first cell within a row which contains data is located on the third cell of the spreadsheet, then the "physical number" is 2 (the numbers are zero-based, meaning the first cell is 0, not 1).- Returns:
intcell number
-
setCellValue
public void setCellValue(boolean value)
Sets this cell's value, and changes theCellTypetoBOOLEAN- Parameters:
value- the boolean value of this cell
-
setCellValue
public void setCellValue(java.math.BigDecimal value)
Sets this cell's value, and changes theCellTypetoNUMERIC- Parameters:
value- the numeric value of this cell
-
setCellValue
public void setCellValue(double value)
Identical tosetCellValue(BigDecimal), except using a native data type ofdouble.- Parameters:
value- the numeric value of this cell
-
setCellValue
public void setCellValue(long value)
Identical tosetCellValue(BigDecimal), except using a native data type oflong.- Parameters:
value- the numeric value of this cell
-
setCellValue
public void setCellValue(int value)
Identical tosetCellValue(BigDecimal), except using a native data type ofint.- Parameters:
value- the numeric value of this cell
-
setCellValue
public void setCellValue(java.lang.String value)
Sets this cell's value, and changes theCellTypetoSTRING- Parameters:
value- the string value of this cell
-
setCellValue
public void setCellValue(java.sql.Date value)
Sets this cell's value, and changes theCellTypetoDATE- Parameters:
value- the date value of this cell
-
getBooleanCellValue
public boolean getBooleanCellValue() throws DIFDataExceptionReturns the value of this cell expressed as abooleanvalue. If the cell type isBOOLEAN, the value returned is an exact reflection of this. This the cell type isBLANKthenfalseis returned. If the cell type isNUMERICthentrueis returned for any non-zero value, otherwisefalse. If the cell type isSTRING, then the string value is parsed (usingBoolean.valueOf(String)) and the result returned.- Returns:
trueoralse- Throws:
DIFDataException- if the underlying data type cannot be expressed as a boolean value
-
getNumericCellValue
public java.math.BigDecimal getNumericCellValue() throws DIFDataExceptionReturns the value of this cell expressed as a numeric value (enclosed in aBigDecimal). If the cell type isBLANKthe 0 (zero) is returned. If the cell type isBOOLEANthen 1 (one) is returned fortruevalues, otherwise 0 (zero). If the cell type isNUMERICthen the value is returned as-is. If the cell type isSTRING, then a conversion is attempted (usingnew BigDecimal(String)) and the value of this returned.- Returns:
- numeric value enclosed in a
BigDecimal - Throws:
DIFDataException- if the underlying data type cannot be expressed as a numeric value
-
getStringCellValue
public java.lang.String getStringCellValue() throws DIFDataExceptionReturns the value of this cell expressed as a numeric. If the cell type isSTRINGthen the value is returned as-is. All other data types are converted usingString.valueOf(Object).- Returns:
- string representation of cell data
- Throws:
DIFDataException- if the underlying data type cannot be expressed as a string value
-
getDateCellValue
public java.sql.Date getDateCellValue() throws DIFDataExceptionReturns theDatevalue stored at this cell. No other type conversion occurs here. Any other cell type will cause an exception.- Returns:
Datevalue of this cell- Throws:
DIFDataException- if the underlying data type cannot be expressed as a date value (i.e. anything other thanDATE).
-
getDoubleCellValue
public double getDoubleCellValue() throws DIFDataExceptionIdentical togetNumericCellValue()except the result is expressed as a nativedoubletype.- Returns:
- numeric value expressed as a
double - Throws:
DIFDataException- if the underlying data type cannot be expressed as a numeric value
-
getLongCellValue
public long getLongCellValue() throws DIFDataExceptionIdentical togetNumericCellValue()except the result is expressed as a nativedoubletype- Returns:
- numeric value expressed a
long - Throws:
DIFDataException- if the underlying data type cannot be expressed as a numeric value
-
getIntCellValue
public long getIntCellValue() throws DIFDataExceptionIdentical togetNumericCellValue()except the result is expressed as a nativedoubletype- Returns:
- numeric value expressed an
int - Throws:
DIFDataException- if the underlying data type cannot be expressed as a numeric value
-
-
DMelt 3.0 © DataMelt by jWork.ORG