Methods Summary |
---|
private void | addToSSTIfRequired()
if (book != null) {
int index = book.addSSTString(string);
record.setSSTIndex(index);
//The act of adding the string to the SST record may have meant that
//a extsing string was returned for the index, so update our local version
string = book.getSSTString(index);
}
|
public void | applyFont(short fontIndex)Applies the specified font to the entire string.
applyFont(0, string.getCharCount(), fontIndex);
|
public void | applyFont(int startIndex, int endIndex, short fontIndex)Applies a font to the specified characters of a string.
if (startIndex > endIndex)
throw new IllegalArgumentException("Start index must be less than end index.");
if (startIndex < 0 || endIndex > length())
throw new IllegalArgumentException("Start and end index not in range.");
if (startIndex == endIndex)
return;
//Need to check what the font is currently, so we can reapply it after
//the range is completed
short currentFont = NO_FONT;
if (endIndex != length()) {
currentFont = this.getFontAtIndex(startIndex);
}
//Need to clear the current formatting between the startIndex and endIndex
string = cloneStringIfRequired();
Iterator formatting = string.formatIterator();
if (formatting != null) {
while (formatting.hasNext()) {
UnicodeString.FormatRun r = (UnicodeString.FormatRun)formatting.next();
if ((r.getCharacterPos() >= startIndex) && (r.getCharacterPos() < endIndex))
formatting.remove();
}
}
string.addFormatRun(new UnicodeString.FormatRun((short)startIndex, fontIndex));
if (endIndex != length())
string.addFormatRun(new UnicodeString.FormatRun((short)endIndex, currentFont));
addToSSTIfRequired();
|
public void | applyFont(int startIndex, int endIndex, org.apache.poi.hssf.usermodel.HSSFFont font)Applies a font to the specified characters of a string.
applyFont(startIndex, endIndex, font.getIndex());
|
public void | applyFont(org.apache.poi.hssf.usermodel.HSSFFont font)Sets the font of the entire string.
applyFont(0, string.getCharCount(), font);
|
public void | clearFormatting()Removes any formatting that may have been applied to the string.
string = cloneStringIfRequired();
string.clearFormatting();
addToSSTIfRequired();
|
private org.apache.poi.hssf.record.UnicodeString | cloneStringIfRequired()Called whenever the unicode string is modified. When it is modified
we need to create a new SST index, so that other LabelSSTRecords will not
be affected by changes tat we make to this string.
if (book == null)
return string;
UnicodeString s = (UnicodeString)string.clone();
return s;
|
public int | compareTo(java.lang.Object o)Compares one rich text string to another.
HSSFRichTextString r = (HSSFRichTextString)o;
return string.compareTo(r.string);
|
public boolean | equals(java.lang.Object o)
if (o instanceof HSSFRichTextString) {
return string.equals(((HSSFRichTextString)o).string);
}
return false;
|
public short | getFontAtIndex(int index)Returns the font in use at a particular index.
int size = string.getFormatRunCount();
UnicodeString.FormatRun currentRun = null;
for (int i=0;i<size;i++) {
UnicodeString.FormatRun r = string.getFormatRun(i);
if (r.getCharacterPos() > index)
break;
else currentRun = r;
}
if (currentRun == null)
return NO_FONT;
else return currentRun.getFontIndex();
|
public short | getFontOfFormattingRun(int index)Gets the font used in a particular formatting run.
UnicodeString.FormatRun r = string.getFormatRun(index);
return r.getFontIndex();
|
public int | getIndexOfFormattingRun(int index)The index within the string to which the specified formatting run applies.
UnicodeString.FormatRun r = string.getFormatRun(index);
return r.getCharacterPos();
|
public java.lang.String | getString()Returns the plain string representation.
return string.getString();
|
org.apache.poi.hssf.record.UnicodeString | getUnicodeString()Used internally by the HSSFCell to get the internal string value
return cloneStringIfRequired();
|
public int | length()
return string.getCharCount();
|
public int | numFormattingRuns()
return string.getFormatRunCount();
|
void | setUnicodeString(org.apache.poi.hssf.record.UnicodeString str)Used internally by the HSSFCell to set the internal string value
this.string = str;
|
void | setWorkbookReferences(org.apache.poi.hssf.model.Workbook book, org.apache.poi.hssf.record.LabelSSTRecord record)This must be called to setup the internal work book references whenever
a RichTextString is added to a cell
this.book = book;
this.record = record;
|
public java.lang.String | toString()
return string.toString();
|