为有中文需求的客户提供多渠道中文技术支持.

Tue Apr 26, 2022 8:26 am

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");

fengyun_23
 
Posts: 13
Joined: Fri Oct 08, 2021 3:33 am

Tue Apr 26, 2022 9:22 am

您好,

感谢您的咨询。
我测试了您的案例,确实复现了您提到的问题。我已将这个问题提交给我们的开发团队,问题编号为SPIREDOC-7747,我们的开发人员将调查并修复它。一旦有任何更新,我会及时通知你的。

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Wed Jun 29, 2022 9:58 am

您好,

感谢您的耐心等待。
关于问题SPIREDOC-7747,经过调查,我们发现问题是由于您的代码没有删除表格中的PermissionStart引起的,请使用下面修改后的代码再次测试。
Code: Select all
Document document = new Document();
document.loadFromFile("111.wps",FileFormat.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);
 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 > 0){
 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);
 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("333.wps",FileFormat.WPS);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Return to 中文技术支持