use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class Docx4J_简单例子 method getRPr.
/**
* 创建字体
*
* @param isBlod
* 粗体
* @param isUnderLine
* 下划线
* @param isItalic
* 斜体
* @param isStrike
* 删除线
*/
public RPr getRPr(ObjectFactory factory, String fontFamily, String colorVal, String fontSize, STHint sTHint, boolean isBlod, boolean isUnderLine, boolean isItalic, boolean isStrike) {
RPr rPr = factory.createRPr();
RFonts rf = new RFonts();
rf.setHint(sTHint);
rf.setAscii(fontFamily);
rf.setHAnsi(fontFamily);
rPr.setRFonts(rf);
BooleanDefaultTrue bdt = factory.createBooleanDefaultTrue();
rPr.setBCs(bdt);
if (isBlod) {
rPr.setB(bdt);
}
if (isItalic) {
rPr.setI(bdt);
}
if (isStrike) {
rPr.setStrike(bdt);
}
if (isUnderLine) {
U underline = new U();
underline.setVal(UnderlineEnumeration.SINGLE);
rPr.setU(underline);
}
Color color = new Color();
color.setVal(colorVal);
rPr.setColor(color);
HpsMeasure sz = new HpsMeasure();
sz.setVal(new BigInteger(fontSize));
rPr.setSz(sz);
rPr.setSzCs(sz);
return rPr;
}
use of org.docx4j.wml.RPr 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.RPr in project docx4j-template by vindell.
the class Docx4J_简单例子2 method createNormalTableTest.
public void createNormalTableTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false);
RPr contentRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
Tbl table = factory.createTbl();
addBorders(table, "2");
// 百分比
double[] widthPercent = new double[] { 15, 20, 20, 20, 25 };
setTableGridCol(wordMLPackage, factory, table, widthPercent);
Tr titleRow = factory.createTr();
setTableTrHeight(factory, titleRow, "500");
addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
table.getContent().add(titleRow);
for (int i = 0; i < 10; i++) {
Tr contentRow = factory.createTr();
addTableCell(factory, wordMLPackage, contentRow, i + "", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲", contentRpr, JcEnumeration.CENTER, false, null);
table.getContent().add(contentRow);
}
setTableAlign(factory, table, JcEnumeration.CENTER);
t.addObject(table);
}
use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class Docx4J_简单例子2 method getRPr.
/**
* 创建字体
*
* @param isBlod
* 粗体
* @param isUnderLine
* 下划线
* @param isItalic
* 斜体
* @param isStrike
* 删除线
*/
public RPr getRPr(ObjectFactory factory, String fontFamily, String colorVal, String fontSize, STHint sTHint, boolean isBlod, boolean isUnderLine, boolean isItalic, boolean isStrike) {
RPr rPr = factory.createRPr();
RFonts rf = new RFonts();
rf.setHint(sTHint);
rf.setAscii(fontFamily);
rf.setHAnsi(fontFamily);
rPr.setRFonts(rf);
BooleanDefaultTrue bdt = factory.createBooleanDefaultTrue();
rPr.setBCs(bdt);
if (isBlod) {
rPr.setB(bdt);
}
if (isItalic) {
rPr.setI(bdt);
}
if (isStrike) {
rPr.setStrike(bdt);
}
if (isUnderLine) {
U underline = new U();
underline.setVal(UnderlineEnumeration.SINGLE);
rPr.setU(underline);
}
Color color = new Color();
color.setVal(colorVal);
rPr.setColor(color);
HpsMeasure sz = new HpsMeasure();
sz.setVal(new BigInteger(fontSize));
rPr.setSz(sz);
rPr.setSzCs(sz);
return rPr;
}
use of org.docx4j.wml.RPr 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