Java Code Examples for org.docx4j.wml.P#setPPr()
The following examples show how to use
org.docx4j.wml.P#setPPr() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void setParagraphSpacing(ObjectFactory factory, P p, JcEnumeration jcEnumeration,String before,String after) { PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); Spacing spacing=new Spacing(); spacing.setBefore(new BigInteger(before)); spacing.setAfter(new BigInteger(after)); spacing.setLineRule(STLineSpacingRule.AUTO); pPr.setSpacing(spacing); p.setPPr(pPr); }
Example 2
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P footerP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); footerP.getContent().add(run); PPr pPr = footerP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); footerP.setPPr(pPr); ftr.getContent().add(footerP); return ftr; }
Example 3
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P footerP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); footerP.getContent().add(run); PPr pPr = footerP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); footerP.setPPr(pPr); ftr.getContent().add(footerP); return ftr; }
Example 4
Source File: FOPAreaTreeHelper.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
private static P createFillerP() { org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory(); P p = wmlObjectFactory.createP(); // Create object for pPr PPr ppr = wmlObjectFactory.createPPr(); p.setPPr(ppr); // Create object for rPr ParaRPr pararpr = wmlObjectFactory.createParaRPr(); // Create object for spacing PPrBase.Spacing pprbasespacing = wmlObjectFactory.createPPrBaseSpacing(); ppr.setSpacing(pprbasespacing); pprbasespacing.setBefore( BigInteger.valueOf( 800) ); pprbasespacing.setAfter( BigInteger.valueOf( 800) ); // Create object for r R r = wmlObjectFactory.createR(); p.getContent().add( r); // Create object for rPr RPr rpr = wmlObjectFactory.createRPr(); r.setRPr(rpr); // Create object for sz HpsMeasure hpsmeasure3 = wmlObjectFactory.createHpsMeasure(); rpr.setSz(hpsmeasure3); hpsmeasure3.setVal( BigInteger.valueOf( 96) ); // Create object for t (wrapped in JAXBElement) Text text = wmlObjectFactory.createText(); JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text); r.getContent().add( textWrapped); text.setValue( "BODY CONTENT"); return p; }
Example 5
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public void setParagraphAlign(ObjectFactory factory, P p, JcEnumeration jcEnumeration) { PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); p.setPPr(pPr); }
Example 6
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public void createParagraghLine(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory,P p,CTBorder topBorder,CTBorder bottomBorder,CTBorder leftBorder,CTBorder rightBorder){ PPr ppr=new PPr(); PBdr pBdr=new PBdr(); pBdr.setTop(topBorder); pBdr.setBottom(bottomBorder); pBdr.setLeft(leftBorder); pBdr.setRight(rightBorder); ppr.setPBdr(pBdr); p.setPPr(ppr); }
Example 7
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P createHeaderBlankP(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, String underLineSz, JcEnumeration jcEnumeration) throws Exception { P p = factory.createP(); R run = factory.createR(); p.getContent().add(run); PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); PBdr pBdr = pPr.getPBdr(); if (pBdr == null) { pBdr = factory.createPPrBasePBdr(); } CTBorder value = new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger(underLineSz)); pBdr.setBetween(value); pPr.setPBdr(pBdr); p.setPPr(pPr); setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); return p; }
Example 8
Source File: Docx4j_创建表格_S5_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
public void setHorizontalAlignment(P paragraph, JcEnumeration hAlign) { if (hAlign != null) { PPr pprop = new PPr(); Jc align = new Jc(); align.setVal(hAlign); pprop.setJc(align); paragraph.setPPr(pprop); } }
Example 9
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P createImageParagraph(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P p, String fileName, String content, byte[] bytes, JcEnumeration jcEnumeration) throws Exception { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline(fileName, "这是图片", 1, 2, false); Text text = factory.createText(); text.setValue(content); text.setSpace("preserve"); R run = factory.createR(); p.getContent().add(run); run.getContent().add(text); Drawing drawing = factory.createDrawing(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); p.setPPr(pPr); setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); return p; }
Example 10
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public void setParagraphInd(ObjectFactory factory, P p, JcEnumeration jcEnumeration, boolean firstLine, String firstLineValue, boolean hangLine, String hangValue) { PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); Ind ind = pPr.getInd(); if (ind == null) { ind = new Ind(); } if (firstLine) { if (firstLineValue != null) { ind.setFirstLineChars(new BigInteger(firstLineValue)); } } if (hangLine) { if (hangValue != null) { ind.setHangingChars(new BigInteger(hangValue)); } } pPr.setInd(ind); p.setPPr(pPr); }
Example 11
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, Part sourcePart, byte[] bytes, String filenameHint, String altText, int id1, int id2, JcEnumeration jcEnumeration) throws Exception { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, sourcePart, bytes); Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, false); P p = factory.createP(); R run = factory.createR(); p.getContent().add(run); Drawing drawing = factory.createDrawing(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); p.setPPr(pPr); PBdr pBdr=pPr.getPBdr(); if(pBdr==null){ pBdr=factory.createPPrBasePBdr(); } CTBorder value=new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger("3")); pBdr.setBetween(value); pPr.setPBdr(pBdr); setParagraphSpacing(factory, p, jcEnumeration, "0", "0"); return p; }
Example 12
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P createHeaderBlankP(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, JcEnumeration jcEnumeration) throws Exception{ P p = factory.createP(); R run = factory.createR(); p.getContent().add(run); PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); PBdr pBdr=pPr.getPBdr(); if(pBdr==null){ pBdr=factory.createPPrBasePBdr(); } CTBorder value=new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger("3")); pBdr.setBetween(value); pPr.setPBdr(pBdr); p.setPPr(pPr); setParagraphSpacing(factory, p, jcEnumeration, "0", "0"); return p; }
Example 13
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P footerP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); footerP.getContent().add(run); PPr pPr = footerP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); footerP.setPPr(pPr); setParagraphSpacing(factory, footerP, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); if (isUnderLine) { PBdr pBdr = pPr.getPBdr(); if (pBdr == null) { pBdr = factory.createPPrBasePBdr(); } CTBorder value = new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger(underLineSz)); pBdr.setBetween(value); pPr.setPBdr(pBdr); footerP.setPPr(pPr); } ftr.getContent().add(footerP); if (isUnderLine) { ftr.getContent().add( createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration)); } return ftr; }
Example 14
Source File: DocxBuilder.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public P createIt() { org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory(); P p = wmlObjectFactory.createP(); // Create object for pPr PPr ppr = wmlObjectFactory.createPPr(); p.setPPr(ppr); // Create object for rPr ParaRPr pararpr = wmlObjectFactory.createParaRPr(); ppr.setRPr(pararpr); // Create object for u U u = wmlObjectFactory.createU(); pararpr.setU(u); u.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE); // Create object for lang CTLanguage language = wmlObjectFactory.createCTLanguage(); pararpr.setLang(language); language.setVal( "en-AU"); // Create object for jc Jc jc = wmlObjectFactory.createJc(); ppr.setJc(jc); jc.setVal(org.docx4j.wml.JcEnumeration.CENTER); // Create object for r R r = wmlObjectFactory.createR(); p.getContent().add( r); // Create object for rPr RPr rpr = wmlObjectFactory.createRPr(); r.setRPr(rpr); // Create object for u U u2 = wmlObjectFactory.createU(); rpr.setU(u2); u2.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE); // Create object for lang CTLanguage language2 = wmlObjectFactory.createCTLanguage(); rpr.setLang(language2); language2.setVal( "en-AU"); // Create object for t (wrapped in JAXBElement) Text text = wmlObjectFactory.createText(); JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text); r.getContent().add( textWrapped); text.setValue( "Underlined and centred"); return p; }
Example 15
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public Ftr createFooterWithPageNr( WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P paragraph = factory.createP(); RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA, false, false, false, false); R run = factory.createR(); run.setRPr(fontRPr); paragraph.getContent().add(run); addPageTextField(factory, paragraph, "第"); addFieldBegin(factory, paragraph); addPageNumberField(factory, paragraph); addFieldEnd(factory, paragraph); addPageTextField(factory, paragraph, "页"); addPageTextField(factory, paragraph, " 总共"); addFieldBegin(factory, paragraph); addTotalPageNumberField(factory, paragraph); addFieldEnd(factory, paragraph); addPageTextField(factory, paragraph, "页"); setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); PPr pPr = paragraph.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); if (isUnderLine) { PBdr pBdr = pPr.getPBdr(); if (pBdr == null) { pBdr = factory.createPPrBasePBdr(); } CTBorder value = new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger(underLineSz)); pBdr.setBetween(value); pPr.setPBdr(pBdr); paragraph.setPPr(pPr); } ftr.getContent().add(paragraph); if (isUnderLine) { ftr.getContent().add( createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration)); } return ftr; }
Example 16
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public void createHyperlink(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory,P paragraph, String url, String value, String fontName, String fontSize,JcEnumeration jcEnumeration) throws Exception { org.docx4j.relationships.ObjectFactory reFactory = new org.docx4j.relationships.ObjectFactory(); org.docx4j.relationships.Relationship rel = reFactory .createRelationship(); rel.setType(Namespaces.HYPERLINK); rel.setTarget(url); rel.setTargetMode("External"); t.getRelationshipsPart().addRelationship(rel); StringBuffer sb = new StringBuffer(); // addRelationship sets the rel's @Id sb.append("<w:hyperlink r:id=\""); sb.append(rel.getId()); sb.append("\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" "); sb.append("xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" >"); sb.append("<w:r><w:rPr><w:rStyle w:val=\"Hyperlink\" />"); sb.append("<w:rFonts w:ascii=\""); sb.append(fontName); sb.append("\" w:hAnsi=\""); sb.append(fontName); sb.append("\" w:eastAsia=\""); sb.append(fontName); sb.append("\" w:hint=\"eastAsia\"/>"); sb.append("<w:sz w:val=\""); sb.append(fontSize); sb.append("\"/><w:szCs w:val=\""); sb.append(fontSize); sb.append("\"/></w:rPr><w:t>"); sb.append(value); sb.append("</w:t></w:r></w:hyperlink>"); Hyperlink link = (Hyperlink) XmlUtils.unmarshalString(sb.toString()); paragraph.getContent().add(link); setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); PPr ppr = paragraph.getPPr(); if (ppr == null) { ppr = factory.createPPr(); } RFonts fonts = new RFonts(); fonts.setAscii("微软雅黑"); fonts.setHAnsi("微软雅黑"); fonts.setEastAsia("微软雅黑"); fonts.setHint(STHint.EAST_ASIA); ParaRPr rpr = new ParaRPr(); rpr.setRFonts(fonts); ppr.setRPr(rpr); paragraph.setPPr(ppr); }
Example 17
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
/** * @param jcEnumeration * 对齐方式 * @param isSpace * 是否设置段前段后值 * @param before * 段前磅数 * @param after * 段后磅数 * @param beforeLines * 段前行数 * @param afterLines * 段后行数 * @param isLine * 是否设置行距 * @param lineValue * 行距值 * @param sTLineSpacingRule * 自动auto 固定exact 最小 atLeast */ public void setParagraphSpacing(ObjectFactory factory, P p, JcEnumeration jcEnumeration, boolean isSpace, String before, String after, String beforeLines, String afterLines, boolean isLine, String lineValue, STLineSpacingRule sTLineSpacingRule) { PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); Spacing spacing = new Spacing(); if (isSpace) { if (before != null) { // 段前磅数 spacing.setBefore(new BigInteger(before)); } if (after != null) { // 段后磅数 spacing.setAfter(new BigInteger(after)); } if (beforeLines != null) { // 段前行数 spacing.setBeforeLines(new BigInteger(beforeLines)); } if (afterLines != null) { // 段后行数 spacing.setAfterLines(new BigInteger(afterLines)); } } if (isLine) { if (lineValue != null) { spacing.setLine(new BigInteger(lineValue)); } spacing.setLineRule(sTLineSpacingRule); } pPr.setSpacing(spacing); p.setPPr(pPr); }
Example 18
Source File: XHTMLtoDocxImageHandler.java From docx-html-editor with GNU Affero General Public License v3.0 | 4 votes |
@Override public void addImage(Docx4jUserAgent docx4jUserAgent, WordprocessingMLPackage wordMLPackage, P targetP, Element e, Long cx, Long cy) { // This design doesn't allow the user to resize the image in the editor, // since we don't trust it to allow that to be done accurately String id = e.getAttribute("id"); if (id==null ) { log.debug("no id on image with src " + e.getAttribute("src") ); // System.out.println("no id on image with src " + e.getAttribute("src") ); } else { log.debug("processing image with id " + id); // System.out.println("processing image with id " + id); Object o = wordMLPackage.getUserData(id); if (o==null) { log.debug("no UserData on image with id " + id); // System.out.println("no UserData on image with id " + id); } else { if (o instanceof P) { P pStored = (P)o; // replace p contents targetP.setPPr(pStored.getPPr()); targetP.getContent().clear(); targetP.getContent().addAll(pStored.getContent()); return; } else { log.debug("adding " + o.getClass().getName() ); // Just add the contents targetP.getContent().add(o); return; } } } super.addImage(docx4jUserAgent, wordMLPackage, targetP, e, cx, cy); }
Example 19
Source File: Docx4j_Helper.java From docx4j-template with Apache License 2.0 | 4 votes |
public void testDocx4jSetPageSize() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); String titleStr="静夜思 李白"; String str="床前明月光,疑似地上霜。"; String str2="举头望明月,低头思故乡。"; P p = Docx4j_Helper.factory.createP(); String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>"; RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr); setParagraphContent(p, rpr,titleStr); mdp.addObject(p); p = Docx4j_Helper.factory.createP(); setParagraphContent(p, rpr,str); mdp.addObject(p); p = Docx4j_Helper.factory.createP(); PPr pPr=Docx4j_Helper.factory.createPPr(); //设置文字方向 SectPr sectPr = Docx4j_Helper.factory.createSectPr(); TextDirection textDirect = Docx4j_Helper.factory.createTextDirection(); //文字方向:垂直方向从右往左 textDirect.setVal("tbRl"); sectPr.setTextDirection(textDirect); Type sectType = Docx4j_Helper.factory.createSectPrType(); //下一页 sectType.setVal("nextPage"); sectPr.setType(sectType); //设置页面大小 PgSz pgSz = Docx4j_Helper.factory.createSectPrPgSz(); pgSz.setW(new BigInteger("8335")); pgSz.setH(new BigInteger("11850")); sectPr.setPgSz(pgSz); pPr.setSectPr(sectPr); p.setPPr(pPr); setParagraphContent(p, rpr,str2); mdp.addObject(p); p = createParagraphWithHAlign(); setParagraphContent(p, rpr,titleStr); mdp.addObject(p); p = createParagraphWithHAlign(); setParagraphContent(p, rpr,str); mdp.addObject(p); p = createParagraphWithHAlign(); setParagraphContent(p, rpr,str2); mdp.addObject(p); // Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath); }
Example 20
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) { Tc tableCell = factory.createTc(); P p = factory.createP(); setParagraphAlign(factory, p, jcEnumeration); Text t = factory.createText(); t.setValue(content); R run = factory.createR(); // 设置表格内容字体样式 run.setRPr(rpr); TcPr tcPr = tableCell.getTcPr(); if (tcPr == null) { tcPr = factory.createTcPr(); } CTVerticalJc valign = factory.createCTVerticalJc(); valign.setVal(STVerticalJc.CENTER); tcPr.setVAlign(valign); run.getContent().add(t); p.getContent().add(run); PPr ppr=p.getPPr(); if(ppr==null){ ppr=factory.createPPr(); } //设置段后距离 Spacing spacing=new Spacing(); spacing.setAfter(new BigInteger("0")); spacing.setLineRule(STLineSpacingRule.AUTO); ppr.setSpacing(spacing); p.setPPr(ppr); tableCell.getContent().add(p); if (hasBgColor) { CTShd shd = tcPr.getShd(); if (shd == null) { shd = factory.createCTShd(); } shd.setColor("auto"); shd.setFill(backgroudColor); tcPr.setShd(shd); tableCell.setTcPr(tcPr); } tableRow.getContent().add(tableCell); }