diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-03-06 20:11:12 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-03-06 20:11:12 +0000 |
commit | 83a90487cb315e5ee798a11bcff3938dba8b67ac (patch) | |
tree | a21f1f5a51e90ca088a5f30d123b7230e9a08d2e | |
parent | ea2cc9e54c8ca02ac62785582c204df3355f9d2b (diff) | |
download | poi-83a90487cb315e5ee798a11bcff3938dba8b67ac.tar.gz poi-83a90487cb315e5ee798a11bcff3938dba8b67ac.zip |
[github-310] use XWPFRun
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898659 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java | 3 | ||||
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xwpf/model/TestMultiSectionHeaders.java | 43 |
2 files changed, 16 insertions, 30 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 24837cc540..ca4c95f76d 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -1456,7 +1456,8 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para * Get a <b>copy</b> of the currently used CTPPr, if none is used, return * a new instance. */ - private CTPPr getCTPPr() { + @Internal + public CTPPr getCTPPr() { return paragraph.getPPr() == null ? paragraph.addNewPPr() : paragraph.getPPr(); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/model/TestMultiSectionHeaders.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/model/TestMultiSectionHeaders.java index 6a0d4c2475..c9a4690b0c 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/model/TestMultiSectionHeaders.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/model/TestMultiSectionHeaders.java @@ -21,6 +21,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFFooter; import org.apache.poi.xwpf.usermodel.XWPFHeader; import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFRun; import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr; @@ -36,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestMultiSectionHeaders { @Test - void testAddHeadersForTwoDistinctSections() throws IOException { + void testAddHeadersForTwoDistinctSections() { String header1Text = "Header 1 Text"; String header2Text = "Header 2 Text"; @@ -46,14 +47,10 @@ public class TestMultiSectionHeaders { // Add first body/section paragraph XWPFParagraph par1 = doc.createParagraph(); - CTP ctp1 = par1.getCTP(); - ctp1.addNewR().addNewT().setStringValue("Text for first body paragraph"); + XWPFRun run1 = par1.createRun(); + run1.setText("Text for first body paragraph"); - CTPPr ppr1 = null; - if (!ctp1.isSetPPr()) { - ctp1.addNewPPr(); - } - ppr1 = ctp1.getPPr(); + CTPPr ppr1 = par1.getCTPPr(); CTSectPr sec1 = null; if (!ppr1.isSetSectPr()) { @@ -75,14 +72,10 @@ public class TestMultiSectionHeaders { // Add second body/section paragraph XWPFParagraph par2 = doc.createParagraph(); - CTP ctp2 = par2.getCTP(); - ctp2.addNewR().addNewT().setStringValue("Text for second body paragraph"); + XWPFRun run2 = par2.createRun(); + run2.setText("Text for second body paragraph"); - CTPPr ppr2 = null; - if (!ctp2.isSetPPr()) { - ctp2.addNewPPr(); - } - ppr2 = ctp2.getPPr(); + CTPPr ppr2 = par2.getCTPPr(); CTSectPr sec2 = null; if (!ppr2.isSetSectPr()) { @@ -133,14 +126,10 @@ public class TestMultiSectionHeaders { // Add first body/section paragraph XWPFParagraph par1 = doc.createParagraph(); - CTP ctp1 = par1.getCTP(); - ctp1.addNewR().addNewT().setStringValue("Text for first body paragraph"); + XWPFRun run1 = par1.createRun(); + run1.setText("Text for first body paragraph"); - CTPPr ppr1 = null; - if (!ctp1.isSetPPr()) { - ctp1.addNewPPr(); - } - ppr1 = ctp1.getPPr(); + CTPPr ppr1 = par1.getCTPPr(); CTSectPr sec1 = null; if (!ppr1.isSetSectPr()) { @@ -162,14 +151,10 @@ public class TestMultiSectionHeaders { // Add second body/section paragraph XWPFParagraph par2 = doc.createParagraph(); - CTP ctp2 = par2.getCTP(); - ctp2.addNewR().addNewT().setStringValue("Text for second body paragraph"); + XWPFRun run2 = par2.createRun(); + run2.setText("Text for second body paragraph"); - CTPPr ppr2 = null; - if (!ctp2.isSetPPr()) { - ctp2.addNewPPr(); - } - ppr2 = ctp2.getPPr(); + CTPPr ppr2 = par2.getCTPPr(); CTSectPr sec2 = null; if (!ppr2.isSetSectPr()) { |