else if (text.length() > 0)
{
if (text.length() < 32768)
{
// There's rich text.
final RichTextString rtStr = creationHelper.createRichTextString(text);
for (int i = 0; i < buffer.size(); i++)
{
final RichTextFormat o = (RichTextFormat) buffer.get(i);
final int position = o.getPosition();
final HSSFFontWrapper font = o.getFont();
if (i == (buffer.size() - 1))
{
// Last element ..
rtStr.applyFont(position, text.length(), fontFactory.getExcelFont(font));
}
else
{
final RichTextFormat next = (RichTextFormat) buffer.get(i + 1);
rtStr.applyFont(position, next.getPosition(), fontFactory.getExcelFont(font));
}
}
return rtStr;
}
else
{
ExcelTextExtractor.logger.warn(
"Excel-Cells cannot contain text larger than 32.737 characters. Text will be clipped.");
final String realText = text.substring(0, 32767);
final RichTextString rtStr = creationHelper.createRichTextString(realText);
for (int i = 0; i < buffer.size(); i++)
{
final RichTextFormat o = (RichTextFormat) buffer.get(i);
final int position = o.getPosition();
if (position >= 32767)
{
break;
}
final HSSFFontWrapper font = o.getFont();
if (i == (buffer.size() - 1))
{
// Last element ..
final int endPosition = Math.min(32767, text.length());
rtStr.applyFont(position, endPosition, fontFactory.getExcelFont(font));
}
else
{
final RichTextFormat next = (RichTextFormat) buffer.get(i + 1);
final int endPosition = Math.min(32767, next.getPosition());
rtStr.applyFont(position, endPosition, fontFactory.getExcelFont(font));
}
}
return rtStr;
}
}