Search in sources :

Example 16 with CTBorder

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);
}
Also used : RPr(org.docx4j.wml.RPr) ParaRPr(org.docx4j.wml.ParaRPr) CTBorder(org.docx4j.wml.CTBorder) BigInteger(java.math.BigInteger) Tr(org.docx4j.wml.Tr) STHint(org.docx4j.wml.STHint) Tbl(org.docx4j.wml.Tbl)

Example 17 with CTBorder

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"));
}
Also used : P(org.docx4j.wml.P) ObjectFactory(org.docx4j.wml.ObjectFactory) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) CTBorder(org.docx4j.wml.CTBorder) Relationship(org.docx4j.relationships.Relationship) BigInteger(java.math.BigInteger) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File)

Example 18 with CTBorder

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);
}
Also used : CTBorder(org.docx4j.wml.CTBorder) BigInteger(java.math.BigInteger) TblBorders(org.docx4j.wml.TblBorders) TblPr(org.docx4j.wml.TblPr)

Example 19 with CTBorder

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;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 20 with CTBorder

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;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) Hdr(org.docx4j.wml.Hdr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Text(org.docx4j.wml.Text)

Aggregations

CTBorder (org.docx4j.wml.CTBorder)24 BigInteger (java.math.BigInteger)22 P (org.docx4j.wml.P)9 PPr (org.docx4j.wml.PPr)9 TblBorders (org.docx4j.wml.TblBorders)9 TblPr (org.docx4j.wml.TblPr)9 CTVerticalJc (org.docx4j.wml.CTVerticalJc)8 Jc (org.docx4j.wml.Jc)8 PBdr (org.docx4j.wml.PPrBase.PBdr)8 R (org.docx4j.wml.R)8 STVerticalJc (org.docx4j.wml.STVerticalJc)8 Text (org.docx4j.wml.Text)3 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)2 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)2 Drawing (org.docx4j.wml.Drawing)2 Ftr (org.docx4j.wml.Ftr)2 Hdr (org.docx4j.wml.Hdr)2 ParaRPr (org.docx4j.wml.ParaRPr)2 RPr (org.docx4j.wml.RPr)2 TcPr (org.docx4j.wml.TcPr)2