xelem.3.0

nl.fountain.xelem.excel.ss
Class SSCell

java.lang.Object
  extended by nl.fountain.xelem.excel.AbstractXLElement
      extended by nl.fountain.xelem.excel.ss.SSCell
All Implemented Interfaces:
Cell, XLElement

public class SSCell
extends AbstractXLElement
implements Cell

An implementation of the XLElement Cell.

The setData-methods

The overloaded setData-methods will set the data displayed in the cell when the xml spreadsheet is opened. These methods will set the Excel datatype according to the java-type of the passed parameter.

The setData(Object)-method reflects upon the class of the given object and will delegate to a corresponding setData-method if such a method is available. If no corresponding method is found this method sets the data of this cell to the toString-value of the given object and the datatype to "String". This class may be extended to accommodate setData-methods for java-objects that might otherwise be displayed as the toString-value of that object.

Null values
If the passed parameter has a value of null the resulting xml will have a datatype set to "Error", the formula of the cell will be set to "=#N/A" and the cell will display "#N/A" when the spreadsheet is opened.

Infinite values
If the passed parameter is of type Double, Float or the primitive representation of these objects and the method isInfinite results to true the resulting xml will have a datatype set to "String" and the cell will display "Infinite" when the spreadsheet is opened.

NaN values
If the passed parameter is of type Double, Float or the primitive representation of these objects and the method isNaN results to true the resulting xml will have a datatype set to "String" and the cell will display "NaN" when the spreadsheet is opened.

See Also:
Worksheet.addCell(), Row.addCell()

Field Summary
 
Fields inherited from interface nl.fountain.xelem.excel.Cell
DATATYPE_BOOLEAN, DATATYPE_DATE_TIME, DATATYPE_ERROR, DATATYPE_NUMBER, DATATYPE_STRING, ERRORVALUE_DIV_BY_0, ERRORVALUE_NA, ERRORVALUE_NAME, ERRORVALUE_NULL, ERRORVALUE_NUM, ERRORVALUE_REF, ERRORVALUE_VALUE
 
Fields inherited from interface nl.fountain.xelem.excel.XLElement
PREFIX_HTML, PREFIX_O, PREFIX_SS, PREFIX_X, XMLNS, XMLNS_HTML, XMLNS_O, XMLNS_SS, XMLNS_X
 
Constructor Summary
SSCell()
          Creates a new SSCell with an initial datatype of "String" and an empty ("") value.
 
