use of org.docx4j.wml.Text in project docx4j-template by vindell.
the class Docx4J_简单例子2 method createImageParagraph.
// 段落中插入文字和图片
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, "0", "0");
return p;
}
use of org.docx4j.wml.Text in project docx4j-template by vindell.
the class Docx4J_简单例子2 method getTextHdr.
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception {
Hdr hdr = factory.createHdr();
P headP = factory.createP();
Text text = factory.createText();
text.setValue(content);
R run = factory.createR();
run.getContent().add(text);
headP.getContent().add(run);
PPr pPr = headP.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);
headP.setPPr(pPr);
setParagraphSpacing(factory, headP, jcEnumeration, "0", "0");
hdr.getContent().add(headP);
hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, jcEnumeration));
return hdr;
}
use of org.docx4j.wml.Text in project docx4j-template by vindell.
the class Docx4J_简单例子2 method addPageTextField.
private void addPageTextField(ObjectFactory factory, P paragraph, String value) {
R run = factory.createR();
Text txt = new Text();
txt.setSpace("preserve");
txt.setValue(value);
run.getContent().add(txt);
paragraph.getContent().add(run);
}
use of org.docx4j.wml.Text 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.Text 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);
}
Aggregations