java - 如何用word文档中的段落替换表格?Apache POI [解决方案]
问题描述
这是用段落替换表格的功能。我们将首先找到表格位置,然后从那里删除它,并在同一位置添加一个段落。
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;
}
解决方案
推荐阅读
- javascript - 不和谐.JS | 如何创建一个专门在 [] 下的参数
- node.js - 如何在函数中获取对象数据并将其传递给nodejs中的不同函数
- c++ - 如何在没有额外副本的情况下从 std::map 安全地“pop-front”?
- javascript - 自定义配置底部导航
- javascript - 如何使 HTML 网站具有交互性,以便当用户单击删除按钮时它会为所有用户更改,即使您重新加载也是如此?
- javascript - 如果vue仍然抛出错误,那么vue中props中的默认值的目的是什么?
- google-bigquery - 如何使用 BigQuery 在没有每个元素的情况下获取所有总和值?
- react-native - React-Native-Audio-Toolkit 准备失败
- python - 在 Python 中计算指数分布的 lambda 参数的置信区间
- operating-system - 使用基址和边界时地址空间大小和“边界”有什么区别?