Class OdfTableCell
- java.lang.Object
-
- org.odftoolkit.odfdom.doc.table.OdfTableCell
-
public class OdfTableCell extends Object
OdfTableCell represents table cell feature in ODF document.OdfTable provides methods to get/set/modify the cell content and cell properties.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BooleangetBooleanValue()Get the cell boolean value as Boolean object.ColorgetCellBackgroundColor()Get the background color of this cell.StringgetCellBackgroundColorString()Get the background color string of this cell.protected OdfStylegetCellStyleElement()protected OdfStylegetCellStyleElementForWrite()intgetColumnIndex()Get the index of the table column which contains this cell.StringgetCurrencyCode()Return the currency code of this cell, for example, "USD", "EUR", "CNY", and etc.StringgetCurrencySymbol()Get the symbol of currency.DoublegetCurrencyValue()Get the currency value of this cell as Double object.CalendargetDateValue()Deprecated.usegetLocalDateValue()instead.StringgetDisplayText()Get the text displayed in this cell.DoublegetDoubleValue()Get the double value of this cell as Double object.DurationgetDurationValue()Get the cell value asDuration.StringgetFormatString()Get the format string of the cell.StringgetFormula()Get the formula string of the cell.StringgetHorizontalAlignment()Return the horizontal alignment setting of this cell.static OdfTableCellgetInstance(TableTableCellElementBase cellElement)Get theOdfTableCellinstance from theTableTableCellElementBaseinstance.LocalDateTimegetLocalDateTimeValue()Get the cell date value asLocalDate.LocalDategetLocalDateValue()Get the cell date value asLocalDate.LocalTimegetLocalTimeValue()Get the cell value asLocalTime.TableTableCellElementBasegetOdfElement()Get the instance ofTableTableCellElementBasewhich represents this cell.OdfTableCellgetOwnerTableCell()Get the cell that covers this cell.DoublegetPercentageValue()Get the cell percentage value as Double object.intgetRowIndex()Get the index of the table row which contains this cell.StringgetStringValue()Get the cell value as a string.StringgetStyleName()Get the style name of this cell.OdfTablegetTable()Get an instance of table feature which contains this cell.OdfTableColumngetTableColumn()Get the instance of table column feature which contains this cell.OdfTableRowgetTableRow()Get the instance of table row feature which contains this cell.CalendargetTimeValue()Deprecated.usegetLocalTimeValue()instead.StringgetValueType()Get the value type of this cell.StringgetVerticalAlignment()Return the vertical alignment setting of this cell.booleanisTextWrapped()Return the wrap option of this cell.voidremoveContent()Remove all the content of the cell.voidremoveTextContent()Remove all the text content of cell.OdfTableCellsetBooleanValue(Boolean value)Set the cell value as a boolean and set the value type to be boolean.OdfTableCellsetCellBackgroundColor(String cellBackgroundColor)Set the background color of this cell using string.OdfTableCellsetCellBackgroundColor(Color cellBackgroundColor)Set the background color of this cell.OdfTableCellsetCurrencyCode(String currency)Set the currency code of this cell, for example, "USD", "EUR", "CNY", and etc.OdfTableCellsetCurrencyFormat(String currencySymbol, String format)Set the currency symbol and overall format of a currency cell.OdfTableCellsetCurrencyValue(Double value, String currency)Set the value and currency of the cell, and set the value type as "currency".OdfTableCellsetDateTimeValue(Calendar date)Deprecated.usesetLocalDateValue(java.time.LocalDate)instead.OdfTableCellsetDateValue(Calendar date)Deprecated.usesetLocalDateValue(java.time.LocalDate)instead.OdfTableCellsetDisplayText(String content)Set the text displayed in this cell.OdfTableCellsetDisplayText(String content, String stylename)Set the text displayed in this cell, with a specified style name.OdfTableCellsetDoubleValue(Double value)Set the cell value as a double and set the value type to be "float".OdfTableCellsetDurationValue(Duration duration)Set the cell value as a time and set the value type to be "time" too.OdfTableCellsetFormatString(String formatStr)Set the format string of the cell.OdfTableCellsetFormula(String formula)Set a formula to the cell.OdfTableCellsetHorizontalAlignment(String horizontalAlignment)Set the horizontal alignment setting of this cell.OdfTableCellsetLocalDateTimeValue(LocalDateTime datetime)Set the cell value as a date and set the value type to be "date".OdfTableCellsetLocalDateValue(LocalDate date)Set the cell value as a date and set the value type to be "date".OdfTableCellsetLocalTimeValue(LocalTime time)Set the cell value as a time and set the value type to be "time" too.OdfTableCellsetPercentageValue(Double value)Set the cell value as a percentage value and set the value type as percentage too.OdfTableCellsetStringValue(String str)Set the cell value as a string, and set the value type to be string.OdfTableCellsetTextWrapped(boolean isTextWrapped)Set the wrap option of this cell.OdfTableCellsetTimeValue(Calendar time)Set the cell value as a time and set the value type to be "time" too.OdfTableCellsetValueType(String type)Set the value type of this cell.OdfTableCellsetVerticalAlignment(String verticalAlignment)Set the vertical alignment setting of this cell.
-
-
-
Method Detail
-
getInstance
public static OdfTableCell getInstance(TableTableCellElementBase cellElement)
Get theOdfTableCellinstance from theTableTableCellElementBaseinstance.Each
TableTableCellElementBaseinstance has a one-to-one relationship to the aOdfTableCellinstance.- Parameters:
cellElement- the cell element that need to get the correspondingOdfTableCellinstance- Returns:
- the
OdfTableCellinstance that represents a specified cell element
-
getHorizontalAlignment
public String getHorizontalAlignment()
Return the horizontal alignment setting of this cell.The returned value can be "center", "end", "justify", "left", "right", or "start". If no horizontal alignment is set, null will be returned.
- Returns:
- the horizontal alignment setting.
-
setHorizontalAlignment
public OdfTableCell setHorizontalAlignment(String horizontalAlignment)
Set the horizontal alignment setting of this cell.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.
- Parameters:
horizontalAlignment- the horizontal alignment setting.- Returns:
- this
OdfTableCellinstance
-
getVerticalAlignment
public String getVerticalAlignment()
Return the vertical alignment setting of this cell.The returned value can be "auto", "automatic", "baseline", "bottom", "middle", or "top".
- Returns:
- the vertical alignment setting of this cell.
-
setVerticalAlignment
public OdfTableCell setVerticalAlignment(String verticalAlignment)
Set the vertical alignment setting of this cell.The parameter can be "auto", "automatic", "baseline", "bottom", "middle", or "top". If argument is null, the explicit vertical alignment setting is removed.
- Parameters:
verticalAlignment- the vertical alignment setting.- Returns:
- this
OdfTableCellinstance
-
isTextWrapped
public boolean isTextWrapped()
Return the wrap option of this cell.- Returns:
- true if the cell content can be wrapped;
false if the cell content cannot be wrapped.
-
setTextWrapped
public OdfTableCell setTextWrapped(boolean isTextWrapped)
Set the wrap option of this cell.- Parameters:
isTextWrapped- whether the cell content can be wrapped or not- Returns:
- this
OdfTableCellinstance
-
getRowIndex
public int getRowIndex()
Get the index of the table row which contains this cell.- Returns:
- the index of the row containing this cell
-
getTable
public OdfTable getTable()
Get an instance of table feature which contains this cell.- Returns:
- the table containing this cell
-
getColumnIndex
public int getColumnIndex()
Get the index of the table column which contains this cell.- Returns:
- the index of the column containing this cell
-
getTableColumn
public OdfTableColumn getTableColumn()
Get the instance of table column feature which contains this cell.- Returns:
- the instance of table column feature which contains the cell.
-
getTableRow
public OdfTableRow getTableRow()
Get the instance of table row feature which contains this cell.- Returns:
- the instance of table row feature which contains the cell.
-
getOwnerTableCell
public OdfTableCell getOwnerTableCell()
Get the cell that covers this cell.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.
- Returns:
- the cell that covers the current cell
-
getOdfElement
public TableTableCellElementBase getOdfElement()
Get the instance ofTableTableCellElementBasewhich represents this cell.- Returns:
- the instance of
TableTableCellElementBase
-
getCurrencyCode
public String getCurrencyCode()
Return the currency code of this cell, for example, "USD", "EUR", "CNY", and etc.If the value type is not "currency", an IllegalArgumentException will be thrown.
- Returns:
- the currency code
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the value type is not "currency".
-
setCurrencyCode
public OdfTableCell setCurrencyCode(String currency)
Set the currency code of this cell, for example, "USD", "EUR", "CNY", and etc.- Parameters:
currency- the currency code that need to be set.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- If inputcurrencyis null, an IllegalArgumentException will be thrown.
-
setValueType
public OdfTableCell setValueType(String type)
Set the value type of this cell. The parameter can be "boolean", "currency", "date", "float", "percentage", "string" or "time".If the parameter
typeis not a valid cell type, an IllegalArgumentException will be thrown.- Parameters:
type- the type that need to be set If input type is null, an IllegalArgumentException will be thrown.- Returns:
- this
OdfTableCellinstance
-
getValueType
public String getValueType()
Get the value type of this cell. The returned value can be "boolean", "currency", "date", "float", "percentage", "string" or "time". If no value type is set, null will be returned.- Returns:
- the type of the cell
-
getDoubleValue
public Double getDoubleValue()
Get the double value of this cell as Double object.Throw IllegalArgumentException if the cell type is not "float".
- Returns:
- the double value of this cell as a Double object. If the cell value is empty, null will
be returned.
An IllegalArgumentException will be thrown if the cell type is not "float".
-
getCurrencyValue
public Double getCurrencyValue()
Get the currency value of this cell as Double object.Throw IllegalArgumentException if the cell type is not "currency".
- Returns:
- the currency value of this cell as a Double object. If the cell value is empty, null will be returned.
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the cell type is not "currency".
-
getCurrencySymbol
public String getCurrencySymbol()
Get the symbol of currency.- Returns:
- the currency symbol
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the value type is not "currency".
-
setCurrencyValue
public OdfTableCell setCurrencyValue(Double value, String currency)
Set the value and currency of the cell, and set the value type as "currency". Ifvalueis null, the cell value will be removed.- Parameters:
value- the value that will be setcurrency- the currency that will be set.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- If input currency is null, an IllegalArgumentException will be thrown.
-
getPercentageValue
public Double getPercentageValue()
Get the cell percentage value as Double object.Throw IllegalArgumentException if the cell type is not "percentage".
- Returns:
- the percentage value of this cell as a Double object. If the cell value is empty, null will be returned.
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the cell type is not "percentage".
-
setPercentageValue
public OdfTableCell setPercentageValue(Double value)
Set the cell value as a percentage value and set the value type as percentage too. Ifvalueis null, the cell value will be removed.- Parameters:
value- the value that will be set- Returns:
- this
OdfTableCellinstance
-
getDisplayText
public String getDisplayText()
Get the text displayed in this cell.- Returns:
- the text displayed in this cell
-
setDisplayText
public OdfTableCell setDisplayText(String content)
Set the text displayed in this cell.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.
- Parameters:
content- the displayed text. If content is null, it will display the empty string instead.- Returns:
- this
OdfTableCellinstance
-
setDisplayText
public OdfTableCell setDisplayText(String content, String stylename)
Set the text displayed in this cell, with a specified style name.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 are calculated and set by editor.
- Parameters:
content- the displayed text. If content is null, it will display the empty string instead.stylename- the style name. If stylename is null, the content will use the default paragraph style.- Returns:
- this
OdfTableCellinstance
-
setDoubleValue
public OdfTableCell setDoubleValue(Double value)
Set the cell value as a double and set the value type to be "float".- Parameters:
value- the double value that will be set. Ifvalueis null, the cell value will be removed.- Returns:
- this
OdfTableCellinstance
-
getBooleanValue
public Boolean getBooleanValue()
Get the cell boolean value as Boolean object.Throw IllegalArgumentException if the cell type is not "boolean".
- Returns:
- the Boolean value of cell. If the cell value is empty, null will be returned.
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the cell type is not "boolean".
-
setBooleanValue
public OdfTableCell setBooleanValue(Boolean value)
Set the cell value as a boolean and set the value type to be boolean. Ifvalueis null, the cell value will be removed.- Parameters:
value- the value of boolean type- Returns:
- this
OdfTableCellinstance
-
getDateValue
@Deprecated public Calendar getDateValue()
Deprecated.usegetLocalDateValue()instead.Get the cell date value as Calendar.- Returns:
- the Calendar value of cell
-
setDateValue
@Deprecated public OdfTableCell setDateValue(Calendar date)
Deprecated.usesetLocalDateValue(java.time.LocalDate)instead.Set the cell value as a date, and set the value type to be "date".This method sets only the date part of the passed value, the time part is ignored. Use #setDateTimeValue() to set both and time values from a Calendar instance.
- Parameters:
date- the value ofjava.util.Calendartype.- Returns:
- this
OdfTableCellinstance - See Also:
setDateTimeValue(Calendar)
-
setDateTimeValue
@Deprecated public OdfTableCell setDateTimeValue(Calendar date)
Deprecated.usesetLocalDateValue(java.time.LocalDate)instead.Set the cell value as a datetime, and set the value type to be "date".- Parameters:
date- the value ofjava.util.Calendartype.- Returns:
- this
OdfTableCellinstance
-
setStringValue
public OdfTableCell setStringValue(String str)
Set the cell value as a string, and set the value type to be string.- Parameters:
str- the value of string type. If input string is null, an empty string will be set.- Returns:
- this
OdfTableCellinstance
-
getStringValue
public String getStringValue()
Get the cell value as a string.If the cell type is not string, the display text will be returned.
- Returns:
- the string value of this cell, or the display text
-
getTimeValue
@Deprecated public Calendar getTimeValue()
Deprecated.usegetLocalTimeValue()instead.Get the cell value asjava.util.Calendar.Throw exception if the cell type is not "time".
- Returns:
- the Calendar value of cell
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the cell type is not time.
-
setTimeValue
public OdfTableCell setTimeValue(Calendar time)
Set the cell value as a time and set the value type to be "time" too.- Parameters:
time- the value ofjava.util.Calendartype.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- If input time is null, an IllegalArgumentException exception will be thrown.
-
getLocalDateValue
public LocalDate getLocalDateValue()
Get the cell date value asLocalDate.- Returns:
- the date value of cell
- Throws:
IllegalArgumentException- if the cell type is not "date".
-
getLocalDateTimeValue
public LocalDateTime getLocalDateTimeValue()
Get the cell date value asLocalDate.- Returns:
- the date value of cell
- Throws:
IllegalArgumentException- if the cell type is not "date".
-
setLocalDateValue
public OdfTableCell setLocalDateValue(LocalDate date)
Set the cell value as a date and set the value type to be "date".- Parameters:
date- the date as a LocalDate object.- Returns:
- this
OdfTableCellinstance
-
setLocalDateTimeValue
public OdfTableCell setLocalDateTimeValue(LocalDateTime datetime)
Set the cell value as a date and set the value type to be "date".- Parameters:
datetime- the date/time as a LocalDateTime object.- Returns:
- this
OdfTableCellinstance
-
getDurationValue
public Duration getDurationValue()
Get the cell value asDuration.- Returns:
- the time value of cell
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the cell type is not time.
-
getLocalTimeValue
public LocalTime getLocalTimeValue()
Get the cell value asLocalTime.- Returns:
- the time value of cell; null will be returned when the value is not a time-of-day (ie over 24 hours)
- Throws:
IllegalArgumentException- an IllegalArgumentException will be thrown if the cell type is not time.
-
setDurationValue
public OdfTableCell setDurationValue(Duration duration)
Set the cell value as a time and set the value type to be "time" too. UnlikesetLocalTimeValue(java.time.LocalTime)this method allows you to set the cell value to something over 24 hours- Parameters:
duration- the time as aDurationinstance.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- If input time is null, an IllegalArgumentException exception will be thrown.
-
setLocalTimeValue
public OdfTableCell setLocalTimeValue(LocalTime time)
Set the cell value as a time and set the value type to be "time" too.- Parameters:
time- the time as aLocalTimeinstance.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- If input time is null, an IllegalArgumentException exception will be thrown.
-
getCellBackgroundColor
public Color getCellBackgroundColor()
Get the background color of this cell.If no background color is set, default background color "#FFFFFF" will be returned.
- Returns:
- the background color of this cell
-
getCellBackgroundColorString
public String getCellBackgroundColorString()
Get the background color string of this cell.If no background color is set, default background color "#FFFFFF" will be returned.
- Returns:
- the background color of this cell
-
setCellBackgroundColor
public OdfTableCell setCellBackgroundColor(Color cellBackgroundColor)
Set the background color of this cell.- Parameters:
cellBackgroundColor- the background color that need to set. IfcellBackgroundColoris null, default background colorColor.WHITEwill be set.- Returns:
- this
OdfTableCellinstance
-
setCellBackgroundColor
public OdfTableCell setCellBackgroundColor(String cellBackgroundColor)
Set the background color of this cell using string. The string must be a valid argument for constructing.org.odftoolkit.odfdom.type.Color- Parameters:
cellBackgroundColor- the background color that need to set. If cellBackgroundColor is null, default background color #FFFFFF will be set.- Returns:
- this
OdfTableCellinstance - See Also:
Color
-
getStyleName
public String getStyleName()
Get the style name of this cell.- Returns:
- the name of the style
-
setFormula
public OdfTableCell setFormula(String formula)
Set a formula to the cell.Please note, the parameter
formulawill not be checked and interpreted; the cell value will not be calculated. It's just simply set as a formula attribute. See @table:formula- Parameters:
formula- the formula that need to be set.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- if formula is null, an IllegalArgumentException will be thrown.
-
getFormula
public String getFormula()
Get the formula string of the cell.- Returns:
- the formula representation of the cell
If the cell does not contain a formula, null will be returned.
-
setCurrencyFormat
public OdfTableCell setCurrencyFormat(String currencySymbol, String format)
Set the currency symbol and overall format of a currency cell.Please note the overall format includes the symbol character, for example: $#,##0.00.
This function only works for currency.
- Parameters:
currencySymbol- the currency symbolformat- overall format- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- if input currencySymbol or format is null, an IllegalArgumentException will be thrown.
-
setFormatString
public OdfTableCell setFormatString(String formatStr)
Set the format string of the cell.This function only works for float, date, time and percentage, otherwise an
IllegalArgumentExceptionwill be thrown.For value type float and percentage, the
formatStrmust follow the encoding rule of. For value type date and time, thejava.text.DecimalFormatformatStrmust follow the encoding rule of.java.text.SimpleDateFormatRefer to
to set the format of currency.setCurrencyFormatIf 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, anValueType 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 UnsupportedOperationExceptionwill be thrown.- Parameters:
formatStr- the cell need be formatted as this specified format string.- Returns:
- this
OdfTableCellinstance - Throws:
IllegalArgumentException- ifformatStris null or the cell value type is supported.UnsupportedOperationException- if the adaptive failed, when cell value type is not set.- See Also:
SimpleDateFormat,DecimalFormat
-
getCellStyleElement
protected OdfStyle getCellStyleElement()
-
getCellStyleElementForWrite
protected OdfStyle getCellStyleElementForWrite()
-
getFormatString
public String getFormatString()
Get the format string of the cell.- Returns:
- the format string of the cell
-
removeTextContent
public void removeTextContent()
Remove all the text content of cell.
-
removeContent
public void removeContent()
Remove all the content of the cell.
-
-