问题
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