如何操作 .doc 文件
我需要用 Java 创建一个小型桌面应用程序,它为我创建一个 .doc 文件并向该文件写入一些文本。我发现了一个有趣的工具,叫做 Aspose,但我发现它根本不是免费的。 你知道我可以使用哪种 java API 来做到这一点(免费)吗? 是否可以仅使用 java SE 库来做到这一点? 您认为实现这一目标最简单、最快的方法是什么?
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 interesting 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议您查看 Apache POI 框架,特别是 HWPF - 用于处理 Microsoft Word 文件的 Java API:
I suggest you have a look at the Apache POI framework, specifically the HWPF - Java API to Handle Microsoft Word Files:
如果您要使用 .doc 作为学习练习,请打开包含一些内容(最好与您想要创建的内容相似)的 Word 文档,然后将其另存为 XML,并查看内容。
您需要在代码中进行一些基本的 DOM 解析和管理才能插入正确的内容。
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.
我认为您所说的 .doc 文件是指 Microsoft Office?读取和写入 Office 文件格式是一种魔法。它必须是 .doc 格式的文件吗?更简单的方法是编写 Word 可以加载的富文本格式文件 (.rtf)。
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.
如果您不需要特别需要使用.doc,我建议您使用.odt,http://www.jopendocument.org/。
And if you don't need to use .doc specifically I would suggest you use .odt, http://www.jopendocument.org/.