Re: All my POI built Excel files are suddenly corrupt?
Andreas Reichel <[email protected]> Fri, 11 Oct 2024 05:57:59 +0700
| Newsgroups | gmane.comp.jakarta.poi.user |
|---|---|
| Organization | manticore-projects Co. Ltd. |
| Message-ID | <63ea284d5ea79c7d7d4bfe76c5328ef3b7ca9b24.camel@manticore-projects.com> |
--=-mTs/HMtqt0NyOXnKhYYR
Content-Type: text/plain; charset="ISO-8859-15"
Content-Transfer-Encoding: 7bit
Greetings,
some more insight: It seems to be a POI SXSSF problem (only). The code
below creates an empty Excel file, which opens flawlessly when written
as XSSF but shows corruption message when written as SXSSF.
Although both files would open in Gnumeric without any problems.
Now what please?
Cheers
Andreas
package com.manticore;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
// this will cause corruption
SXSSFWorkbook wb = new SXSSFWorkbook(new XSSFWorkbook(), 100, true, true);
SXSSFSheet sheet = wb.createSheet("test");
// This will work!
// XSSFWorkbook wb = new XSSFWorkbook();
// XSSFSheet sheet = wb.createSheet("test");
File outputFile = null;
try {
outputFile = File.createTempFile("poitest_", ".xlsx");
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
wb.write(fileOutputStream);
wb.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
--=-mTs/HMtqt0NyOXnKhYYR--