[github-310] use XWPFRun

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898659 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-03-06 20:11:12 +00:00
parent ea2cc9e54c
commit 83a90487cb
2 changed files with 16 additions and 30 deletions

View File

@ -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();
}

View File

@ -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()) {