开发者

How to manipulate .doc files

开发者 https://www.devze.com 2023-02-13 22:55 出处:网络
I need to create a little desktop app in Java that creates for me a .doc file and writes a bit of text into the file. I found an interestin开发者_StackOverflow中文版g tool called Aspose, but i saw it

I need to create a little desktop app in Java that creates for me a .doc file and writes a bit of text into the file. I found an interestin开发者_StackOverflow中文版g tool called Aspose, but i saw it is not free at all. Do yoy know what kind of, java API can i use for doing that(for free)? Is it possible to do that only with the java SE libraries? What do you think would be the easiest and fastest way to achive this goal?


I suggest you have a look at the Apache POI framework, specifically the HWPF - Java API to Handle Microsoft Word Files:

HWPF is the name of our port of the Microsoft Word 97(-2007) file format to pure Java. It also provides limited read only support for the older Word 6 and Word 95 file formats.


if you are going with .doc then as a learning excercise, open a Word document with some content (ideally similar to what you want to create) then save that as XML, and review the contents.

you will need to do some basic DOM parsing and management in your code to insert the right stuff.


By .doc file, I assume you mean Microsoft Office? Reading and writing Office file formats is something of a black art. Does it have to be a .doc format file specifically? A lot easier would be to write out a Rich Text Format file (.rtf) that Word could load.


And if you don't need to use .doc specifically I would suggest you use .odt, http://www.jopendocument.org/.

0

精彩评论

暂无评论...
验证码 换一张
取 消