问题描述
这是一个用段落替换表格的函数。我们将首先找到表格位置,然后将其从那里删除,并在同一位置添加一个段落。
public XWPFDocument replaceTableWithText(XWPFDocument document){
String replaceText = "This is the text which needs to replace a table";
int tableNumberInDocument = 1;
List<XWPFTable> tables = document.getTables();
XWPFTable theTable = tables.get(tableNumberInDocument);
int position = document.getPosOfTable(theTable);
document.removeBodyElement(position);
XWPFParagraph paragraph = document.createParagraph();
XWPFRun xr = paragraph.createRun();
xr.setBold(true);
xr.setText(replaceText);
xr.addBreak();
xr.setFontSize(12);
xr.setFontFamily("Arial");
document.setParagraph(paragraph,position);
return document;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)