use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_例子2 method createNormalCell.
public void createNormalCell(ObjectFactory factory, Tr tr, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor, boolean isHMerger, String mergeVal) {
Tc tableCell = factory.createTc();
P p = factory.createP();
setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
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);
if (isHMerger) {
HMerge merge = new HMerge();
if (mergeVal != null) {
merge.setVal(mergeVal);
}
tcPr.setHMerge(merge);
} else {
VMerge merge = new VMerge();
if (mergeVal != null) {
merge.setVal(mergeVal);
}
tcPr.setVMerge(merge);
}
run.getContent().add(t);
p.getContent().add(run);
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);
tr.getContent().add(tableCell);
}
use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_例子2 method createFooterWithPageNr.
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;
}
use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_例子2 method getTextFtr.
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;
}
use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_例子2 method createHeaderBlankP.
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;
}
use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_例子2 method addPageBreak.
// 分页
public void addPageBreak(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, STBrType sTBrType) {
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
Br breakObj = new Br();
breakObj.setType(sTBrType);
P paragraph = factory.createP();
paragraph.getContent().add(breakObj);
documentPart.addObject(paragraph);
}
Aggregations