Reputation: 497
Was trying to implement an excel export feature on an app using apache POI 3.17.
All was working fine on my local tomcat server and on a windows dev environment. However, the SXSSFWorkbook workbook.createSheet() method fails on a linux tomcat server without throwing any kind of meaningful error (it's just hanging).
Strangely, the same method on the XSSFWorkbook createSheet class works fine. Below are the snippets of code. Has anyone experienced a similar issue before?
final SXSSFWorkbook workbook = new SXSSFWorkbook();
workbook.setCompressTempFiles(true);
SXSSFSheet sheet = workbook.createSheet("Sheet 1"); //this method fails
final XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1"); // this works fine
Edit
I created a custom TempFileCreationStrategy to ensure tomcat is writing the file to a directory it has full access to. I can see the file has been created but it's hanging as it tries to write any data to the file.
I cannot figure this one out.
Edit2
I've enabled POI logging but it I'm still not getting anything meaningful that I can investigate. On my local server POI logging spits out the following as it begins to write the file:
[20:13:05,005]DEBUG (?:?) - Save core properties part
[20:13:05,005]DEBUG (?:?) - Save package relationships
[20:13:05,005]DEBUG (?:?) - Save content types part
[20:13:05,005]DEBUG (?:?) - Save part 'docProps/app.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'docProps/core.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/sharedStrings.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/styles.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/workbook.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/worksheets/sheet1.xml'
On the Linux box, it's not even getting as far as the first log output. Need to find a way to get more detail about the failure!
Edit3
Is it possible to get more detailed logging beyond the default logging I have enabled below?
System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger" );
String tmpDir = System.getProperty("java.io.tmpdir")+File.separator+"excelfiles";
ExcelFileCreationStrategy tfcs = new ExcelFileCreationStrategy();
try {
tfcs.createTempDirectory(tmpDir);
} catch (IOException e) {
e.printStackTrace();
LOG.error(e);
}
TempFile.setTempFileCreationStrategy(tfcs);
final SXSSFWorkbook workbook = new SXSSFWorkbook();
workbook.setCompressTempFiles(true);
LOG.debug("creating work sheet - next line fails");
Sheet sheet = workbook.createSheet(); //hangs here
LOG.debug("It's worked!!!!");
Upvotes: 8
Views: 4819
Reputation: 182
I had the same problem and after a long time of debugging and analysis, the "bug" is that when streaming, it tries to use the font to determine the width of the characters to adjust the columns. This fails without a message and simply aborts the creation if the font cannot be created / determined. The only solution I could find was to install the package "fontconfig".
sudo apt-get update
sudo apt-get install fontconfig
Without the package java unfortunately cannot work with java.awt.Fonts.
Upvotes: 0
Reputation: 449
I have checked with strace what happens under the hood, and the relevant output was:
11924 openat(AT_FDCWD, "/tmp/out.bin", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 48
11924 openat(AT_FDCWD, "/tmp/poifiles/poi-sxssf-template2618545805950425148.xlsx", O_RDWR|O_CREAT|O_EXCL, 0666) = 49
11924 openat(AT_FDCWD, "/tmp/poifiles/poi-sxssf-template2618545805950425148.xlsx", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 49
11924 openat(AT_FDCWD, "/tmp/poifiles/poi-sxssf-template2618545805950425148.xlsx", O_RDONLY) = 49
11924 openat(AT_FDCWD, "/tmp/poifiles/poi-sxssf-sheet-xml261863645047955641.gz", O_RDONLY) = 21
I guess you need to make sure the /tmp/poifiles
is writable by your user. However in my case when I make it non-writable, the app won't hang, but instead throws IOException
.
Or, if your java.io.tmpdir
is not /tmp
, I guess you need to make sure your poifiles
subdirectory inside java.io.tmpdir
is writable.
Upvotes: 1