英文:
Java Apache poi: Word - Unable to extract specific texts from document along with numbering and tables
问题
无法从文档中提取特定文本,包括编号和表格。
有关如何解决这个问题的任何想法吗?
英文:
Unable to extract specific texts from document along with numbering and tables.
Any ideas on how to solve this?
答案1
得分: 1
你需要设置位置,仅替换具有以下格式的文本:
r.setText(text, 0);
对于表格,你需要按照以下方式查找:
for (XWPFTable tbl : doc.getTables()) {
for (XWPFTableRow row : tbl.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (XWPFRun r : p.getRuns()) {
// ...
}
}
// 替换具有嵌套表格的值
for (XWPFTable tbl2 : cell.getTables()) {
for (XWPFTableRow row2 : tbl2.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (XWPFRun r : p.getRuns()) {
// ...
}
}
}
}
}
}
}
}
英文:
You need to set with the position to replace only the text with format
r.setText(text, 0);
For Table u need to find this way
for (XWPFTableRow row : tbl.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (XWPFRun r : p.getRuns()) {
.....
}}
// Replace values with nested table
for (XWPFTable tbl2 : cell.getTables()) {
for (XWPFTableRow row2 : tbl2.getRows()){
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (XWPFRun r : p.getRuns()) {
...
}}
}}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论