Re: All my POI built Excel files are suddenly corrupt?

PJ Fanning <[email protected]> Thu, 10 Oct 2024 23:03:29 +0000 (UTC)
Newsgroups gmane.comp.jakarta.poi.user
Message-ID <[email protected]>
Could you try this (SXSSF only)?

workBook.setZip64Mode(Zip64Mode.Never);

Some tools may not be able to handle Zip64 mode.






On Thursday 10 October 2024 at 23:58:09 IST, Andreas Reichel <andreas@manti=
core-projects.com> wrote:=20





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 {
=C2=A0 =C2=A0 public static void main(String[] args) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // this will cause corruption
=C2=A0 =C2=A0 =C2=A0 =C2=A0 SXSSFWorkbook wb=C2=A0 =3D new SXSSFWorkbook(ne=
w XSSFWorkbook(), 100, true, true);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 SXSSFSheet sheet =3D wb.createSheet("test");

=C2=A0 =C2=A0 =C2=A0 =C2=A0 // This will work!
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // XSSFWorkbook wb =3D new XSSFWorkbook();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // XSSFSheet sheet =3D wb.createSheet("test");

=C2=A0 =C2=A0 =C2=A0 =C2=A0 File outputFile =3D null;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 try {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 outputFile =3D File.createTempFil=
e("poitest_", ".xlsx");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 FileOutputStream fileOutputStream=
 =3D new FileOutputStream(outputFile);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wb.write(fileOutputStream);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wb.close();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 } catch (IOException e) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 throw new RuntimeException(e);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 }
}