diff options
author | Yegor Kozlov <yegor@apache.org> | 2008-04-16 08:43:08 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2008-04-16 08:43:08 +0000 |
commit | 5319125c39204257b8f5ee22bc6a70ec94f107b3 (patch) | |
tree | 81651b06ef3f1a496361a14afd88a116ebf37c6d | |
parent | 3e3ed348cc702a6994832b8b155b8c87eabfbfe3 (diff) | |
download | poi-5319125c39204257b8f5ee22bc6a70ec94f107b3.tar.gz poi-5319125c39204257b8f5ee22bc6a70ec94f107b3.zip |
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
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java | 3 | ||||
-rwxr-xr-x | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java b/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java index 3a8fedd696..c9d4fbf111 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java @@ -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; } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java index f7ce61faf2..f836d4284e 100755 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java @@ -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));
+ }
+
}
|