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;
public class TestMultiSectionHeaders {
@Test
- void testAddHeadersForTwoDistinctSections() throws IOException {
+ void testAddHeadersForTwoDistinctSections() {
String header1Text = "Header 1 Text";
String header2Text = "Header 2 Text";
// 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()) {
// 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()) {
// 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()) {
// 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()) {