Method Summary
 Comment addComment()
          Adds a comment to this cell.
 Comment addComment(Comment comment)
          Adds the given comment to this cell.
 Comment addComment(String text)
          Adds a comment to this cell and sets the data-attribute of the comment to the given text.
 Element assemble(Element parent, GIO gio)
          Assembles the state of this XLElement and all of it's children into an Element.
 boolean booleanValue()
          Convenience method for reading the value of the data element of this cell as a boolean.
 double doubleValue()
          Convenience method for reading the value of the data element of this cell as a double.
 Comment getComment()
          Gets the comment of this cell.
 Object getData()
          Gets the value of the data element of this cell as an object.
 String getData$()
          Gets the NodeValue of the Data-tag as a String.
 Element getDataElement(Document doc)
          Gets the Data-element of this cell as an org.w3c.dom.Element.
 String getFormula()
          Gets the formula that was set on this cell.
 String getHRef()
          Gets the ss:HRef-attribute value that was set on this cell.
 int getIndex()
          Gets the value of the ss:Index-attribute of this Cell-element.
 int getMergeAcross()
          Gets the number of cells over which this cell has been merged horizontally.
 int getMergeDown()
          Gets the number of cells over which this cell has been merged vertically.
 String getNameSpace()
          Gets the namespace of this XLElement.
 String getPrefix()
          Gets the prefix of this XLElement.
 String getStyleID()
          Gets the ss:StyleID which was set on this cell.
 String getTagName()
          Gets the tagname (localName) of this XLElement.
 String getXLDataType()
          Gets the value of the ss:Type-attribute of the Data-element.
 boolean hasComment()
          Specifies whether this cell has a comment.
 boolean hasData()
          Specifies whether this cell has data.
 boolean hasError()
          Specifies whether this cell has an error.
 int intValue()
          Convenience method for reading the value of the data element of this cell as an int.
 void setAttributes(Attributes attrs)
          Does effectively nothing.
 void setChildElement(String localName, String content)
          Does effectively nothing.
 void setData(boolean data)
          Sets the given boolean as the data of this cell.
 void setData(Boolean data)
          Sets the given Boolean as the data of this cell.
 void setData(byte data)
          Sets the given byte as the data of this cell.
 void setData(char data)
          Sets the data of this cell to the value String.valueOf(char).
 void setData(Date data)
          Sets the given Date as the data of this cell.
 void setData(double data)
          Sets the given double as the data of this cell.
 void setData(Double data)
          Sets the given Double as the data of this cell.
 void setData(float data)
          Sets the given float as the data of this cell.
 void setData(Float data)
          Sets the given Float as the data of this cell.
 void setData(int data)
          Sets the given int as the data of this cell.
 void setData(Integer data)
          Sets the given Integer as the data of this cell.
 void setData(long data)
          Sets the given long as the data of this cell.
 void setData(Long data)
          Sets the given Long as the data of this cell.
 void setData(Number data)
          Sets the given Number as the data of this cell.
 void setData(Object data)
          Sets the given object as the data of this cell.
 void setData(short data)
          Sets the given short as the data of this cell.
 void setData(String data)
          Sets the given String as the data of this cell.
 void setError(String error_value)
          Sets the given error value as the data of this cell.
 void setFormula(String formula)
          Sets the ss:Formula-attribute on this cell.
 void setHRef(String href)
          Sets the ss:HRef-attribute on this cell.
 void setIndex(int index)
          Sets the value of the ss:Index-attribute of this Cell-element.
 void setMergeAcross(int m)
          Merges this cell with adjacent cells on the same row.
 void setMergeDown(int m)
          Merges this cell with adjacent cells on the same column.
 void setStyleID(String id)
          Sets the ss:StyleID on this cell.
protected  void setType(String type)
          Sets the value of the ss:Type-attribute of the Data-element.
protected  void setXLDataType(String type)
          Deprecated. as of xelem.2.0 use setType(String)
 
Methods inherited from class nl.fountain.xelem.excel.AbstractXLElement
addElementComment, assemble, createAttributeNS, createAttributeNS, createElementNS, createElementNS, createElementNS, createElementNS, getElementComments
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nl.fountain.xelem.excel.XLElement
addElementComment, getElementComments
 

Constructor Detail

SSCell

public SSCell()
Creates a new SSCell with an initial datatype of "String" and an empty ("") value.

See Also:
Worksheet.addCell()
Method Detail

setStyleID

public void setStyleID(String id)
Sets the ss:StyleID on this cell. If no styleID is set on a cell, the ss:StyleID-attribute is not deployed in the resulting xml and the Default-style will be employed on the cell.

The refered style-definition must be available from the XFactory. If the definition was not found, the XLWorkbook-implementation will create an empty ss:Style-definition and adds a UnsupportedStyleException-warning.

Specified by:
setStyleID in interface Cell
Parameters:
id - the id of the style to employ on this cell.
See Also:
XLWorkbook.getWarnings()

getStyleID

public String getStyleID()
Description copied from interface: Cell
Gets the ss:StyleID which was set on this cell.

Specified by:
getStyleID in interface Cell
Returns:
The id of the style to employ on this cell or null if no styleID was previously set.

setFormula

public void setFormula(String formula)
Description copied from interface: Cell
Sets the ss:Formula-attribute on this cell. When opening a XML spreadsheet the formula-result goes before any data-value that was set on the cell.
         cell.setData(3);
         cell.setFormula("=1+1");
 
