]> source.dussan.org Git - poi.git/commitdiff
#63624: setText in XWPFTableCell updates the xml and also updates the runs and iruns
authorAlain Béarez <abearez@apache.org>
Fri, 27 Mar 2020 03:13:31 +0000 (03:13 +0000)
committerAlain Béarez <abearez@apache.org>
Fri, 27 Mar 2020 03:13:31 +0000 (03:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1875744 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java

index 745f5b2879d0b7a22f5c7240df8e69066c6e96a3..b5bb92ba32773c509d1559f991052789a19b1ebd 100644 (file)
@@ -427,8 +427,7 @@ public class XWPFTableCell implements IBody, ICell {
     }
 
     public void setText(String text) {
-        CTP ctP = (ctTc.sizeOfPArray() == 0) ? ctTc.addNewP() : ctTc.getPArray(0);
-        XWPFParagraph par = new XWPFParagraph(ctP, this);
+        XWPFParagraph par = (paragraphs.size() == 0) ? addParagraph() : paragraphs.get(0);
         par.createRun().setText(text);
     }
 
index df3fa2a7a4ec68a66473809cff9c14d225c7cde5..47076649f9c7565bb0aec7ebab28140a2379daa1 100644 (file)
@@ -149,4 +149,18 @@ public class TestXWPFTableCell {
         assertEquals(2500, cell.getWidth());
         doc.close();
     }
+
+    @Test
+    public void testBug63624() throws Exception {
+        XWPFDocument doc = new XWPFDocument();
+        XWPFTable table = doc.createTable(1, 1);
+        XWPFTableRow row = table.getRow(0);
+        XWPFTableCell cell = row.getCell(0);
+
+        String expected = "this must not be empty";
+        cell.setText(expected);
+        String actual = cell.getText();
+        assertEquals(expected, actual);
+        doc.close();
+    }
 }