Document document = new Document("111.wps");
for (int j = 0; j < document.getSections().getCount(); j++) {
Section section = document.getSections().get(j);
for (int k = 0; k < section.getParagraphs().getCount(); k++) {
Paragraph paragraph = section.getParagraphs().get(k);
// 找到"PermissionStart" and "PermissionEnd" 标签并删除 (去掉标注每个人都可编辑的权限)
for (int i = 0; i < paragraph.getChildObjects().getCount();) {
DocumentObject obj = paragraph.getChildObjects().get(i);
if (obj instanceof PermissionStart || obj instanceof PermissionEnd) {
paragraph.getChildObjects().remove(obj);
} else {
i++;
}
}
}
int tableCount = section.getBody().getTables().getCount();
if(tableCount > 1){
// 遍历table
for (int i = 0; i < tableCount; i++) {
Table table = section.getBody().getTables().get(i);
for (int r = 0; r < table.getRows().getCount(); r++) {
TableRow row = table.getRows().get(r);
for (int c = 0; c < row.getCells().getCount(); c++) {
TableCell cell = row.getCells().get(c);
for (int p = 0; p < cell.getParagraphs().getCount(); p++) {
Paragraph paragraph = (Paragraph) cell.getParagraphs().get(p);
// 找到"PermissionStart" and "PermissionEnd" 标签并删除 (去掉标注每个人都可编辑的权限)
for (int ii = 0; ii < paragraph.getChildObjects().getCount();) {
DocumentObject obj = paragraph.getChildObjects().get(ii);
if (obj instanceof PermissionStart || obj instanceof PermissionEnd) {
paragraph.getChildObjects().remove(obj);
} else {
ii++;
}
}
}
}
}
}
}
}
// 设置文档是否接受修订
document.setTrackChanges(true);
// 接受修订
document.acceptChanges();
document.saveToFile("222.wps");