8

I discovered Apache POI for doing a lot with MS Office programmatically in Java, but its documentation leaves me wanting, as well as a few other things. Does a better alternative exist?

I thought to myself that OpenOffice.org might have something, but cannot find any concise site that would have a Library that would allow you to open and store Word, Powerpoint, Excel, or other MS Office applications through Java.

Do any better alternatives exist?

Nicholas
  • 7,403
  • 10
  • 48
  • 76

5 Answers5

6

I think POI is the best among other libraries. I don't know the reason why you don't like it

Excel .xls & .xlsx

HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.

Word .doc & .docx

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. The partner to HWPF for the new Word 2007 .docx format is XWPF. Whilst HWPF and XWPF provide similar features, there is not a common interface across the two of them at this time.

anyway here are some libraries : Try Aspose and java2word

  • 1
    Yes, that was what I found, but I was just wondering if there were any alternatives. Thank you for the information. – Nicholas Jan 05 '11 at 21:40
  • 4
    I'm also looking for some alternatives, I recently worked with Excel and try to put a Chart in it and it was a real nightmare, POI is ok when working obnly with data but whet it comes to images and charts it is garbage – simonC Apr 18 '12 at 08:38
  • The thing is POI libraries and much of Apache libraries anyway, have a tendency to pollute jar files with bloat. – TheRealChx101 Apr 19 '20 at 08:05
  • 1
    Here some reasons to not use POI: it's slow and uses lots of memory. – bebbo Nov 24 '20 at 11:05
  • Since 3.8-beta3, POI provides a low-memory footprint SXSSF API built on top of XSSF. – kkk Jul 08 '21 at 14:48
  • Java2word has moved to https://github.com/leonardoanalista/java2word – Steve Eynon Jun 02 '22 at 16:30
3

On the Aspose.cells site they offer a comparison to its open source competitors.

http://www.aspose.com/docs/display/cellsjava/Aspose.Cells+for+Java+Vs+Open+Source+Competitors

They contrast with the following:

JExcelAPI POI-HSSF

Not an unbiased comparison probably but...

Mark D
  • 5,368
  • 3
  • 25
  • 32
2

I maintain docx4j, which is a strongly typed ASL v2 library for manipulating the XML file types (docx, pptx, xlsx) via JAXB.

If you also need to deal with the legacy binary formats (doc, ppt, xls), you'd need to pre-convert them to docx/pptx/xlsx before bringing docx4j to bear on them.

See more at Apache POI or docx4j for dealing with docx documents

Community
  • 1
  • 1
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
0

While POI does seem to be the go to option version 5.0 has become extremely bloated. Be prepared for your war files to be at least 10-15MB larger than with 4.x and no obvious way to build without all the cruft

Fred
  • 335
  • 1
  • 6
  • 22
  • 1
    As I'm the one responsible for the mentioned bloat, I think your answer misses a few points. If you still use POI in classpath mode it's easy to exclude unnecessary [components](http://poi.apache.org/components/index.html) - see component map. If you use modulepath mode, you would have problems if we don't include those dependencies, i.e. you would wonder which add-module options need to be added to the JVM. – kiwiwings Jul 15 '21 at 10:12
  • thanks @kiwiwings With the following exclusions I got the war file size close to previously size org.apache.xmlgraphics batik-all org.apache.santuario xmlsec org.bouncycastle * org.apache.pdfbox pdfbox – Fred Jul 16 '21 at 13:09
0

For Excel, I recommand JXLS http://jxls.sourceforge.net/index.html

Small Java library to interact with Excel files.

With jxls-reader (jxls-reader-2.0.5.jar 40Kb), for example, it's as simple as specifying mapping (xml) between your Bean and an Excel file - no overkill with poi plumbing (transtyping, character encoding, etc.)

No more headache sincerely

<?xml version="1.0" encoding="utf-8"?>
<workbook>
    <worksheet idx="0">
        <section startRow="0" endRow="0" />
        <loop startRow="1" endRow="1" items="mybeans" var="mybean" varType="MyBean">
            <section startRow="1" endRow="1">
                <mapping row="1" col="0">mybean.field1</mapping>
                <mapping row="1" col="1">mybean.field2</mapping>
                <mapping row="1" col="2">mybean.field3</mapping>
            </section>
            <loopbreakcondition>
                <rowcheck offset="0">
                    <!-- stop looping when content of cell[n,0] is empty -->
                    <cellcheck offset="0"></cellcheck>
                </rowcheck>
            </loopbreakcondition>
        </loop>
    </worksheet>
</workbook>