我是否可以通过Aspose.Words For Java来判断一个word文档的状态
Aspose.Words For Java 有没有方法可以判断 word文档 是否加密,是否限制编辑?
我是否可以通过Aspose.Words For Java来判断一个word文档的状态
Aspose.Words For Java 有没有方法可以判断 word文档 是否加密,是否限制编辑?
谢谢您的回复。
在你发的这个链接里,我没有看到具体的办法,我在这里找到了FileFormatUtil相关的代码:Get Document Properties|Aspose.Words for Java
但是经过我的测试,无论word文档是不是加密状态,通过这段代码检查的结果都是false。
另外,除了判断文档加密状态以外, 还能不能判断文档是不是限制编辑状态?
@SupportDhorde 是的,您可以使用 Document.getWriteProttection 来检查文档是否被写保护。
还可以使用FileFormatInfo.isEncrypted 属性来检查文档是否加密
我用示例代码测试了不同的文档,无论是加密文档还是未加密文档,代码结果反馈都是文档未加密。
请问我的代码需要做什么调整呢?
判断加密.png (38.2 KB)
同样的,判断文档是否限制编辑也有类似的问题,你能提供一下完整的示例代码给我吗?
非常感谢!
@Gavin_Zhang 您可以使用如下代码:
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");
}