2015-05-13 4 views
-4

Мне нужна граница для моего XWPFTableCell, как показано ниже.Как добавить границу в XWPFTableCell

 **XXX Technologies** 

__________________
| Имя | Пол | Зарплата |
__________________
Раджи самку 24000
Ravi Мужской 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); 
}