public class XSSFRichTextString extends java.lang.Object implements RichTextString
Most strings in a workbook have formatting applied at the cell level, that is, the entire string in the cell has the same formatting applied. In these cases, the formatting for the cell is stored in the styles part, and the string for the cell can be shared across the workbook. The following code illustrates the example.
In the above example all three cells will use the same string cached on workbook level.cell1.setCellValue(new XSSFRichTextString("Apache POI")); cell2.setCellValue(new XSSFRichTextString("Apache POI")); cell3.setCellValue(new XSSFRichTextString("Apache POI"));
Some strings in the workbook may have formatting applied at a level that is more granular than the cell level. For instance, specific characters within the string may be bolded, have coloring, italicizing, etc. In these cases, the formatting is stored along with the text in the string table, and is treated as a unique entry in the workbook. The following xml and code snippet illustrate this.
XSSFRichTextString s1 = new XSSFRichTextString("Apache POI"); s1.applyFont(boldArial); cell1.setCellValue(s1); XSSFRichTextString s2 = new XSSFRichTextString("Apache POI"); s2.applyFont(italicCourier); cell2.setCellValue(s2);
Constructor and Description |
---|
XSSFRichTextString()
Create empty rich text string and initialize it with empty string
|
XSSFRichTextString(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst st)
Create a rich text string from the supplied XML bean
|
XSSFRichTextString(java.lang.String str)
Create a rich text string
|
Modifier and Type | Method and Description |
---|---|
void |
append(java.lang.String text)
Append new text to this text run
|
void |
append(java.lang.String text,
XSSFFont font)
Append new text to this text run and apply the specify font to it
|
void |
applyFont(Font font)
Sets the font of the entire string.
|
void |
applyFont(int startIndex,
int endIndex,
Font font)
Applies a font to the specified characters of a string.
|
void |
applyFont(int startIndex,
int endIndex,
short fontIndex)
Applies a font to the specified characters of a string.
|
void |
applyFont(short fontIndex)
Applies the specified font to the entire string.
|
void |
clearFormatting()
Removes any formatting that may have been applied to the string.
|
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst |
getCTRst()
Return the underlying xml bean
|
XSSFFont |
getFontAtIndex(int index)
Return a copy of the font in use at a particular index.
|
XSSFFont |
getFontOfFormattingRun(XSSFWorkbook book,
int index)
Gets a copy of the font used in a particular formatting run.
|
int |
getIndexOfFormattingRun(int index)
The index within the string to which the specified formatting run applies.
|
int |
getLengthOfFormattingRun(int index)
Returns the number of characters this format run covers.
|
java.lang.String |
getString()
Returns the plain string representation.
|
int |
length()
Returns the number of characters in this string.
|
int |
numFormattingRuns() |
protected static void |
preserveSpaces(org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring xs)
Add the xml:spaces="preserve" attribute if the string has leading or trailing spaces
|
void |
setString(java.lang.String s)
Removes any formatting and sets new string value
|
protected void |
setStylesTableReference(StylesTable tbl) |
protected static org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont |
toCTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt pr)
CTRPrElt --> CTFont adapter
|
java.lang.String |
toString()
Returns the plain string representation.
|
public XSSFRichTextString(java.lang.String str)
public XSSFRichTextString()
public XSSFRichTextString(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst st)
public void applyFont(int startIndex, int endIndex, short fontIndex)
applyFont
in interface RichTextString
startIndex
- The start index to apply the font to (inclusive)endIndex
- The end index to apply the font to (exclusive)fontIndex
- The font to use.public void applyFont(int startIndex, int endIndex, Font font)
applyFont
in interface RichTextString
startIndex
- The start index to apply the font to (inclusive)endIndex
- The end index to apply to font to (exclusive)font
- The index of the font to use.public void applyFont(Font font)
applyFont
in interface RichTextString
font
- The font to use.public void applyFont(short fontIndex)
applyFont
in interface RichTextString
fontIndex
- the font to apply.public void append(java.lang.String text, XSSFFont font)
text
- the text to appendfont
- the font to apply to the appended text or null
if no formatting is requiredpublic void append(java.lang.String text)
text
- the text to appendpublic void clearFormatting()
clearFormatting
in interface RichTextString
public int getIndexOfFormattingRun(int index)
getIndexOfFormattingRun
in interface RichTextString
index
- the index of the formatting runpublic int getLengthOfFormattingRun(int index)
index
- the index of the formatting runpublic java.lang.String getString()
getString
in interface RichTextString
public void setString(java.lang.String s)
s
- new string valuepublic java.lang.String toString()
toString
in class java.lang.Object
public int length()
length
in interface RichTextString
public int numFormattingRuns()
numFormattingRuns
in interface RichTextString
public XSSFFont getFontOfFormattingRun(XSSFWorkbook book, int index)
index
- the index of the formatting runpublic XSSFFont getFontAtIndex(int index)
index
- The index.@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst getCTRst()
protected void setStylesTableReference(StylesTable tbl)
protected static org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont toCTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt pr)
protected static void preserveSpaces(org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring xs)
xs
- the string to checkCopyright © 2005-2010 Potix Corporation. All Rights Reserved.