0

I have a problem. I wrote a little program for a friend. I read a .xlsx-file and update this. In the IDE it works well. But if i build a .jar and execute it, then i get the error "Your InputStream was neither an OLE2 stream, nor an OOXML stream or you haven't provide the poi-ooxml*.jar in the classpath/modulepath".

There are abstracts of my code:

//Import Excel
public static ImportDaten importExcel() throws IOException {
        ImportDaten importDaten = new ImportDaten();
        java.util.List<Kunde> kunden = new ArrayList<>();
        List<Artikel> artikelList = new ArrayList<>();
        DataFormatter dataFormatter = new DataFormatter();
        File inputWorkbook = new File("C:/Users/jboeh/OneDrive/Desktop/stammdaten.xlsx");
        Workbook workbook = WorkbookFactory.create(inputWorkbook);
        //Rechnungsnummer einlesen
        Sheet indexSheet = workbook.getSheet("Index");
        
        //read data

        workbook.close();

        importDaten.setKunden(kunden);
        importDaten.setArtikelList(artikelList);
        return importDaten;
    }

public static void exportExcel() throws IOException {

        FileInputStream inputStream = new FileInputStream(new File("C:/Users/jboeh/OneDrive/Desktop/stammdaten.xlsx"));
        Workbook workbook = WorkbookFactory.create(inputStream);

        Sheet sheetIndex = workbook.getSheet("Index");
        Cell zelleRechNr = sheetIndex.getRow(0).createCell(1);
        zelleRechNr.setCellValue(rechnung.getRechnungsnr());

        Sheet sheetRechnung = workbook.getSheet("Rechnung");

        Cell zelleRechnung;

        //write Data

        inputStream.close();

        FileOutputStream outputStream = new FileOutputStream("C:/Users/jboeh/OneDrive/Desktop/stammdaten.xlsx");
        workbook.write(outputStream);
        workbook.close();
        outputStream.close();
    }

I hope somebody can help me.

Thanks

Mira

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
MiraSnow
  • 1
  • 1
  • Try converting your `FileInputStream` to a `BufferedInputStream`. *Your input stream MUST either support mark/reset, or be wrapped as a BufferedInputStream!*-[Apache POI WorkbookFactory documentation](https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/WorkbookFactory.html;). Try putting `BufferredInputStream buffStream = new BufferedInputStream(inputStream);` right after your inputstream and pass it into the factory. [Reading files with BufferedInputStream](https://mkyong.com/java/how-to-read-file-from-java-bufferedinputstream-example/). – Alias Cartellano Sep 29 '21 at 19:44
  • 1
    You haven't provided any info on how built the jar. Is it a fat jar (cf You haven't provided any info on how built the jar. Is it a fat jar (cf https://www.baeldung.com/gradle-fat-jar) or a standard jar? If it's a standard jar, you need to include the poi jars and their dependencies on your classpath. – PJ Fanning Sep 29 '21 at 19:46
  • I tried an BufferedInputStream, but it also doesn't work. I read, that you should not use an stream for files to update. So i changed it and use not anywhere an inputStream. But the error is still present. I don't know why. I can't explain it. It is a standard jar. I forget the poi jar. I fixed it, but the error is still present too. – MiraSnow Oct 02 '21 at 20:34
  • Maybe try the answer to this question:[SO: Your InputStream was neither an OLE2 stream, nor an OOXML stream or you haven't provide the poi-ooxml*.jar in the classpath/modulepath](https://stackoverflow.com/questions/29236294/getting-error-your-inputstream-was-neither-an-ole2-stream-nor-an-ooxml-stream). If it still doesn't work try downloading the poi-ooxml file and [adding it to the classpath in your jar's manifest file](https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html). – Alias Cartellano Oct 02 '21 at 21:07

0 Answers0