这种情况下,怎么在给XWPFDocument这个里面穿两个文档
for (int i = 0; i < scword.size(); i++) {
in = new FileInputStream(scword.get(i).getPath());
OPCPackage open = OPCPackage.open(in);
XWPFDocument document = new XWPFDocument(open);
documentlist.add(document);
}
循环中创建一个新的XWPFParagraph对象,使用XWPFParagraph.createRun()方法将两个文档的内容添加到新段落中。将新段落添加到目标XWPFDocument中。
XWPFDocument targetDoc = new XWPFDocument();
for (int i = 0; i < scword.size(); i++) {
FileInputStream in = new FileInputStream(scword.get(i).getPath());
OPCPackage open = OPCPackage.open(in);
XWPFDocument sourceDoc = new XWPFDocument(open);
for (XWPFParagraph p : sourceDoc.getParagraphs()) {
XWPFParagraph newP = targetDoc.createParagraph();
for (XWPFRun r : p.getRuns()) {
XWPFRun newR = newP.createRun();
newR.setText(r.getText(0));
newR.setBold(r.isBold());
newR.setItalic(r.isItalic());
newR.setUnderline(r.getUnderline());
newR.setColor(r.getColor());
}
}
}
// do something with targetDoc
官方文档里面有,可以设置只读,修订,批注,填写窗体
XWPFDocument document=new XWPFDocument();
// document.isEnforcedReadonlyProtection();不行
document.enforceReadonlyProtection("123", HashAlgorithm.md5);wps无效
// document.enforceReadonlyProtection("123", HashAlgorithm.sha512);可以,但是依然可以复制
// document.enforceTrackedChangesProtection("123", HashAlgorithm.sha512);修订
// document.enforceCommentsProtection("123", HashAlgorithm.sha512);//批注
//document.enforceFillingFormsProtection("123", HashAlgorithm.sha512);//填写窗口
这里说一下只读,md5加密的时候,wps表面不能修改,但是可以直接停止保护
可以使用sha512加密,这样在wps中也有效果了;但是 。。。
目前只读有bug,我们复制出来就可以修改了,很明显与我们的开发需求不符合
我们可以使用填写窗体这个方法,并设置密码;这样就不能修改文档内容,不能被复制了
XWPFDocument document=new XWPFDocument();
// document.isEnforcedReadonlyProtection();不行
// document.enforceReadonlyProtection("123", HashAlgorithm.md5);wps无效
// document.enforceReadonlyProtection("123", HashAlgorithm.sha512);可以,但是依然可以复制
// document.enforceTrackedChangesProtection("123", HashAlgorithm.sha512);修订
// document.enforceCommentsProtection("123", HashAlgorithm.sha512);//批注
document.enforceFillingFormsProtection("123", HashAlgorithm.sha512);//填写窗口
好了,完美解决,正常操作是不能复制的!!!