use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_简单例子2 method addTableCell.
// 新增单元格
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);
}
use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4J_简单例子2 method addParagraphTest.
public void addParagraphTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
RPr titleRPr = getRPr(factory, "黑体", "000000", "30", STHint.EAST_ASIA, true, false, false, false);
RPr boldRPr = getRPr(factory, "宋体", "000000", "24", STHint.EAST_ASIA, true, false, false, false);
RPr fontRPr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
P paragraph = factory.createP();
setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
Text txt = factory.createText();
txt.setValue("七年级上册Unit2 This is just a test. sectionA测试卷答题卡");
R run = factory.createR();
run.getContent().add(txt);
run.setRPr(titleRPr);
paragraph.getContent().add(run);
t.addObject(paragraph);
paragraph = factory.createP();
setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
txt = factory.createText();
txt.setValue("班级:________ 姓名:________");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("一、单选题");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(boldRPr);
paragraph.getContent().add(run);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("1.下列有关仪器用途的说法错误的是( )");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("A.烧杯用于较多量试剂的反应容器");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("B.烧杯用于较多量试剂的反应容器");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("C.烧杯用于较多量试剂的反应容器");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("D.烧杯用于较多量试剂的反应容器");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
t.addObject(paragraph);
paragraph = factory.createP();
txt = factory.createText();
txt.setValue("2.下列实验操作中,正确的是( ) ");
run = factory.createR();
run.getContent().add(txt);
run.setRPr(fontRPr);
paragraph.getContent().add(run);
// 段前8磅 段后0.5磅
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "160", "10");
t.addObject(paragraph);
paragraph = factory.createP();
File file = new File("f:/saveFile/temp/image1.png");
java.io.InputStream is = new java.io.FileInputStream(file);
createImageParagraph(wordMLPackage, factory, paragraph, "img_1", "A.", BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
file = new File("f:/saveFile/temp/image2.png");
is = new java.io.FileInputStream(file);
createImageParagraph(wordMLPackage, factory, paragraph, "img_2", StringUtils.leftPad("B.", 20), BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "1", "3");
t.addObject(paragraph);
paragraph = factory.createP();
file = new File("f:/saveFile/temp/image3.png");
is = new java.io.FileInputStream(file);
createImageParagraph(wordMLPackage, factory, paragraph, "img_3", "C.", BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
file = new File("f:/saveFile/temp/image4.png");
is = new java.io.FileInputStream(file);
createImageParagraph(wordMLPackage, factory, paragraph, "img_4", StringUtils.leftPad("D.", 20), BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "1", "3");
t.addObject(paragraph);
}
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, 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;
}
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, 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;
}
use of org.docx4j.wml.P in project docx4j-template by vindell.
the class Docx4j_Helper method name.
public static void name() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
String titleStr = "测试插入段落";
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);
documentPart.getContent().add(5, p);
String tblPrStr = "<w:tblPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:tblW w:w=\"8522\" w:type=\"dxa\"/><w:tblBorders><w:top w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:left w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:insideH w:val=\"single\" w:sz=\"4\" w:space=\"0\"/></w:tblBorders></w:tblPr>";
Tbl tbl = Docx4j_Helper.factory.createTbl();
TblPr tblPr = (TblPr) XmlUtils.unmarshalString(tblPrStr);
tbl.setTblPr(tblPr);
Tr tr = Docx4j_Helper.factory.createTr();
Tc tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tbl.getContent().add(tr);
tr = Docx4j_Helper.factory.createTr();
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tbl.getContent().add(tr);
documentPart.getContent().add(9, tbl);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
Aggregations