use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class Docx4j_Helper method testDocx4jSetPageSize.
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);
}
use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class Docx4jStyle_S3 method addCellStyle.
public void addCellStyle(ObjectFactory factory, Tc tableCell, String content, Docx4jStyle_S3 style) {
if (style != null) {
P paragraph = factory.createP();
Text text = factory.createText();
text.setValue(content);
R run = factory.createR();
run.getContent().add(text);
paragraph.getContent().add(run);
setHorizontalAlignment(paragraph, style.getHorizAlignment());
RPr runProperties = factory.createRPr();
if (style.isBold()) {
addBoldStyle(runProperties);
}
if (style.isItalic()) {
addItalicStyle(runProperties);
}
if (style.isUnderline()) {
addUnderlineStyle(runProperties);
}
setFontSize(runProperties, style.getFontSize());
setFontColor(runProperties, style.getFontColor());
setFontFamily(runProperties, style.getCnFontFamily(), style.getEnFontFamily());
setCellMargins(tableCell, style.getTop(), style.getRight(), style.getBottom(), style.getLeft());
setCellColor(tableCell, style.getBackground());
setVerticalAlignment(tableCell, style.getVerticalAlignment());
setCellBorders(tableCell, style.isBorderTop(), style.isBorderRight(), style.isBorderBottom(), style.isBorderLeft());
run.setRPr(runProperties);
tableCell.getContent().add(paragraph);
}
}
use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setTcHidden.
/**
* @Description: 隐藏单元格内容
*/
public void setTcHidden(Tc tc, boolean hidden) {
List<P> pList = getTcAllP(tc);
for (P p : pList) {
PPr ppr = getPPr(p);
List<Object> objRList = getAllElementFromObject(p, R.class);
if (objRList == null) {
continue;
}
for (Object objR : objRList) {
if (objR instanceof R) {
R r = (R) objR;
RPr rpr = getRPr(r);
setRPrVanishStyle(rpr, hidden);
}
}
setParaVanish(ppr, hidden);
}
}
use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class WordprocessingMLPackageRender method addStyling.
/**
* 这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象;
* 第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
* 到其中. 随后我们将运行块R添加到段落内容中.
* 直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
* 这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
*/
public void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {
P paragraph = factory.createP();
Text text = factory.createText();
text.setValue(content);
R run = factory.createR();
run.getContent().add(text);
paragraph.getContent().add(run);
RPr runProperties = factory.createRPr();
if (bold) {
addBoldStyle(runProperties);
}
if (fontSize != null && !fontSize.isEmpty()) {
setFontSize(runProperties, fontSize);
}
run.setRPr(runProperties);
tableCell.getContent().add(paragraph);
}
use of org.docx4j.wml.RPr in project docx4j-template by vindell.
the class ChangingTheStyleSheet method alterNormalStyle.
/**
* First we create a run properties object as we want to remove nearly all of
* the existing styling. Then we change the font and font size and set the
* run properties on the given style. As in previous examples, the font size
* is defined to be in half-point size.
*/
private static void alterNormalStyle(Style style) {
// we want to change (or remove) almost all the run properties of the
// normal style, so we create a new one.
RPr rpr = new RPr();
changeFontToArial(rpr);
changeFontSize(rpr, 20);
style.setRPr(rpr);
}
Aggregations