0

I am trying to add the border to the merged cell but with the below line of code it is not possible:

XWPFDocument document = new XWPFDocument();
XWPFTable table = document.createTable(1, 8);
CTTblBorders borders = table.getCTTbl().getTblPr().addNewTblBorders();
borders.addNewBottom().setVal(STBorder.THICK);
borders.addNewLeft().setVal(STBorder.NONE);
borders.addNewRight().setVal(STBorder.NONE);
borders.addNewTop().setVal(STBorder.THICK);
borders.addNewInsideV().setVal(STBorder.THICK);
table.getCTTbl().getTblPr().setTblBorders(borders);
table.setWidth(1440);

for (int col = 0 ; col < 8; col++) {
CTTblWidth tblWidth = table.getRow(0).getCell(col).getCTTc().addNewTcPr().addNewTcW();
tblWidth.setW(BigInteger.valueOf(1440));
//STTblWidth.DXA is used to specify width in twentieths of a point.
tblWidth.setType(STTblWidth.DXA);
}    
**mergeCellHorizontally(table, 0, 0, 1);**
XWPFTableCell cell = table.getRow(0).getCell(1);
CTTcPr ctTcPr = cell.getCTTc().getTcPr();
CTTcBorders ctTcBorders = ctTcPr.addNewTcBorders();
ctTcBorders.addNewRight().setVal(STBorder.NONE);
ctTcBorders.addNewBottom().setVal(STBorder.NONE);
theduck
  • 2,589
  • 13
  • 17
  • 23
Misthi
  • 33
  • 10
  • 1
    Your question is not clear. The title "... to **remove** the border ..." contradicts the only one sentence in your question "... trying to **add** the border ...". Providing code is good and necessary. But also from your code it is not possible to know what you want to achieve. Please ask as follows: What I want to achieve: ... What I have tried: What it results in at the moment: ... What do I have to change to get what I want? – Axel Richter Nov 02 '19 at 11:59
  • https://i.stack.imgur.com/FIuQ0.png I am trying to create a table without borders , Attached screenshot shows the table without borders .Also I have created 8 cells ,but when i am trying to merge cell 1 and 2 , i want to remove the right border for the newly created cell. XWPFTableCell cell = table.getRow(0).getCell(1); CTTcPr ctTcPr = cell.getCTTc().getTcPr(); CTTcBorders ctTcBorders = ctTcPr.addNewTcBorders(); ctTcBorders.addNewRight().setVal(STBorder.NONE); ctTcBorders.addNewBottom().setVal(STBorder.NONE); This code is not removing the border – Misthi Nov 02 '19 at 12:13
  • Please [edit](https://stackoverflow.com/posts/58669416/edit) your question and provide all necessary information there and not in comments. – Axel Richter Nov 02 '19 at 12:15

0 Answers0