public class Cell extends Component implements ListContainer, ParagraphContainer, FrameContainer
Table provides methods to get/set/modify the cell content and cell properties.
Modifier and Type | Method and Description |
---|---|
List |
addList()
Add a new List to this container.
|
List |
addList(ListDecorator decorator)
Add a List with specified ListDecorator to this container.
|
Paragraph |
addParagraph(String text)
Creates a new paragraph and append text
|
void |
clearList()
Remove all Lists from this container.
|
Boolean |
getBooleanValue()
Get the cell boolean value as Boolean object.
|
Border |
getBorder(StyleTypeDefinitions.CellBordersType type)
Return the border setting for a specific border.
|
BufferedImage |
getBufferedImage()
Deprecated.
|
Color |
getCellBackgroundColor()
Get the background color of this cell.
|
String |
getCellBackgroundColorString()
Deprecated.
As of Simple version 0.3, replaced by
getCellBackgroundColor() |
String |
getCellStyleName()
Get the cell style name.
|
int |
getColumnIndex()
Get the index of the table column which contains this cell.
|
int |
getColumnSpannedNumber()
Get the column spanned number of this cell.
|
String |
getCurrencyCode()
Return the currency code of this cell, for example, "USD", "EUR", "CNY",
and etc.
|
String |
getCurrencySymbol()
Get the symbol of currency.
|
Double |
getCurrencyValue()
Get the currency value of this cell as Double object.
|
Calendar |
getDateValue()
Get the cell date value as Calendar.
|
String |
getDisplayText()
Get the text displayed in this cell.
|
Double |
getDoubleValue()
Get the double value of this cell as Double object.
|
Font |
getFont()
Return the font definition for this cell.
|
String |
getFormatString()
Get the format string of the cell.
|
String |
getFormula()
Get the formula string of the cell.
|
OdfElement |
getFrameContainerElement()
Get the ODF element which can have
|
String |
getHorizontalAlignment()
Deprecated.
As of Simple version 0.3, replaced by
getHorizontalAlignmentType() |
StyleTypeDefinitions.HorizontalAlignmentType |
getHorizontalAlignmentType()
Return the horizontal alignment setting of this cell.
|
Image |
getImage()
Get the image from the specified cell.
|
static Cell |
getInstance(TableTableCellElementBase cellElement)
Get the
Cell instance from the
TableTableCellElementBase instance. |
OdfElement |
getListContainerElement()
Get the ODF element which can have
|
Iterator<List> |
getListIterator()
Return an Iterator of the Lists in this ListContainer.
|
String |
getNoteText()
Get the note text of this table cell.
|
TableTableCellElementBase |
getOdfElement()
Get the instance of
TableTableCellElementBase which
represents this cell. |
Cell |
getOwnerTableCell()
Get the cell that covers this cell.
|
Paragraph |
getParagraphByIndex(int index,
boolean isEmptyParagraphSkipped)
Return a paragraph with a given index.
|
Paragraph |
getParagraphByReverseIndex(int reverseIndex,
boolean isEmptyParagraphSkipped)
Return a paragraph with a given index.
|
OdfElement |
getParagraphContainerElement()
Get the ODF element which can have
|
Iterator<Paragraph> |
getParagraphIterator()
Return an Iterator of the paragraph in this container.
|
Double |
getPercentageValue()
Get the cell percentage value as Double object.
|
int |
getRowIndex()
Get the index of the table row which contains this cell.
|
int |
getRowSpannedNumber()
Get the row spanned number of this cell.
|
String |
getStringValue()
Get the cell value as a string.
|
CellStyleHandler |
getStyleHandler()
Return style handler for this cell
|
String |
getStyleName()
Get the style name of this cell.
|
Table |
getTable()
Get an instance of table feature which contains this cell.
|
Column |
getTableColumn()
Get the instance of table column feature which contains this cell.
|
Row |
getTableRow()
Get the instance of table row feature which contains this cell.
|
Calendar |
getTimeValue()
Get the cell value as
java.util.Calendar . |
String |
getValueType()
Get the value type of this cell.
|
String |
getVerticalAlignment()
Deprecated.
As of Simple version 0.3, replaced by
getVerticalAlignmentType() |
StyleTypeDefinitions.VerticalAlignmentType |
getVerticalAlignmentType()
Return the vertical alignment setting of this cell.
|
boolean |
isTextWrapped()
Return the wrap option of this cell.
|
void |
removeContent()
Remove all the content of the cell.
|
boolean |
removeList(List list)
Remove the existing List from this container.
|
boolean |
removeParagraph(Paragraph para)
Remove paragraph from this document
|
void |
removeTextContent()
Remove all the text content of cell.
|
void |
setBooleanValue(Boolean value)
Set the cell value as a boolean and set the value type to be boolean.
|
void |
setBorders(StyleTypeDefinitions.CellBordersType bordersType,
Border border)
Set the border style definitions for this cell.
|
void |
setCellBackgroundColor(Color cellBackgroundColor)
Set the background color of this cell.
|
void |
setCellBackgroundColor(String cellBackgroundColor)
Deprecated.
As of Simple version 0.3, replaced by
setCellBackgroundColor(Color) |
void |
setCellStyleName(String styleName)
Set the cell style name.
|
void |
setCurrencyCode(String currency)
Set the currency code of this cell, for example, "USD", "EUR", "CNY", and
etc.
|
void |
setCurrencyFormat(String currencySymbol,
String format)
Set the currency symbol and overall format of a currency cell.
|
void |
setCurrencyValue(Double value,
String currency)
Set the value and currency of the cell, and set the value type as
"currency".
|
void |
setDateValue(Calendar date)
Set the cell value as a date, and set the value type to be "date".
|
void |
setDisplayText(String content)
Set the text displayed in this cell.
|
void |
setDisplayText(String content,
CellValueAdapter adapter)
Set the text displayed in this cell.
|
void |
setDisplayText(String content,
CellValueAdapter adapter,
String stylename)
Set the text displayed in this cell, with a specified style name.
|
void |
setDisplayText(String content,
String stylename)
Set the text displayed in this cell, with a specified style name.
|
void |
setDoubleValue(Double value)
Set the cell value as a double and set the value type to be "float".
|
void |
setFont(Font font)
Set font style for this cell.
|
void |
setFormatString(String formatStr)
Set the format string of the cell.
|
void |
setFormula(String formula)
Set a formula to the cell.
|
void |
setHorizontalAlignment(String horizontalAlignment)
Deprecated.
As of Simple version 0.3, replaced by
setHorizontalAlignment(SimpleHorizontalAlignmentType) |
void |
setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType alignType)
Set the horizontal alignment setting of this cell.
|
Image |
setImage(URI imageUri)
Insert an Image from the specified uri to cell.
|
void |
setInputHelpMessage(String title,
String text)
Sets the title and the text of the tip, which will then be displayed if
the cell is selected.
|
void |
setNoteText(String note)
Set note text for this table cell.
|
void |
setPercentageValue(Double value)
Set the cell value as a percentage value and set the value type as
percentage too.
|
void |
setStringValue(String str)
Set the cell value as a string, and set the value type to be string.
|
void |
setTextWrapped(boolean isTextWrapped)
Set the wrap option of this cell.
|
void |
setTimeValue(Calendar time)
Set the cell value as a time and set the value type to be "time" too.
|
void |
setValidityList(List<String> values)
Specifies the allowed values of this cell in a list.
|
void |
setValueType(String type)
Set the value type of this cell.
|
void |
setVerticalAlignment(String verticalAlignment)
Deprecated.
As of Simple version 0.3, replaced by
setVerticalAlignment(SimpleVerticalAlignmentType) |
void |
setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType verticalAlignment)
Set the vertical alignment setting of this cell.
|
getComponentByElement, getOwnerDocument, registerComponent, unregisterComponent
public static Cell getInstance(TableTableCellElementBase cellElement)
Cell
instance from the
TableTableCellElementBase
instance.
Each TableTableCellElementBase
instance has a one-to-one
relationship to the a Cell
instance.
cellElement
- the cell element that need to get the corresponding
Cell
instanceCell
instance that represents a specified cell
element@Deprecated public String getHorizontalAlignment()
getHorizontalAlignmentType()
The returned value can be "center", "end", "justify", "left", "right", or "start". If no horizontal alignment is set, null will be returned.
getHorizontalAlignmentType()
public StyleTypeDefinitions.HorizontalAlignmentType getHorizontalAlignmentType()
Null will returned if there is no explicit style definition for this cell.
Default value will be returned if explicit style definition is found but no horizontal alignment is set.
@Deprecated public void setHorizontalAlignment(String horizontalAlignment)
setHorizontalAlignment(SimpleHorizontalAlignmentType)
The parameter can be "center", "end", "justify", "left", "right", or "start". Actually, "left" will be interpreted as "start", while "right" will be interpreted as "end". If argument is null, the explicit horizontal alignment setting is removed.
horizontalAlignment
- the horizontal alignment setting.setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType)
public void setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType alignType)
alignType
- the horizontal alignment setting.@Deprecated public String getVerticalAlignment()
getVerticalAlignmentType()
The returned value can be "auto", "automatic", "baseline", "bottom", "middle", or "top".
getVerticalAlignmentType()
public StyleTypeDefinitions.VerticalAlignmentType getVerticalAlignmentType()
Null will returned if there is no explicit style definition for this cell.
Default value will be returned if explicit style definition is found but no vertical alignment is set.
@Deprecated public void setVerticalAlignment(String verticalAlignment)
setVerticalAlignment(SimpleVerticalAlignmentType)
The parameter can be "auto", "automatic", "baseline", "bottom", "middle", or "top". If argument is null, the explicit vertical alignment setting is removed.
verticalAlignment
- the vertical alignment setting.setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType)
public void setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType verticalAlignment)
If the alignment is set as Default or null, the explicit vertical alignment setting is removed.
verticalAlignment
- the vertical alignment setting.public boolean isTextWrapped()
false if the cell content cannot be wrapped.
public void setTextWrapped(boolean isTextWrapped)
isTextWrapped
- whether the cell content can be wrapped or notpublic int getRowIndex()
public Table getTable()
public int getColumnIndex()
public Column getTableColumn()
public Row getTableRow()
public Cell getOwnerTableCell()
If the cell is a covered cell, the owner cell will be returned; if the cell is a real cell , the cell itself will be returned.
public TableTableCellElementBase getOdfElement()
TableTableCellElementBase
which
represents this cell.getOdfElement
in class Component
TableTableCellElementBase
public String getCurrencyCode()
If the value type is not "currency", an IllegalArgumentException will be thrown.
IllegalArgumentException
- an IllegalArgumentException will be thrown if the value type
is not "currency".public void setCurrencyCode(String currency)
currency
- the currency code that need to be set.IllegalArgumentException
- If input currency
is null, an
IllegalArgumentException will be thrown.public void setValueType(String type)
If the parameter type
is not a valid cell type, an
IllegalArgumentException will be thrown.
type
- the type that need to be set If input type is null, an
IllegalArgumentException will be thrown.public String getValueType()
public Double getDoubleValue()
Throw IllegalArgumentException if the cell type is not "float".
An IllegalArgumentException will be thrown if the cell type is not "float".
public Double getCurrencyValue()
Throw IllegalArgumentException if the cell type is not "currency".
IllegalArgumentException
- an IllegalArgumentException will be thrown if the cell type
is not "currency".public String getCurrencySymbol()
IllegalArgumentException
- an IllegalArgumentException will be thrown if the value type
is not "currency".public void setCurrencyValue(Double value, String currency)
value is null, the cell value will be removed.
value
- the value that will be setcurrency
- the currency that will be set.IllegalArgumentException
- If input currency is null, an IllegalArgumentException will
be thrown.public Double getPercentageValue()
Throw IllegalArgumentException if the cell type is not "percentage".
IllegalArgumentException
- an IllegalArgumentException will be thrown if the cell type
is not "percentage".public void setPercentageValue(Double value)
value is null, the cell value will be removed.
value
- the value that will be setpublic String getDisplayText()
public void setDisplayText(String content, CellValueAdapter adapter)
Please note the displayed text in ODF viewer might be different with the value set by this method, because the displayed text in ODF viewer is calculated and set by editor. So an adapter can be assigned to adapt cell value and value type.
content
- the displayed text.adapter
- the CellValueAdapter
used to adapt cell value and
value type.CellValueAdapter
public void setDisplayText(String content)
Please note the displayed text in ODF viewer might be different with the
value set by this method, because the displayed text in ODF viewer is
calculated and set by editor. The cell value and value type will be
updated follow by the rules which are designed in the
.DefaultCellValueAdapter
content
- the displayed text.CellValueAdapter
,
DefaultCellValueAdapter
public void setDisplayText(String content, CellValueAdapter adapter, String stylename)
Please note the displayed text in ODF viewer might be different with the value set by this method, because the displayed text in ODF viewer is calculated and set by editor. So an adapter can be assigned to adapt cell value and value type.
content
- the displayed text. If content is null, it will display the
empty string instead.adapter
- the CellValueAdapter
used to adapt cell value and
value type.stylename
- the style name. If style name is null, the content will use
the default paragraph style.CellValueAdapter
public void setDisplayText(String content, String stylename)
Please note the displayed text in ODF viewer might be different with the
value set by this method, because the displayed text in ODF viewer is
calculated and set by editor. The cell value and value type will be
updated follow by the rules which are designed in the
.DefaultCellValueAdapter
content
- the displayed text. If content is null, it will display the
empty string instead.stylename
- the style name. If style name is null, the content will use
the default paragraph style.CellValueAdapter
,
DefaultCellValueAdapter
public void setDoubleValue(Double value)
value
- the double value that will be set. If
value is null, the cell value will be removed.
public Boolean getBooleanValue()
Throw IllegalArgumentException if the cell type is not "boolean".
IllegalArgumentException
- an IllegalArgumentException will be thrown if the cell type
is not "boolean".public void setBooleanValue(Boolean value)
value is null, the cell value will be removed.
value
- the value of boolean typepublic Calendar getDateValue()
Throw IllegalArgumentException if the cell type is not "date".
IllegalArgumentException
- an IllegalArgumentException will be thrown, if the cell type
is not "date".public void setDateValue(Calendar date)
date
- the value of java.util.Calendar
type.public void setCellStyleName(String styleName)
styleName
- an exit cell style name.public String getCellStyleName()
public void setStringValue(String str)
str
- the value of string type. If input string is null, an empty
string will be set.public String getStringValue()
If the cell type is not string, the display text will be returned.
public Calendar getTimeValue()
java.util.Calendar
.
Throw exception if the cell type is not "time".
IllegalArgumentException
- an IllegalArgumentException will be thrown if the cell type
is not time.public void setTimeValue(Calendar time)
time
- the value of java.util.Calendar
type.IllegalArgumentException
- If input time is null, an IllegalArgumentException exception
will be thrown.public Color getCellBackgroundColor()
If no background color is set, default background color "#FFFFFF" will be returned.
@Deprecated public String getCellBackgroundColorString()
getCellBackgroundColor()
If no background color is set, default background color "#FFFFFF" will be returned.
getCellBackgroundColor()
public void setCellBackgroundColor(Color cellBackgroundColor)
cellBackgroundColor
- the background color that need to set. If
cellBackgroundColor
is null, default background
color Color.WHITE
will be set.@Deprecated public void setCellBackgroundColor(String cellBackgroundColor)
setCellBackgroundColor(Color)
org.odftoolkit.odfdom.type.Color
.cellBackgroundColor
- the background color that need to set. If cellBackgroundColor
is null, default background color #FFFFFF will be set.Color
,
setCellBackgroundColor(Color)
public int getColumnSpannedNumber()
public int getRowSpannedNumber()
public String getStyleName()
public void setFormula(String formula)
Please note, the parameter formula
will not be checked and
interpreted; the cell value will not be calculated. It's just simply set
as a formula attribute.
formula
- the formula that need to be set.IllegalArgumentException
- if formula is null, an IllegalArgumentException will be
thrown.TableFormulaAttribute
public String getFormula()
If the cell does not contain a formula, null will be returned.
public void setCurrencyFormat(String currencySymbol, String format)
Please note the overall format includes the symbol character, for example: $#,##0.00.
This function only works for currency.
currencySymbol
- the currency symbolformat
- overall formatIllegalArgumentException
- if input currencySymbol or format is null, an
IllegalArgumentException will be thrown.public void setFormatString(String formatStr)
This function only works for float, date, time and percentage, otherwise an
IllegalArgumentException
will be thrown.
For value type float and percentage, the formatStr
must follow the encoding
rule of
.
For value type date and time, the java.text.DecimalFormat
formatStr
must follow the encoding
rule of
.
java.text.SimpleDateFormat
Refer to
to set the format of currency.
setCurrencyFormat
If the cell value type is not set, the method will try to give it a value type, according to common ordination. The adapt order is: percentage-> time-> date-> float.
The adapt result may be inaccurate, so you'd better set value type before call this method. If adaptive failed, an
ValueType Distinguish Symbol Distinguish Priority percentage % 1 time H, k, m, s, S 2 date y, M, w, W, D, d, F, E, K, h 3 float #, 0 4
UnsupportedOperationException
will be thrown.
formatStr
- the cell need be formatted as this specified format string.IllegalArgumentException
- if formatStr
is null or the cell value type is supported.UnsupportedOperationException
- if the adaptive failed, when cell value type is not set.SimpleDateFormat
,
DecimalFormat
public String getFormatString()
public void removeTextContent()
public void removeContent()
public Font getFont()
Null will be returned if there is no explicit style definition, or even default style definition, for this cell.
public void setFont(Font font)
font
- - the fontpublic void setBorders(StyleTypeDefinitions.CellBordersType bordersType, Border border)
This method will invoke
CellStyleHandler.setBorders(Border border, SimpleCellBordersType bordersType).
bordersType
- - A predefined border typeborder
- - border style descriptionCellStyleHandler.setBorders(Border border,
StyleTypeDefinitions.CellBordersType bordersType)
public Border getBorder(StyleTypeDefinitions.CellBordersType type)
This method will invoke
CellStyleHandler.getBorder(SimpleCellBordersType type).
type
- - the border type which describes a single borderCellStyleHandler.getBorder(StyleTypeDefinitions.CellBordersType
type)
public String getNoteText()
null
will be returned.
The note may contain text list, text paragraph and styles, but this method extracts only text from them.
public void setNoteText(String note)
Only simple text is supported to receive in this method, which is a sub function of office annotation. So overwriting a note with text might loose structure and styles.
note
- note content.public Image setImage(URI imageUri)
imageUri
- The URI of the image that will be added to the cell, add image
stream to the package, in the 'Pictures/' graphic directory
with the same image file name as in the URI. If the imageURI
is relative first the user.dir is taken to make it absolute.public BufferedImage getBufferedImage()
Image
will be returned.public Image getImage()
Image
will be returned.public CellStyleHandler getStyleHandler()
public OdfElement getListContainerElement()
ListContainer
getListContainerElement
in interface ListContainer
public List addList()
ListContainer
addList
in interface ListContainer
public List addList(ListDecorator decorator)
ListContainer
addList
in interface ListContainer
decorator
- the specified ListDecoratorpublic void clearList()
ListContainer
clearList
in interface ListContainer
public Iterator<List> getListIterator()
ListContainer
getListIterator
in interface ListContainer
Iterator
public boolean removeList(List list)
ListContainer
removeList
in interface ListContainer
public Paragraph addParagraph(String text)
addParagraph
in interface ParagraphContainer
text
- Exception
- if the file DOM could not be created.public boolean removeParagraph(Paragraph para)
removeParagraph
in interface ParagraphContainer
para
- - the instance of paragraphpublic OdfElement getParagraphContainerElement()
getParagraphContainerElement
in interface ParagraphContainer
public Paragraph getParagraphByIndex(int index, boolean isEmptyParagraphSkipped)
An index of zero represents the first paragraph.
If empty paragraph is skipped, the empty paragraph won't be counted.
getParagraphByIndex
in interface ParagraphContainer
index
- - the index started from 0.isEmptyParagraphSkipped
- - whether the empty paragraph is skipped or notpublic Paragraph getParagraphByReverseIndex(int reverseIndex, boolean isEmptyParagraphSkipped)
An index of zero represents the last paragraph.
If empty paragraph is skipped, the empty paragraph won't be counted.
getParagraphByReverseIndex
in interface ParagraphContainer
reverseIndex
- - the index started from 0 in reverse order.isEmptyParagraphSkipped
- - whether the empty paragraph is skipped or notpublic Iterator<Paragraph> getParagraphIterator()
getParagraphIterator
in interface ParagraphContainer
public OdfElement getFrameContainerElement()
FrameContainer
getFrameContainerElement
in interface FrameContainer
public void setValidityList(List<String> values)
NOTE: Now, the validity rule does not take effect when a cell value is updated by Simple ODF API yet.
values
- the list of allowed values.Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.