will display 2 in the opened spreadsheet.

Specified by:
setFormula in interface Cell
Parameters:
formula - The formula for this cell.

getFormula

public String getFormula()
Description copied from interface: Cell
Gets the formula that was set on this cell.

Specified by:
getFormula in interface Cell
Returns:
The formula that was set on this cell or null if the cell has no formula.

setHRef

public void setHRef(String href)
Description copied from interface: Cell
Sets the ss:HRef-attribute on this cell. Any special html-characters will be escaped in the reulting xml.

Specified by:
setHRef in interface Cell
Parameters:
href - the ss:HRef-attribute on this cell.

getHRef

public String getHRef()
Description copied from interface: Cell
Gets the ss:HRef-attribute value that was set on this cell.

Specified by:
getHRef in interface Cell
Returns:
The HRef that was set on this cell or null if this cell has no HRef.

addComment

public Comment addComment()
Description copied from interface: Cell
Adds a comment to this cell. Initially the comment has no text (no data and no author) and is not showing. If this cell allready had a comment, replaces this comment.

Specified by:
addComment in interface Cell
Returns:
the comment added to this cell

addComment

public Comment addComment(Comment comment)
Description copied from interface: Cell
Adds the given comment to this cell. If this cell allready had a comment, replaces this comment.

Specified by:
addComment in interface Cell
Parameters:
comment - the comment to be added to this cell
Returns:
the newly added comment

addComment

public Comment addComment(String text)
Description copied from interface: Cell
Adds a comment to this cell and sets the data-attribute of the comment to the given text. Initially the comment will have no author and is not showing. If this cell allready had a comment, replaces this comment.

Specified by:
addComment in interface Cell
Parameters:
text - the string to be displayed in the newly added comment
Returns:
the newly added comment

hasComment

public boolean hasComment()
Description copied from interface: Cell
Specifies whether this cell has a comment.

Specified by:
hasComment in interface Cell
Returns:
true if this cell has a comment, false otherwise.

getComment

public Comment getComment()
Description copied from interface: Cell
Gets the comment of this cell.

Specified by:
getComment in interface Cell
Returns:
the comment of this cell. May be null.

setMergeAcross

public void setMergeAcross(int m)
Description copied from interface: Cell
Merges this cell with adjacent cells on the same row.

The value of m must be greater than 0 in order to have effect on the resulting xml. No logic is included to prevent the merging of cells that goes beyond the width of the spreadsheet. If such is the case, the resulting xml spreadsheet will not open.

No other cells must be added within the scope of the merged cell:

         Cell c1 = sheet.addCellAt(1, 3);  // adds a cell at row 1, column 3
         c1.setMergeAcross(5);             // merges c1 across columns 3 - 8
         // illegal: first free index = 3 + 5 + 1 = 9
         // Cell c2 = sheet.addCellAt(1, 7);
 

Specified by:
setMergeAcross in interface Cell
Parameters:
m - The number of cells to include in the merge.

getMergeAcross

public int getMergeAcross()
Description copied from interface: Cell
Gets the number of cells over which this cell has been merged horizontally. A return value of 0 indicates no horizontal merge was applied on this cell.

Specified by:
getMergeAcross in interface Cell
Returns:
the number of cells that partake in the horizontal merge of this cell

setMergeDown

public void setMergeDown(int m)
Description copied from interface: Cell
Merges this cell with adjacent cells on the same column.

The value of m must be greater than 0 in order to have effect on the resulting xml.

No other rows or cells must be added within the scope of the merged cell:

         Cell c1 = sheet.addCellAt(1, 3);  // adds a cell at row 1, column 3
         c1.setMergeDown(5);             // merges c1 across rows 1 - 6
         // illegal: first free index = 1 + 5 + 1 = 7
         // Cell c2 = sheet.addCellAt(5, 3);
 

Specified by:
setMergeDown in interface Cell
Parameters:
m - The number of cells to include in the merge.

getMergeDown

