在Java中的Word文档创建API [英] Word document creation API in Java

查看:287
本文介绍了在Java中的Word文档创建API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用模板创建一个Word文档,替换一些变量(字段),并将其保存为一个新的Word文档。

I would like to create a word document using a template, replace some variables (fields) and save it as a new word document.

我使用Apache POI想, http://poi.apache.org/ 是它最适合这个目的是什么?
你可以从中分享您的IM pression?

I was thinking using Apache POI, http://poi.apache.org/ is it the best for this purpose? can you share your impression from it?

推荐答案

我和POI工作前,它肯定能够生成Word文档。但魔鬼在细节。

I've worked with POI before and it's certainly able to generate Word documents. But the devil is in the details.

Word有数以千计的功能:你可以把编号列表开始于#13负缩进到表的两个加入细胞包含在另一个表本身就是一个符号列表的一部分...你的想法。当POI文件说,他们是在进展中的工作,这反映了可能会试图赶上(给我们,无证)字规范一个永恒的状态。

Word has thousands of features: You can put numbered lists starting at #13 with negative indents into two joined cells of a table included in another table that is itself part of a bullet list... you get the idea. When the POI documentation says they are a work in progress, that reflects what will probably be an eternal state of trying to catch up to the (to us, undocumented) specification of Word.

用一个合理的正常设置的功能都深受POI,其接口和方法是合理的,一致的,但有时需要一些工作文件的支持。但正如帕斯卡尔说,用一个不太昂贵的特性文件也由RTF支持。
我几乎没有任何经验的做RTF但它可能比POI工作简单一些。

Documents with a reasonably "normal" set of used features are well supported by POI, whose interfaces and methods are reasonable and consistent but sometimes require a bit of work. But as Pascal says, documents with a not too exorbitant set of features are also supported by RTF. I have almost no experience "doing" RTF but it's probably a bit simpler than working with POI.

如果您是在一个环境或者谁坚称您出示的文件是一个客户合作 .DOC ,而不是 .RTF ,那么POI是pretty多少你唯一的选择,除非你能介绍,你用了一下办公自动化为RTF转换成DOC的一步。

If you're working in an environment or for a customer who insists that your produced documents be .DOC rather than .RTF, then POI is pretty much your only choice, unless you can introduce a step where you use a bit of Office automation to convert RTF into DOC.

更新:我在此期间,有一对夫妇更多的想法。

Update: I've had a couple more ideas in the meantime.

使用POI或创建RTF文档的东西,你可以在几乎任何平台上做。在我的工作,这样做处理这样所有服务器都发生在运行Linux为例。

Using POI or creating RTF documents is something that you could do on practically any platform. At my job, all servers doing processing like this happen to be running Linux, for example.

然而,在你的程序将在Windows下运行可能发生的情况,还有另一种选择:雅各http://www.land-of-kain.de/docs/jacob/

However, in the likely case that your programs will run under Windows, there is another alternative: Jacob http://www.land-of-kain.de/docs/jacob/

雅各布是一个Java COM 界面;它基本上是让你遥控器的Windows程序,如Word和Excel。我联系到上面的文件是不是雅各布自己的网站,但与俗套的配方使用雅各布单页。该项目本身是在SourceForge上:<一href=\"http://sourceforge.net/projects/jacob-project/\">http://sourceforge.net/projects/jacob-project/但人声称,这是正确的,该文档有点欠缺。

Jacob is a COM interface for Java; it essentially allows you to "remote control" Windows programs such as Word and Excel. The document I linked to above is not to Jacob's own site but to a single page with "cookie cutter" recipes for using Jacob. The project itself is on SourceForge: http://sourceforge.net/projects/jacob-project/ But people claim, and rightly so, that the documentation is a bit lacking.

雅各布的优势,你处理实字,因此,所有其他解决方案的所有的字的功能是提供给您。如果有,只是不能与POI或经由RTF格式的处理文档的细节方面,这将是另一种选择。

Jacob has the advantage over all other solutions that you're dealing with the "real" Word and therefore all capabilities of Word are available to you. This would be an alternative if there are detail aspects of your document that just can't be handled with POI or via the RTF format.

这篇关于在Java中的Word文档创建API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