Protect a word document programmatically using java

血红的双手。 提交于 2021-01-29 03:33:53

问题


I am creating a word 2003 document from a template XML document using a java code. I need to protect (make read-only) the document after it has been created. The document has some fields as editable (i.e. text form fields of the developer mode) in it, which can be editable after the document is created. Can this be achieved using java?


回答1:


If you only need to make the Word Document a Read-Only, you can do it like this:

import java.io.File;

public class FileReadOnly {
    public static void main(String[] args) {
        File file = new File("c:/file.txt");
        file.setReadOnly();
    }
}



回答2:


Have a look at Apache poi. This is a java library for manipulating office document.



来源:https://stackoverflow.com/questions/9991834/protect-a-word-document-programmatically-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!