Rich text in HSSFTextbox must have at least one format run. Make sure it is so and apply th default fopnt if no formats were applied.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@648623 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9b786497f8
commit
c52a8b10af
@ -81,6 +81,9 @@ public class HSSFTextbox
|
||||
*/
|
||||
public void setString( HSSFRichTextString string )
|
||||
{
|
||||
//if font is not set we must set the default one
|
||||
if (string.numFormattingRuns() == 0) string.applyFont((short)0);
|
||||
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
|
@ -49,4 +49,23 @@ public final class TestHSSFTextbox extends TestCase{
|
||||
assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel requires at least one format run in HSSFTextbox.
|
||||
* When inserting text make sure that if font is not set we must set the default one.
|
||||
*/
|
||||
public void testSetDeafultTextFormat() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||
|
||||
HSSFTextbox textbox1 = patriarch.createTextbox(new HSSFClientAnchor(0,0,0,0,(short)1,1,(short)3,3));
|
||||
HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!");
|
||||
assertEquals(0, rt1.numFormattingRuns());
|
||||
textbox1.setString(rt1);
|
||||
|
||||
HSSFRichTextString rt2 = textbox1.getString();
|
||||
assertEquals(1, rt2.numFormattingRuns());
|
||||
assertEquals(HSSFRichTextString.NO_FONT, rt2.getFontOfFormattingRun(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user