|
@@ -43,6 +43,18 @@ public class PoiService extends ServiceImpl<PatentPledgeMapper, PatentPledge> {
|
|
|
PoiVO poiVO =new PoiVO();
|
|
|
InputStream is = new FileInputStream("C:\\\\BaiduNetdiskDownload\\\\生成\\\\first.docx");
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
+ List<IBodyElement> bodyElements= doc.getBodyElements();
|
|
|
+ for(IBodyElement iBodyElement: bodyElements)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(iBodyElement.getElementType().equals(""))
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
List<XWPFParagraph> ps=doc.getParagraphs();
|
|
|
PoiVO.Pg title = new PoiVO.Pg();
|
|
|
List<PoiVO.Pg> pgs =new ArrayList<>();
|
|
@@ -169,17 +181,17 @@ String[] row =org.split("\\|\\|");
|
|
|
XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(doc, sectPr);
|
|
|
|
|
|
|
|
|
- this.createFooter(doc);
|
|
|
- //添加页脚
|
|
|
-// CTP ctpFooter = CTP.Factory.newInstance();
|
|
|
-// CTR ctrFooter = ctpFooter.addNewR();
|
|
|
-// CTText ctFooter = ctrFooter.addNewT();
|
|
|
-// String footerText = "ctpFooter";
|
|
|
-// ctFooter.setStringValue(footerText);
|
|
|
-// XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, doc);
|
|
|
-// XWPFParagraph[] parsFooter = new XWPFParagraph[1];
|
|
|
-// parsFooter[0] = footerParagraph;
|
|
|
-// policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
|
|
|
+// this.createDefaultFooter(doc,"宋体",8);
|
|
|
+ // 添加页脚,
|
|
|
+ CTP ctpFooter = CTP.Factory.newInstance();
|
|
|
+ CTR ctrFooter = ctpFooter.addNewR();
|
|
|
+ CTText ctFooter = ctrFooter.addNewT();
|
|
|
+ String footerText = "ctpFooter";
|
|
|
+ ctFooter.setStringValue(footerText);
|
|
|
+ XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, doc);
|
|
|
+ XWPFParagraph[] parsFooter = new XWPFParagraph[1];
|
|
|
+ parsFooter[0] = footerParagraph;
|
|
|
+ policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
|
|
|
doc.write(out);
|
|
|
out.close();
|
|
|
|
|
@@ -208,66 +220,52 @@ String[] row =org.split("\\|\\|");
|
|
|
|
|
|
|
|
|
//生成页脚
|
|
|
- public void createFooter(XWPFDocument doc){
|
|
|
- /*
|
|
|
- * 生成页脚段落
|
|
|
- * 给段落设置宽度为占满一行
|
|
|
- * */
|
|
|
- CTSectPr sectPr=doc.getDocument().getBody().addNewSectPr();
|
|
|
- XWPFHeaderFooterPolicy headerFooterPolicy=new XWPFHeaderFooterPolicy(doc,sectPr);
|
|
|
- try {
|
|
|
- XWPFFooter footer=headerFooterPolicy.createFooter(STHdrFtr.DEFAULT);
|
|
|
- XWPFParagraph paragraph = footer.getParagraphArray(0);
|
|
|
- paragraph.setAlignment(ParagraphAlignment.LEFT);
|
|
|
- paragraph.setVerticalAlignment(TextAlignment.CENTER);
|
|
|
- paragraph.setBorderTop(Borders.THICK);
|
|
|
- CTTabStop tabStop = paragraph.getCTP().getPPr().addNewTabs().addNewTab();
|
|
|
- tabStop.setVal(STTabJc.RIGHT);
|
|
|
- int twipsPerInch = 1440;
|
|
|
- tabStop.setPos(BigInteger.valueOf(6 * twipsPerInch));
|
|
|
- /*
|
|
|
- * 给段落创建元素
|
|
|
- * 设置元素字面为公司地址+公司电话
|
|
|
- * */
|
|
|
- XWPFRun run = paragraph.createRun();
|
|
|
- run.addTab();
|
|
|
- String s=run.getFontFamily();
|
|
|
- /*
|
|
|
- * 生成页码
|
|
|
- * 页码右对齐
|
|
|
- * */
|
|
|
- run = paragraph.createRun();
|
|
|
- run.setText("第");
|
|
|
- run = paragraph.createRun();
|
|
|
- CTFldChar fldChar = run.getCTR().addNewFldChar();
|
|
|
- fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));
|
|
|
- run = paragraph.createRun();
|
|
|
- CTText ctText = run.getCTR().addNewInstrText();
|
|
|
- ctText.setStringValue("PAGE \\* MERGEFORMAT");
|
|
|
- ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
|
|
|
- fldChar = run.getCTR().addNewFldChar();
|
|
|
- fldChar.setFldCharType(STFldCharType.Enum.forString("end"));
|
|
|
-
|
|
|
- run = paragraph.createRun();
|
|
|
- run.setText("页/共");
|
|
|
-
|
|
|
- run = paragraph.createRun();
|
|
|
- fldChar = run.getCTR().addNewFldChar();
|
|
|
- fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));
|
|
|
-
|
|
|
- run = paragraph.createRun();
|
|
|
- ctText = run.getCTR().addNewInstrText();
|
|
|
- ctText.setStringValue("NUMPAGES \\* MERGEFORMAT ");
|
|
|
- ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
|
|
|
-
|
|
|
- fldChar = run.getCTR().addNewFldChar();
|
|
|
- fldChar.setFldCharType(STFldCharType.Enum.forString("end"));
|
|
|
-
|
|
|
- run = paragraph.createRun();
|
|
|
- run.setText("页");;
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
+ public static void createDefaultFooter(final XWPFDocument document,String fontName,int fontSize) throws IOException {
|
|
|
+ CTP pageNo = CTP.Factory.newInstance();
|
|
|
+ XWPFParagraph footer = new XWPFParagraph(pageNo, document);
|
|
|
+ footer.createRun().setFontSize(2000);
|
|
|
+ CTPPr begin = pageNo.addNewPPr();
|
|
|
+ begin.addNewPStyle().setVal("style21");
|
|
|
+ begin.addNewJc().setVal(STJc.CENTER);
|
|
|
+ CTR pageBegin=pageNo.addNewR();
|
|
|
+ pageBegin.addNewRPr().addNewRFonts().setAscii(fontName);
|
|
|
+ pageBegin.addNewRPr().addNewRFonts().setCs(fontName);
|
|
|
+ pageBegin.addNewRPr().addNewRFonts().setEastAsia(fontName);
|
|
|
+ pageBegin.addNewRPr().addNewRFonts().setHAnsi(fontName);
|
|
|
+ pageBegin.addNewRPr().addNewSz().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ pageBegin.addNewRPr().addNewSzCs().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ pageBegin.addNewFldChar().setFldCharType(STFldCharType.BEGIN);
|
|
|
+ CTR page=pageNo.addNewR();
|
|
|
+ page.addNewRPr().addNewRFonts().setAscii(fontName);
|
|
|
+ page.addNewRPr().addNewRFonts().setCs(fontName);
|
|
|
+ page.addNewRPr().addNewRFonts().setEastAsia(fontName);
|
|
|
+ page.addNewRPr().addNewRFonts().setHAnsi(fontName);
|
|
|
+ page.addNewRPr().addNewSz().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ page.addNewRPr().addNewSzCs().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ page.addNewInstrText().setStringValue("PAGE \\* MERGEFORMAT");
|
|
|
+ CTR pageSep=pageNo.addNewR();
|
|
|
+ pageSep.addNewRPr().addNewRFonts().setAscii(fontName);
|
|
|
+ pageSep.addNewRPr().addNewRFonts().setCs(fontName);
|
|
|
+ pageSep.addNewRPr().addNewRFonts().setEastAsia(fontName);
|
|
|
+ pageSep.addNewRPr().addNewRFonts().setHAnsi(fontName);
|
|
|
+ pageSep.addNewRPr().addNewSz().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ pageSep.addNewRPr().addNewSzCs().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ pageSep.addNewFldChar().setFldCharType(STFldCharType.SEPARATE);
|
|
|
+ CTR end = pageNo.addNewR();
|
|
|
+ CTRPr endRPr = end.addNewRPr();
|
|
|
+ endRPr.addNewNoProof();
|
|
|
+ endRPr.addNewLang().setVal("zh-CN");
|
|
|
+ end.addNewRPr().addNewRFonts().setAscii(fontName);
|
|
|
+ end.addNewRPr().addNewRFonts().setCs(fontName);
|
|
|
+ end.addNewRPr().addNewRFonts().setEastAsia(fontName);
|
|
|
+ end.addNewRPr().addNewRFonts().setHAnsi(fontName);
|
|
|
+ end.addNewRPr().addNewSz().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ end.addNewRPr().addNewSzCs().setVal(BigInteger.valueOf(fontSize));
|
|
|
+ end.addNewFldChar().setFldCharType(STFldCharType.END);
|
|
|
+
|
|
|
+ CTSectPr sectPr = document.getDocument().getBody().isSetSectPr() ? document.getDocument().getBody().getSectPr() : document.getDocument().getBody().addNewSectPr();
|
|
|
+ XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
|
|
|
+ policy.createFooter(STHdrFtr.DEFAULT, new XWPFParagraph[] { footer });
|
|
|
}
|
|
|
|
|
|
// 目录添加行
|
|
@@ -379,4 +377,5 @@ String[] row =org.split("\\|\\|");
|
|
|
sz.setVal(new BigInteger("36"));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|