本文将介绍如何使用Spire.Doc for Java给Word文档设置限制编辑保护。
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.ProtectionType;
public class RestrictEditing {
public static void main(String[] args){
//创建Document实例
Document document = new Document();
//加载Word文档
document.loadFromFile("Sample.docx");
//设置编辑限制的类型及文档保护密码
//不允许任何更改(只读)
document.protect(ProtectionType.Allow_Only_Reading, "123456");
//仅允许批注
//document.protect(ProtectionType.Allow_Only_Comments, "123456");
//仅允许填写窗体
//document.protect(ProtectionType.Allow_Only_Form_Fields, "123456");
//仅允许修订
//document.protect(ProtectionType.Allow_Only_Revisions, "123456");
//保存文档
document.saveToFile("RestrictEditing.docx", FileFormat.Docx_2013);
}
}
设置“不允许任何更改(只读)”后的效果: