Java操作MS Word和Excel文档

来源:互联网 发布:淘宝市场行情出租 编辑:程序博客网 时间:2024/05/10 21:10

能通过Java来操作Word或者Excel的api,据我所知的有这些,都考察了一下,开源的除了Openoffice和officewriter对Word的表格有好的支持外,其他都很不专业,或者不支持。

jacob http://sourceforge.net/projects/jacob-project/

JACOB is a JAVA-COM Bridge that allows you to call COM Automation components from Java. It uses JNI to make native calls to the COM libraries. JACOB runs on x86 and x64 environments supporting 32 bit and 64 bit JVMs

 

 

docx4j http://dev.plutext.org/trac/docx4j

docx4j is our library for unzipping a docx "package", and parsing the WordprocessingML XML to create an in-memory representation in Java.

It is available under the Apache License (v2).

This library is used by the plutext collaboration server, and the docx4all editor.

The library is designed to round trip docx files with 100% fidelity, and supports all WordML.

 

jxl http://jexcelapi.sourceforge.net/

 

poi http://poi.apache.org/

 

Aspose.Words http://www.aspose.com/ 付费产品

Aspose.Words for Java, it runs on any OS where Java is installed.

It will output the document to DOC, DOCX or RTF if you need an MS Word output format. All are supported equally well.

Using this API you can create a document from scratch, literally from nodes and set their formatting properties. You can also use a DocumentBuilder which provides higher level methods such as create a table row, insert a field etc. Or you can copy/join/move portions between existing pre created document, say you want to assemble a contract, just grab and copy pieces from several documents and Aspose.Words will merge styles, list formatting etc properly in the resulting document.

You will be able to insert a TOC field using Aspose.Words, but as of today, the TOC field will require a field update when the document is opened in Microsoft Word. However, we are going to release full support for TOC fields early in 2010. E.g. it will build complete TOC as MS Word does it.

openoffice http://www.openoffice.org/

 

officewriter http://officewriter.softartisans.com/officewriter-240.aspx 付费产品

 

SoftArtisans OfficeWriter is a pure Java™ reporting tool that generates real Excel and Word reports from your J2EE™ application without any dependency on Microsoft Office. Because it is designed specifically for server-side development and high-request Web server environments, OfficeWriter easily scales to meet your reporting needs.

With OfficeWriter, Java™ developers can create applications that deliver presentation-quality reports in just minutes. Excel or Word reports can be populated with data from a variety of sources, including JDBC ResultSets from popular databases (MSSQL, Oracle, MySQL, DB2, etc) or any data that can be contained in a Java™ object.

OfficeWriter is compatible with any server's operating system and, through industry partnerships with companies such as IBM and Sun Microsystems, you can be assured that OfficeWriter supports the latest development environments and platforms. OfficeWriter libraries are simple to add to a variety of J2EE™-compliant application servers, including Apache Tomcat, IBM WebSphere and BEA WebLogic, so integration is always seamless.

iText http://itextpdf.com/

iText is a library that allows you to generate PDF files on the fly.

iText is an ideal library for developers looking to enhance web- and other applications with dynamic PDF document generation and/or manipulation. iText is not an end-user tool. Typically you won't use it on your Desktop as you would use Acrobat or any other PDF application. Rather, you'll build iText into your own applications so that you can automate the PDF creation and manipulation process. For instance in one or more of the following situations:

  • Due to time or size, the PDF documents can't be produced manually.
  • The content of the document must be calculated or based on user input.
  • The content needs to be customized or personalized.
  • The PDF content needs to be served in a web environment.
  • Documents are to be created in "batch process" mode.

You can use iText to:

  • Serve PDF to a browser
  • Generate dynamic documents from XML files or databases
  • Use PDF's many interactive features
  • Add bookmarks, page numbers, watermarks, etc.
  • Split, concatenate, and manipulate PDF pages
  • Automate filling out of PDF forms
  • Add digital signatures to a PDF file
  • And much more...

In short: the iText classes are very useful for people who need to generate read-only, platform independent documents containing text, lists, tables and images; or who want to perform specific manipulations on existing PDF documents. The library is especially useful in combination with Java(TM) technology-based Servlets; there's also a .NET port available: iTextSharp (written in C#).

iText requires Java 5. It's available for free under the GNU Affero General Public License (see the Terms of Use).

javadocx http://www.javadocx.com/ 付费产品(There is a free (LGPL) version.

JAVADOCX is a JAVA library designed to dynamically generate reports in Word format (WordprocessingML).

The reports may be built from any available data source like a HSQLDB, Oracle or MySQL database or a spreadsheet. The resulting documents remain fully editable in Microsoft Word (or any other compatible software like Open Office) and therefore the final users are able to modify them as necessary.

The formatting capabilities of the library allow the programmers to generate dynamically and programmatically all the standard rich formatting of a typical word processor.

This library also provides an easy method to generate documents in other standard formats such as PDF or HTML.

What can I do with JAVADOCX ?

With a few lines of code you can generate a complete report that includes:

  • Standard paragraphs
  • Bulleted or numbered lists
  • Customized tables
  • All kind of editable charts and graphs to display numerical data
  • Tables of content to simplify readability within long documents
  • Headers that will reflect your corporate branding
  • Footers with automatic page numbering
  • Graphic elements

JAVADOCX allows programmers to generate documents in a fast and convenient way when used with its default settings.

When design is a priority, JAVADOCX allows you to generate fully customized reports to match your company's branding or your previously created design.

JODConverter http://sourceforge.net/projects/jodconverter/

JODConverter automates conversions between office document formats using OpenOffice.org. Supported formats include OpenDocument, PDF, RTF, Word, Excel, PowerPoint, and Flash. It can be used as a Java library, a command line tool, or a Web application.

 

 

至于各个API的好坏,就开发者自己掂量了,不过对Word支持的都比较弱(比如表格的操作),而对Excel的支持强。Openoffice,officewriter和Aspose.Words对Word中的表格的支持比较专业。像POI就很不成熟,据说其主要开发人员没有再参与此事了。JXL操作Excel很不错,Jacob就是个COM桥,操作已有的文档或者根据模板来操作比较理想。

 

MS Office 2007以上版本的.doc and .xls文件似乎是压缩的XML文件,所以高人似乎有直接解析XML,读写XML来搞定.doc and .xls文件的操作的。

 

其实有些报表工具也有导出Word、Excel文件的功能,搞WEB开发的人肯定很熟悉这些。也可以直接把输出流给定义成Word or Excel 文件流, e.g. Render an HTML page with the MIME type set to "application/msword"

 

原创粉丝点击