Search in sources :

Example 11 with TblBorders

use of org.docx4j.wml.TblBorders in project Java-Tutorial by gpcodervn.

the class TableBordersTest method testTableBorderStyles.

@Test
public void testTableBorderStyles() throws Docx4JException {
    HashMap<String, STBorder> styles = new HashMap<String, STBorder>();
    styles.put("none", STBorder.NONE);
    styles.put("hidden", STBorder.NONE);
    styles.put("solid", STBorder.SINGLE);
    styles.put("dotted", STBorder.DOTTED);
    styles.put("dashed", STBorder.DASHED);
    styles.put("double", STBorder.DOUBLE);
    styles.put("inset", STBorder.INSET);
    styles.put("outset", STBorder.OUTSET);
    // no direct substitution
    styles.put("groove", STBorder.SINGLE);
    // no direct substitution
    styles.put("ridge", STBorder.SINGLE);
    styles.put("anyOther", STBorder.NONE);
    for (String style : styles.keySet()) {
        Tbl tbl = table("<table style='border: 1px " + style + " black;'><tr><td>1</td></tr></table>");
        TblBorders borders = tbl.getTblPr().getTblBorders();
        assertEquals(styles.get(style), borders.getTop().getVal());
    }
}
Also used : STBorder(org.docx4j.wml.STBorder) HashMap(java.util.HashMap) TblBorders(org.docx4j.wml.TblBorders) Tbl(org.docx4j.wml.Tbl) Test(org.junit.Test)

Example 12 with TblBorders

use of org.docx4j.wml.TblBorders in project Java-Tutorial by gpcodervn.

the class TableBordersTest method testTableBorderColors.

@Test
public void testTableBorderColors() throws Docx4JException {
    Tbl tbl = table("<table style='border-style: solid; border-color:#111 #222 #333 #444;'><tr><th>1</th></tr></table>");
    TblBorders borders = tbl.getTblPr().getTblBorders();
    assertEquals("111111", borders.getTop().getColor());
    assertEquals("222222", borders.getRight().getColor());
    assertEquals("333333", borders.getBottom().getColor());
    assertEquals("444444", borders.getLeft().getColor());
}
Also used : TblBorders(org.docx4j.wml.TblBorders) Tbl(org.docx4j.wml.Tbl) Test(org.junit.Test)

Example 13 with TblBorders

use of org.docx4j.wml.TblBorders in project Java-Tutorial by gpcodervn.

the class TableBordersTest method testTableBorderWidths.

@Test
public void testTableBorderWidths() throws Docx4JException {
    Tbl tbl = table("<table style='border-style: solid; border-width: 0px 1px 2px 3px;'><tr><th>1</th></tr></table>");
    TblBorders borders = tbl.getTblPr().getTblBorders();
    assertNull(borders.getTop().getSz());
    assertTrue(borders.getRight().getSz().longValue() > 0);
    assertTrue(borders.getBottom().getSz().longValue() > borders.getRight().getSz().longValue());
    assertTrue(borders.getLeft().getSz().longValue() > borders.getBottom().getSz().longValue());
}
Also used : TblBorders(org.docx4j.wml.TblBorders) Tbl(org.docx4j.wml.Tbl) Test(org.junit.Test)

Example 14 with TblBorders

use of org.docx4j.wml.TblBorders in project docx4j-template by vindell.

the class Docx4J_例子2 method addBorders.

// 表格增加边框 可以设置上下左右四个边框样式以及横竖水平线样式
public void addBorders(Tbl table, CTBorder topBorder, CTBorder bottomBorder, CTBorder leftBorder, CTBorder rightBorder, CTBorder hBorder, CTBorder vBorder) {
    table.setTblPr(new TblPr());
    TblBorders borders = new TblBorders();
    borders.setBottom(bottomBorder);
    borders.setLeft(leftBorder);
    borders.setRight(rightBorder);
    borders.setTop(bottomBorder);
    borders.setInsideH(hBorder);
    borders.setInsideV(vBorder);
    table.getTblPr().setTblBorders(borders);
}
Also used : TblBorders(org.docx4j.wml.TblBorders) TblPr(org.docx4j.wml.TblPr)

Example 15 with TblBorders

use of org.docx4j.wml.TblBorders 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)

Aggregations

TblBorders (org.docx4j.wml.TblBorders)18 TblPr (org.docx4j.wml.TblPr)10 CTBorder (org.docx4j.wml.CTBorder)9 BigInteger (java.math.BigInteger)8 Tbl (org.docx4j.wml.Tbl)6 Test (org.junit.Test)6 TcPrInner (org.docx4j.wml.TcPrInner)3 HashMap (java.util.HashMap)1 STBorder (org.docx4j.wml.STBorder)1