|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.poi.hssf.usermodel.HSSFRichTextString
public final class HSSFRichTextString
Rich text unicode string. These strings can have fonts applied to arbitary parts of the string.
Note, that in certain cases creating too many HSSFRichTextString cells may cause Excel 2003 and lower to crash when changing the color of the cells and then saving the Excel file. Compare two snippets that produce equivalent output:
andHSSFCell hssfCell = row.createCell(idx); //rich text consists of two runs HSSFRichTextString richString = new HSSFRichTextString( "Hello, World!" ); richString.applyFont( 0, 6, font1 ); richString.applyFont( 6, 13, font2 ); hssfCell.setCellValue( richString );
//create a cell style and assign the first font to it HSSFCellStyle style = workbook.createCellStyle(); style.setFont(font1); HSSFCell hssfCell = row.createCell(idx); hssfCell.setCellStyle(style); //rich text consists of one run overriding the cell style HSSFRichTextString richString = new HSSFRichTextString( "Hello, World!" ); richString.applyFont( 6, 13, font2 ); hssfCell.setCellValue( richString );
Excel always uses the latter approach: for a reach text containing N runs Excel saves the font of the first run in the cell's style and subsequent N-1 runs override this font.
For more information regarding this behavior please consult Bugzilla 47543: https://issues.apache.org/bugzilla/show_bug.cgi?id=47543
| Field Summary | |
|---|---|
static short |
NO_FONT
Place holder for indicating that NO_FONT has been applied here |
| Constructor Summary | |
|---|---|
HSSFRichTextString()
|
|
HSSFRichTextString(java.lang.String string)
|
|
| Method Summary | |
|---|---|
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. |
int |
compareTo(HSSFRichTextString r)
Compares one rich text string to another. |
boolean |
equals(java.lang.Object o)
|
short |
getFontAtIndex(int index)
Returns the font in use at a particular index. |
short |
getFontOfFormattingRun(int index)
Gets the font used in a particular formatting run. |
int |
getIndexOfFormattingRun(int index)
The index within the string to which the specified formatting run applies. |
java.lang.String |
getString()
Returns the plain string representation. |
int |
hashCode()
|
int |
length()
|
int |
numFormattingRuns()
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final short NO_FONT
| Constructor Detail |
|---|
public HSSFRichTextString()
public HSSFRichTextString(java.lang.String string)
| Method Detail |
|---|
public void applyFont(int startIndex,
int endIndex,
short fontIndex)
applyFont in interface RichTextStringstartIndex - 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 RichTextStringstartIndex - 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 RichTextStringfont - The font to use.public void clearFormatting()
clearFormatting in interface RichTextStringpublic java.lang.String getString()
getString in interface RichTextStringpublic int length()
length in interface RichTextStringpublic short getFontAtIndex(int index)
index - The index.
public int numFormattingRuns()
numFormattingRuns in interface RichTextStringNO_FONTpublic int getIndexOfFormattingRun(int index)
getIndexOfFormattingRun in interface RichTextStringindex - the index of the formatting run
public short getFontOfFormattingRun(int index)
index - the index of the formatting run
public int compareTo(HSSFRichTextString r)
compareTo in interface java.lang.Comparable<HSSFRichTextString>public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic void applyFont(short fontIndex)
applyFont in interface RichTextStringfontIndex - the font to apply.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||