From 74b2ae268f818237104130723dd8935d8600f2e2 Mon Sep 17 00:00:00 2001 From: Tony Qu Date: Sat, 21 Feb 2026 01:58:32 +0800 Subject: [PATCH 1/3] POI Bug Github 170 - XWPFTableCell does not process bodyElements when handle paragraph https://github.com/apache/poi/pull/170 --- ooxml/XWPF/Usermodel/XWPFTableCell.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ooxml/XWPF/Usermodel/XWPFTableCell.cs b/ooxml/XWPF/Usermodel/XWPFTableCell.cs index 27aa952ab..674e35f03 100644 --- a/ooxml/XWPF/Usermodel/XWPFTableCell.cs +++ b/ooxml/XWPF/Usermodel/XWPFTableCell.cs @@ -155,6 +155,7 @@ public XWPFParagraph AddParagraph() public void AddParagraph(XWPFParagraph p) { paragraphs.Add(p); + bodyElements.Add(p); } /** @@ -163,8 +164,10 @@ public void AddParagraph(XWPFParagraph p) */ public void RemoveParagraph(int pos) { + XWPFParagraph removedParagraph = paragraphs[pos]; paragraphs.RemoveAt(pos); ctTc.RemoveP(pos); + bodyElements.Remove(removedParagraph); } /** From 416550d1a766906d89260e368a1d89bd0a9dfaef Mon Sep 17 00:00:00 2001 From: Tony Qu Date: Sun, 22 Feb 2026 16:20:46 +0800 Subject: [PATCH 2/3] fix compilation error --- main/HPSF/SummaryInformation.cs | 2 +- main/SS/UserModel/ConditionalFormattingRule.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/HPSF/SummaryInformation.cs b/main/HPSF/SummaryInformation.cs index d9b0a921e..f3c629cbf 100644 --- a/main/HPSF/SummaryInformation.cs +++ b/main/HPSF/SummaryInformation.cs @@ -66,7 +66,7 @@ public SummaryInformation(PropertySet ps) : base(ps) /// /// - /// Creates a instance from an instance from an InputStream in the Horrible Property Set Format. /// /// /// The constructor reads the first few bytes from the stream diff --git a/main/SS/UserModel/ConditionalFormattingRule.cs b/main/SS/UserModel/ConditionalFormattingRule.cs index c524df220..d1e6e9e26 100644 --- a/main/SS/UserModel/ConditionalFormattingRule.cs +++ b/main/SS/UserModel/ConditionalFormattingRule.cs @@ -144,7 +144,7 @@ public interface IConditionalFormattingRule : IDifferentialStyleProvider /// true if conditional formatting rule processing stops when this one is true, false if not /// /// - /// Microsoft Excel help + /// Microsoft Excel help bool StopIfTrue { get; } /// From 75abad78169e7c20c29108a53c31921eb6940209 Mon Sep 17 00:00:00 2001 From: Tony Qu Date: Sun, 22 Feb 2026 21:13:19 +0800 Subject: [PATCH 3/3] Add tests from POI Bug Github-170 --- .../ooxml/XWPF/UserModel/TestXWPFTableCell.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/testcases/ooxml/XWPF/UserModel/TestXWPFTableCell.cs b/testcases/ooxml/XWPF/UserModel/TestXWPFTableCell.cs index a19f70322..726186520 100644 --- a/testcases/ooxml/XWPF/UserModel/TestXWPFTableCell.cs +++ b/testcases/ooxml/XWPF/UserModel/TestXWPFTableCell.cs @@ -132,5 +132,59 @@ public void TestCellVerticalAlignShouldNotThrowNPE() } } } + + [Test] + public void TestAddParagraph() + { + using (XWPFDocument doc = new XWPFDocument()) + { + XWPFTable table = doc.CreateTable(); + XWPFTableRow tr = table.CreateRow(); + XWPFTableCell cell = tr.AddNewTableCell(); + + // cell have at least one paragraph by default + ClassicAssert.AreEqual(1, cell.Paragraphs.Count); + ClassicAssert.AreEqual(1, cell.BodyElements.Count); + ClassicAssert.AreEqual(cell.GetParagraphArray(0), cell.BodyElements[0]); + + XWPFParagraph p = cell.AddParagraph(); + ClassicAssert.AreEqual(2, cell.Paragraphs.Count); + ClassicAssert.AreEqual(2, cell.BodyElements.Count); + ClassicAssert.AreEqual(p, cell.GetParagraphArray(1)); + ClassicAssert.AreEqual(cell.GetParagraphArray(1), cell.BodyElements[1]); + } + } + + [Test] + public void TestRemoveParagraph() + { + using (XWPFDocument doc = new XWPFDocument()) + { + XWPFTable table = doc.CreateTable(); + XWPFTableRow tr = table.CreateRow(); + XWPFTableCell cell = tr.AddNewTableCell(); + + // cell have at least one paragraph by default + XWPFParagraph p0 = cell.GetParagraphArray(0); + XWPFParagraph p1 = cell.AddParagraph(); + cell.AddParagraph(); + + // remove 3rd + cell.RemoveParagraph(2); + ClassicAssert.AreEqual(2, cell.Paragraphs.Count); + ClassicAssert.AreEqual(2, cell.BodyElements.Count); + ClassicAssert.AreEqual(p0, cell.GetParagraphArray(0)); + ClassicAssert.AreEqual(p1, cell.GetParagraphArray(1)); + ClassicAssert.AreEqual(p0, cell.BodyElements[0]); + ClassicAssert.AreEqual(p1, cell.BodyElements[1]); + + // remove 2nd + cell.RemoveParagraph(1); + ClassicAssert.AreEqual(1, cell.Paragraphs.Count); + ClassicAssert.AreEqual(1, cell.BodyElements.Count); + ClassicAssert.AreEqual(p0, cell.GetParagraphArray(0)); + ClassicAssert.AreEqual(p0, cell.BodyElements[0]); + } + } } }