public int getMergeDown()
Description copied from interface: Cell
Gets the number of cells over which this cell has been merged vertically. A return value of 0 indicates no vertical merge was applied on this cell.

Specified by:
getMergeDown in interface Cell
Returns:
the number of cells that partake in the vertical merge of this cell

getXLDataType

public String getXLDataType()
Description copied from interface: Cell
Gets the value of the ss:Type-attribute of the Data-element.

Specified by:
getXLDataType in interface Cell
Returns:
The value of the ss:Type-attribute of the Data-element.

setData

public void setData(Number data)
Description copied from interface: Cell
Sets the given Number as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setData

public void setData(Integer data)
Description copied from interface: Cell
Sets the given Integer as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setData

public void setData(Double data)
Description copied from interface: Cell
Sets the given Double as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values, Infinite values, NaN values

setData

public void setData(Long data)
Description copied from interface: Cell
Sets the given Long as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setData

public void setData(Float data)
Description copied from interface: Cell
Sets the given Float as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values, Infinite values, NaN values

setData

public void setData(Date data)
Description copied from interface: Cell
Sets the given Date as the data of this cell. The attribute ss:Type of the Data-element will be set to "DateTime".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setData

public void setData(Boolean data)
Description copied from interface: Cell
Sets the given Boolean as the data of this cell. The attribute ss:Type of the Data-element will be set to "Boolean".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setData

public void setData(String data)
Description copied from interface: Cell
Sets the given String as the data of this cell. The attribute ss:Type of the Data-element will be set to "String".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setData

public void setData(Object data)
Description copied from interface: Cell
Sets the given object as the data of this cell. This method reflects upon the class of the given object and will delegate to a corresponding setData-method if such a method is available. If no corresponding method is found this method sets the data of this cell to the toString-value of the given object and the datatype to "String".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Null values

setError

public void setError(String error_value)
Description copied from interface: Cell
Sets the given error value as the data of this cell. The attribute ss:Type of the Data-element will be set to "Error". The formula of this cell will be set to the corresponding error value.

Specified by:
setError in interface Cell
Parameters:
error_value - Must be one of Cell's ERRORVALUE_XXX values.

setData

public void setData(byte data)
Description copied from interface: Cell
Sets the given byte as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.

setData

public void setData(short data)
Description copied from interface: Cell
Sets the given short as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.

setData

public void setData(int data)
Description copied from interface: Cell
Sets the given int as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.

setData

public void setData(long data)
Description copied from interface: Cell
Sets the given long as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.

setData

public void setData(float data)
Description copied from interface: Cell
Sets the given float as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Infinite values, NaN values

setData

public void setData(double data)
Description copied from interface: Cell
Sets the given double as the data of this cell. The attribute ss:Type of the Data-element will be set to "Number".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.
See Also:
Infinite values, NaN values

setData

public void setData(char data)
Description copied from interface: Cell
Sets the data of this cell to the value String.valueOf(char). The attribute ss:Type of the Data-element will be set to "String".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.

setData

public void setData(boolean data)
Description copied from interface: Cell
Sets the given boolean as the data of this cell. The attribute ss:Type of the Data-element will be set to "Boolean".

Specified by:
setData in interface Cell
Parameters:
data - The data to be displayed in this cell.

hasData

public boolean hasData()
Description copied from interface: Cell
Specifies whether this cell has data.

Specified by:
hasData in interface Cell
Returns:
true if this cell has a data element, false otherwise

hasError

public boolean hasError()
Description copied from interface: Cell
Specifies whether this cell has an error.

Specified by:
hasError in interface Cell
Returns:
true if the 'Type' attribute of this cells data element equals DATATYPE_ERROR, false otherwise

getData$

public String getData$()
Description copied from interface: Cell
Gets the NodeValue of the Data-tag as a String.

Specified by:
getData$ in interface Cell
Returns:
The NodeValue of the Data-tag as a String.

getData

public Object getData()
Description copied from interface: Cell
Gets the value of the data element of this cell as an object. The type of the returned object is determined by the value of the 'Type' attribute of this cells data element.

