4

I've written module that generates excel, and deployed it under Servicemix. In Windows environment everything is fine, but under Linux Servicemix unexpectedly crashes on following call:

    for (short i=0;i<=3;i++) {
        log.trace("AutoSize column {}", i);
        worksheet.autoSizeColumn(i);
    }

I'm using POI version 4.2-FINAL, FuseESB 4.2, Java 5.0. There are, however, no hs_err*.pid files. Servicemix logs ends on first autoSizeColumn call.

Did anyone met such behaviour and know, how it is caused and how to come this around?

рüффп
  • 5,172
  • 34
  • 67
  • 113
Danubian Sailor
  • 1
  • 38
  • 145
  • 223

3 Answers3

6

In order to be able to calculate the column widths, POI needs to get hold of the Font in use, and ask it to size each character in turn. On all JVMs that I know of, this requires a graphical environment, because the actual work is delegated by the JVM to the underlying graphical system.

If you're on Windows, you always have a graphical system so that's fine. On Linux, if you're running on the command line on a server, you may not. (Linux as a desktop is fine though)

If you are running on a linux server without an X server running, you'll need to tell Java to run "headless". As taken from the POI AutoSize documentation

To calculate column width Sheet.autoSizeColumn uses Java2D classes that throw exception if graphical environment is not available. In case if graphical environment is not available, you must tell Java that you are running in headless mode and set the following system property: java.awt.headless=true

Try setting that when you start your JVM, and I've a hunch it'll fix your issue (which is most likely caused by Java not finding a complete graphical environment)

Gagravarr
  • 47,320
  • 10
  • 111
  • 156
2

We haven't tested it as it's not released yet, but since POI 5.2.3 there's a boolean system property that could help: org.apache.poi.ss.ignoreMissingFontSystem

Instructs Apache POI to ignore some errors due to missing fonts and thus allows to perform more functionality even when no fonts are installed. Note: Some functionality will still not be possible as it cannot use default-values, e.g. rendering slides, drawing, ...

bigstones
  • 15,087
  • 7
  • 65
  • 82
0

Hi I faced a similar problem. I didn't have any crash, but on my development environment (Windows) the autosizecolumn worked. On production environment (Unix-like) it didn't work. I put system property java.awt.headless=true but I had the problem still. I solved following this solution but I added all the Arial Family fonts. Hope it helps anyone.

Marco Luly
  • 333
  • 4
  • 8
  • Unfortunately, it does not as the link is no longer valid. That is why it is recommended to avoid using links to avoid an actual explanation – Tony BenBrahim May 31 '22 at 19:01
  • wayback machine to the rescue! https://web.archive.org/web/20190905110215/http://apache-poi.1045710.n5.nabble.com/HSSFSheet-autoSizeColumn-method-doesn-t-work-properly-on-Linux-system-td4270552.html – bigstones Aug 05 '22 at 07:38