2015-05-13 224 views
-4

我需要一个边框到我的XWPFTableCell,如下表所示。如何添加边框到XWPFTableCell

 **XXX Technologies** 

__________________
|名称|性别|工资|
__________________
的Raji女性24000
拉维男06790

+0

你看到了吗? http://obscuredclarity.blogspot.com/2011/12/set-background-color-and-add-border-to.html –

回答

1

您可以添加边框您的细胞像下面

CTTc ctTc = cell.getCTTc(); 
CTTcPr tcPr = ctTc.getTcPr(); 
CTTcBorders border = tcPr.addNewTcBorders(); 

border.addNewBottom().setVal(STBorder.SINGLE); 
border.addNewRight().setVal(STBorder.SINGLE); 
border.addNewLeft().setVal(STBorder.SINGLE); 
border.addNewTop().setVal(STBorder.SINGLE); 
4
CTTc ctTc = cell.getCTTc(); 
// here is need to change... 
CTTcPr tcPr = ctTc.addNewTcPr(); 
CTTcBorders border = tcPr.addNewTcBorders(); 
border.addNewRight().setVal(STBorder.SINGLE); 
+0

你可以使用下面的代码:(只需要添加addNewTcPr()) –

+0

这是工作我!谢谢! – Fzum

1

此方法允许你设置表格的边框到你想要的颜色。

private static void setTableBorderColor(XWPFTable table, String color) { 

    table.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getRight().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setColor(color); 

    table.getCTTbl().getTblPr().getTblBorders().getRight().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getBottom().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setSz(BigInteger.valueOf(4)); 
} 
0

你可以使用这个辅助函数的风格整个表(改编自拉胡尔khanvani):

public static void tableSetBorders(
     XWPFTable table, 
     STBorder.Enum borderType, 
     int size, 
     int space, 
     String hexColor) { 

    table.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getRight().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setColor(hexColor); 

    table.getCTTbl().getTblPr().getTblBorders().getRight().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getBottom().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setSz(BigInteger.valueOf(size)); 

    table.getCTTbl().getTblPr().getTblBorders().getBottom().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getRight().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setVal(borderType); 
}