Hi Sir
請問一下空白列中若想要複製未選checkbox的部分,可以如何實現呢?
空白列複製未選擇的checkbox.7z (19.0 KB)
请将以下资源压缩成ZIP格式并附上.zip文件用于测试:
- 一个简化的源 Word DOCX 文档
- 要在空白行中复制的区域的屏幕截图
- 您预期的 DOCX 文件显示了所需的输出。 您可以使用 MS Word 手动创建此文件。
一旦您准备好这些信息,我们就会开始进一步调查您的特定情况并为您提供更多信息。
请使用这些示例输入和输出 Word DOCX 文件并尝试运行以下代码:
- awjava-21.9.docx (15.6 KB)
- input.docx (20.2 KB)
Document doc = new Document("C:\\Temp\\236038\\input.docx");
Table table = doc.getFirstSection().getBody().getTables().get(0);
Row cloneOfLastRow = (Row) table.getLastRow().deepClone(true);
for (Cell cell : cloneOfLastRow.getCells()) {
boolean hasCheckboxes = false;
for (StructuredDocumentTag sdt : (Iterable<StructuredDocumentTag>)
cell.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
if (sdt.getSdtType() == SdtType.CHECKBOX) {
hasCheckboxes = true;
sdt.setChecked(false);
}
}
if (!hasCheckboxes) {
cell.removeAllChildren();
cell.ensureMinimum();
}
}
for (int i = 0; i < 7; i++) {
table.getRows().add(cloneOfLastRow.deepClone(true));
}
doc.save("C:\\temp\\236038\\awjava-21.9.docx");
thank you very much!
1 Like