Word这么判断限制编辑是否加密

 FileFormatInfo ins2 =  FileFormatUtil.detectFileFormat("新建 DOCX 文档.docx");
 System.out.println("Document is encryptedins21111111: " + ins2.isEncrypted());

这么判断不出来。

@zhangquan 你能把你的文件附在这里进行测试吗? 我们会检查并为您提供更多信息。

好的,小鹏汽车西宁王府井项目合同20210930.docx (130.9 KB)

@zhangquan 附加文档未加密,但受 ALLOW_ONLY_COMMENTS ProtectionType 保护。 请查看以下简单代码来检查这一点

FileFormatInfo info = FileFormatUtil.detectFileFormat("C:\\Temp\\in.docx");
if (info.isEncrypted())
{
    System.out.println("The document is encrypted.");
}
else
{
    System.out.println("The document is not encrypted.");

    // Open document without password.
    Document doc = new Document("C:\\Temp\\in.docx");
    if (doc.getWriteProtection().isWriteProtected())
        System.out.println("The document is Write Protected.");
    if (doc.getWriteProtection().getReadOnlyRecommended())
        System.out.println("The document is Read Only Recommended.");

    if (doc.getProtectionType() != ProtectionType.NO_PROTECTION)
        System.out.println("The document is protected with " + doc.getProtectionType() + " protection type");
}

感谢大佬的讲解,可以通过这样来判断,但是我用编辑受限的密码去解密为什么是失败的啊。用的是unprotect 这个方法。小鹏汽车西宁王府井项目合同20210930.docx (130.9 KB)
Document doc = new Document(“C:\Temp\in.docx”); doc.unprotect(“123”)

@zhangquan
我使用以下代码取消了对您的文档的保护,并且输出文档没有任何保护。

Document doc = new Document("C:\\Temp\\in.docx");
doc.unprotect();
doc.save("C:\\Temp\\out.docx");

是的,这样的确是能取消。但是我不打算取消保护啊。我想通过限制编辑密码在做一层校验。因为我这边上传的附件 也许有我们自己加的限制编辑密码,也有不是我们加的限制编辑密码。要区分出来。有什么好的方法吗?小鹏汽车西宁王府井项目合同20210930.docx (130.9 KB)
限制 编辑密码是 123

如果我正确理解您,您正在尝试验证密码。 我看到在这种情况下无法使用正确指定的密码取消对文档的保护。 我已将此问题记录为 WORDSNET-22989

后续我这么跟踪这个问题啊。

The issues you have found earlier (filed as WORDSNET-22989) have been fixed in this Aspose.Words for .NET 22.3 update also available on NuGet.