use of org.docx4j.wml.CTBorder 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();
CTBorder topBorder = new CTBorder();
topBorder.setColor("80C687");
topBorder.setVal(STBorder.DOUBLE);
topBorder.setSz(new BigInteger("2"));
CTBorder leftBorder = new CTBorder();
leftBorder.setVal(STBorder.NONE);
leftBorder.setSz(new BigInteger("0"));
CTBorder hBorder = new CTBorder();
hBorder.setVal(STBorder.SINGLE);
hBorder.setSz(new BigInteger("1"));
addBorders(table, topBorder, topBorder, leftBorder, leftBorder, hBorder, null);
// 百分比
double[] colWidthPercent = new double[] { 15, 20, 20, 20, 25 };
setTableGridCol(wordMLPackage, factory, table, 80, colWidthPercent);
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.CTBorder in project docx4j-template by vindell.
the class Docx4J_例子2 method main.
public static void main(String[] args) throws Exception {
Docx4J_例子2 t = new Docx4J_例子2();
WordprocessingMLPackage wordMLPackage = t.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
Relationship relationship = t.createHeaderPart(wordMLPackage, mp, factory, false, "3");
relationship = t.createTextHeaderPart(wordMLPackage, mp, factory, "我是页眉,独乐乐不如众乐乐", true, "3", JcEnumeration.CENTER);
t.addParagraphTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory, STBrType.PAGE);
t.createHeaderReference(wordMLPackage, mp, factory, relationship);
t.createNormalTableTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory, STBrType.TEXT_WRAPPING);
t.createTableTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory, STBrType.TEXT_WRAPPING);
P paragraph = factory.createP();
CTBorder topBorder = new CTBorder();
topBorder.setSpace(new BigInteger("1"));
topBorder.setSz(new BigInteger("2"));
topBorder.setVal(STBorder.WAVE);
t.createParagraghLine(wordMLPackage, mp, factory, paragraph, topBorder, topBorder, topBorder, topBorder);
mp.addObject(paragraph);
t.createHyperlink(wordMLPackage, mp, factory, paragraph, "mailto:1329186624@qq.com?subject=docx4j测试", "联系我", "微软雅黑", "24", JcEnumeration.CENTER);
// 页脚
// relationship = t.createFooterPart(wordMLPackage, mp, factory,
// false,"3");
// relationship = t.createTextFooterPart(wordMLPackage, mp,
// factory,"我是页脚", true, "3", JcEnumeration.CENTER);
relationship = t.createFooterPageNumPart(wordMLPackage, mp, factory, false, "3", JcEnumeration.CENTER);
t.createFooterReference(wordMLPackage, mp, factory, relationship);
t.saveWordPackage(wordMLPackage, new File("f:/saveFile/temp/s7_simple.docx"));
}
use of org.docx4j.wml.CTBorder in project docx4j-template by vindell.
the class Docx4J_例子2 method addBorders.
// 表格增加边框
public void addBorders(Tbl table, String borderSize) {
table.setTblPr(new TblPr());
CTBorder border = new CTBorder();
border.setColor("auto");
border.setSz(new BigInteger(borderSize));
border.setSpace(new BigInteger("0"));
border.setVal(STBorder.SINGLE);
TblBorders borders = new TblBorders();
borders.setBottom(border);
borders.setLeft(border);
borders.setRight(border);
borders.setTop(border);
borders.setInsideH(border);
borders.setInsideV(border);
table.getTblPr().setTblBorders(borders);
}
use of org.docx4j.wml.CTBorder in project docx4j-template by vindell.
the class Docx4J_例子2 method newImage.
public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, Part sourcePart, byte[] bytes, String filenameHint, String altText, int id1, int id2, boolean isUnderLine, String underLineSize, JcEnumeration jcEnumeration) throws Exception {
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, sourcePart, bytes);
Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, false);
P p = factory.createP();
R run = factory.createR();
p.getContent().add(run);
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);
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(underLineSize));
pBdr.setBetween(value);
pPr.setPBdr(pBdr);
}
setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
return p;
}
use of org.docx4j.wml.CTBorder 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;
}
Aggregations