xlDataTypereturned type
NumberDouble
DateTimeDate
BooleanBoolean
StringString
ErrorString
(not specified)String

Specified by:
getData in interface Cell
Returns:
the value of the data element of this cell as an object

intValue

public int intValue()
Description copied from interface: Cell
Convenience method for reading the value of the data element of this cell as an int. Returns 0 if the value could not be converted.

Specified by:
intValue in interface Cell
Returns:
the value of the data element

doubleValue

public double doubleValue()
Description copied from interface: Cell
Convenience method for reading the value of the data element of this cell as a double. Returns 0.0 if the value could not be converted.

Specified by:
doubleValue in interface Cell
Returns:
the value of the data element

booleanValue

public boolean booleanValue()
Description copied from interface: Cell
Convenience method for reading the value of the data element of this cell as a boolean. Returns false if the value is not equal to "1".

Specified by:
booleanValue in interface Cell
Returns:
the value of the data element

getTagName

public String getTagName()
Description copied from interface: XLElement
Gets the tagname (localName) of this XLElement.

Specified by:
getTagName in interface XLElement
Returns:
qualified name

getNameSpace

public String getNameSpace()
Description copied from interface: XLElement
Gets the namespace of this XLElement.

Specified by:
getNameSpace in interface XLElement
Returns:
namespace

getPrefix

public String getPrefix()
Description copied from interface: XLElement
Gets the prefix of this XLElement.

Specified by:
getPrefix in interface XLElement
Returns:
prefix

assemble

public Element assemble(Element parent,
                        GIO gio)
Description copied from interface: XLElement
Assembles the state of this XLElement and all of it's children into an Element. Attaches the new element to it's parent-element if needed.

Specified by:
assemble in interface XLElement
Parameters:
parent - the parent-element to which the new formed element will be appended
gio - a global information object
Returns:
the newly assembled element. may be null.

setAttributes

public void setAttributes(Attributes attrs)
Description copied from class: AbstractXLElement
Does effectively nothing.

Specified by:
setAttributes in interface XLElement
Overrides:
setAttributes in class AbstractXLElement
Parameters:
attrs - the attributes found on the element

setChildElement

public void setChildElement(String localName,
                            String content)
Description copied from class: AbstractXLElement
Does effectively nothing.

Specified by:
setChildElement in interface XLElement
Overrides:
setChildElement in class AbstractXLElement
Parameters:
localName - the local name of the child
content - the content of the child

getDataElement

public Element getDataElement(Document doc)
Description copied from interface: Cell
Gets the Data-element of this cell as an org.w3c.dom.Element.

Specified by:
getDataElement in interface Cell
Parameters:
doc - the document to which the returned element may be appended
Returns:
the Data-element

setXLDataType

protected void setXLDataType(String type)
Deprecated. as of xelem.2.0 use setType(String)

Parameters:
type - one of Cell's DATATYPE_XXX values

setType

protected void setType(String type)
Sets the value of the ss:Type-attribute of the Data-element.

Parameters:
type - Must be one of Cell's DATATYPE_XXX values.

setIndex

public void setIndex(int index)
Description copied from interface: Cell
Sets the value of the ss:Index-attribute of this Cell-element. Any value set may be overruled by Row.cellIterator(), which sets the index of cells during assembly.

If you want to place a cell in any particular place, use the addCellAt-methods of Row, Table or Worksheet, or use Worksheets CellPointer.

Specified by:
setIndex in interface Cell
Parameters:
index - the index of this cell

getIndex

public int getIndex()
Description copied from interface: Cell
Gets the value of the ss:Index-attribute of this Cell-element. The returned value only makes sence if this cell was read with the reader-API in the nl.fountain.xelem.lex-package and before any manipulation of this cell or the workbook took place.

Specified by:
getIndex in interface Cell
Returns:
the value of the ss:Index-attribute of this Cell-element

xelem.3.0