使用Jacob开源插件操作Microsoft Word 主题 最近项目中要进行公文的操作,所有就想到了使用Java来操作word,找了一些资料,都是比较零散、杂乱的东西,今早向Google大神求救,终于发现了一位热心的国外同学的文章,收获颇多,因此将此文翻译出来,供大家参考,本文英语水平很烂,但是为了学习同鞋你一定要hold住。 "Am I the only person on this planet who wants to write MS Word files with Java?" - Me, after researching Jacob, POI, WordBean and others, all to no informational avail. “难道我是这个星球上唯一的一个愿意使用Java操作Microsoft Word文件的人吗?” -我在研究Jacob,POI,WordBean和其他开源插件后发现没有好的帮助信息可以供我使用。 Jacob介绍 Jacob is a Java/COM bridge provided by Dan Adlerunder a semi GPL license (may not be used in a commercial product targetted at java developers, e.g. virtual machines, debuggers. The chance that you are not allowed to use it is very slim). Jacob是在半GPL许可证约束下的java/COM桥接软件,作者是Dan Adler.注:半GPL许可证是使用者不允许将软件应用于java开发的商业化软件中,比如虚拟机、调试器等。但是你不被允许使用的机会是很小的。 There is no documentation available concerning the practical use of any Microsoft applications; it is, so Adler, intended as a generic Java/COM bridge and not some MS Office API. However, M. Bigatti made a FAQ, which IMHO is not too useful when it comes to MS Word; and there is a Jacob Mailing List, where I got most of my information, even if it was tedious work. 这里没有任何关于微软产品的实际使用的说明;因此,作者的想法是想它作为一个通用的java/COM桥组件,而不是作为一个操作word的API。然而,M. Bigatti提出了一个问题,恕我直言它对于解决word的问题是不是太有用了;并且有一个Jacob邮件列表,在哪里我得到了大部分的信息,尽管这个工作单调和乏味。 Now, this is a tutorial entirely dedicated to the handling of Microsoft Word with Jacob. If you want Excel stuff, I would rather recommend POI, hosted at the Apache Foundationthey have good excel support, but only word scratchpad stuff. If you just need to insert some unformatted text, an easier solution is the WordBean by Mller&Stein. 现在,这是一个完全致力于使用Jacob对Word进行操作的指导材料。如果你希望使用Excel,那么我宁愿推荐你使用POI,由阿帕奇基金会维护的项目;POI由对Excel由很好的支持,但是在Word方面还有点欠缺。如果你只想插入一些没有格式的文字,那么可以使用一些简单点的解决方案,比如使用Mller&Stein编写的WordBean软件。 A good alternative to using Jacobmay be Jawin, which follows exactly the same goal, namely dispatching calls to COM objects. 还有一个Jacob的替代品是Jawin,这个遵循着与Jacob一样的目标,也是通过调用COM组件的方式调用的。 作者 This document is far from complete; I am always open for suggestions, tips and any enhancements. If you know something, please tell me. The absence of another site like this, in contrast to all the questions on JDC Search and Jacob Mailing list, imply that my page will be of some usability. My mail adress is kain at the above domain. 这篇文档要完成还要花费一段时间;我一直是采纳大家的意见、建议和一些改进方法。如果你知道关于这个方面的东西,请告诉我。在对比了JDC搜索和Jacob邮件列表里面的所有问题后,在喜欢这个网页的情况下我的文档还是有一定的可用性的。在上述域中我的邮箱地址是Kain. Update 2006-04: I had a nice email exchange with a guy named Jean Helou; he summarised his experiences with Jacob in a wiki documentation: it contains a section on macros, and is based on ms word xp. Also, he provided me with a link to the useful ms office object model documentation. Update 2006-04:我与一个叫Jean Helou的家伙又一段精彩的邮件交流;他在维基百科上面总结了他对Jacob的使用经验:是在基于XP系统中的Word关于宏的使用。他还提供给我一个关于微软对象模型文档的使用连接。 Update 2006-08: A nice girl named Kathrin Eichler emailed me a section on hyperlinks; it is included below. She is using Office XP. Thanks Kathrin! Update 2006-08:一位叫Kathrin Eichler的美女发给我了一份关于超链接使用的邮件;在下面有介绍。她使用的是xp版的office软件,感谢她。 |