Java 删除XWPFTableRow的边框
我有一个带边框的Java 删除XWPFTableRow的边框,java,apache-poi,Java,Apache Poi,我有一个带边框的XWPFTable,我在其中添加了一个分页符: addBreak(BreakType.PAGE) 在下一页中,我想删除最后一个XWPFTableRow的边框,但我不能,因为此行不提供对边框的访问。边框属于表格 如何删除最后一行的边框?下面的代码显示了如何访问/添加CTTcBorders对象以根据需要设置标志 XWPFDocument doc = new XWPFDocument(); CTTbl ctTable = CTTbl.Factory.newInstan
XWPFTable
,我在其中添加了一个分页符:
addBreak(BreakType.PAGE)
在下一页中,我想删除最后一个XWPFTableRow
的边框,但我不能,因为此行不提供对边框的访问。边框属于表格
如何删除最后一行的边框?下面的代码显示了如何访问/添加CTTcBorders对象以根据需要设置标志
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
XWPFTable table = new XWPFTable(ctTable, doc);
XWPFTableRow tr = table.getRow(0);
XWPFTableCell cell = tr.getCell(0);
CTTc ctTc = cell.getCTTc();
CTTcPr tcPr = ctTc.addNewTcPr();
CTHMerge hMerge = tcPr.addNewHMerge();
hMerge.setVal(STMerge.RESTART);
CTTcBorders tblBorders = tcPr.addNewTcBorders();
对于现有文档,您需要遍历对象以找到要调整的对象。解决方案是:
cell.getCTTc().getTcPr().getTcBorders().addNewRight().setVal(STBorder.NIL);
谢谢 我试图删除一些行的中间边框,但我所做的不仅仅是删除右边框 我必须迭代所需的单元格,然后,对于第I个单元格(cell=row.get(I)),删除第I个单元格的右边框和下一个单元格的左边框(nextCell=row.get(I+1)) 一个单元格的右边框与行中下一个单元格的左边框重合,我需要同时隐藏这两个单元格
public void hideTableInnerBorders(XWPFTable table){
// for the 5th and 6th rows (index 4,5),
// hide the right border for the three middle columns (index 1,2,3)
// and the left border on the three last columns (index 2,3,4)
List<XWPFTableRow> rows = table.getRows();
for( int rowIndex = 4; rowIndex < rows.size(); rowIndex++){ // rowIndex:{4,5} - last two lines
List<XWPFTableCell> cells = rows.get(rowIndex).getTableCells();
for(int cellIndex = 1; cellIndex < cells.size(); cellIndex++){ // cellIndex:{1,2,3,4}
XWPFTableCell cell = cells.get(cellIndex);
CTTcBorders tblBorders = cell.getCTTc().getTcPr().addNewTcBorders();
// remove the right border for the indexes 1 2 3
if( cellIndex == 1 || cellIndex == 2 || cellIndex == 3 ){
tblBorders.addNewRight().setVal(STBorder.NIL);
}
// remove the left border for the indexes 2,3,4
if ( cellIndex == 2 || cellIndex == 3 || cellIndex == 4 ) {
tblBorders.addNewLeft().setVal(STBorder.NIL);
}
}
}
}
public void hideTableInnerBorders(xwptTable表){
//对于第5行和第6行(索引4,5),
//隐藏中间三列的右边框(索引1,2,3)
//最后三列的左边框(索引2,3,4)
列表行=table.getRows();
对于(introwindex=4;rowIndex
结果是:
您能用Word创建一个文档吗?有了这个,您可以看看它是如何存储在.docx(实际上是一个包含XML文件的zip)中的,POI通常允许访问一些低级API,如果您知道需要如何设置的话,这些API允许执行类似的操作。谢谢。还有一个问题。如何使用apachepoi处理此xml:
code