0

I have a bean with method to generate report made with jett:

Map<String, Object> beans = new HashMap<String, Object>();

    beans.put("fichasTecnicasMateriaPrimaResumo", fichasTecnicasMateriaPrimaResumo);

    try {

        InputStream inPath = ProdutoManagedBean.class.getResourceAsStream("/template.xls");

        ExcelTransformer transformer = new ExcelTransformer();
        transformer.transform(inPath, beans);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InvalidFormatException e) {
        e.printStackTrace();
    }

I'm having an InvalidFormatException in transformer.transfom (...):

22:44:37,803 ERROR [stderr] (default task-28) org.apache.poi.openxml4j.exceptions.InvalidFormatException: Your InputStream was neither an OLE2 stream, nor an OOXML stream

I saw that it might be regarding the compatibility of the xls file with the libreoffice, or something. Thank you for any help.

philabreu
  • 55
  • 1
  • 7
  • 1
    The error states it already: `Your InputStream was neither an OLE2 stream, nor an OOXML stream`. So your `template.xls` is neither a binary Excel file in `BIFF` format nor an Office OpenXML file. So your `template.xls` is not a file which can be read as an Excel file. Maybe it is a wrong named CSV file? Or a wrong named XML file? Excel itself is possibly able to open it then but the `ExcelTransformer` is not. – Axel Richter Sep 04 '17 at 03:38
  • Well I created a xls and xlsx in microsoft excel 2007 itself and it still gives the same error ... will it even be that the office excel file would be created wrong? Do you suggest any changes to the code? Is there nothing you can do in the code? @AxelRichter – philabreu Sep 04 '17 at 15:20
  • The error comes from [WorkbookFactory](https://svn.apache.org/viewvc/poi/tags/REL_3_14_FINAL/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?revision=1732982&view=markup#l196) and it only occurs if the first bytes in the `InputStream` are wrong. So if you doubt that your file is wrong, then something with the `InputStream` must be wrong. But that we cannot test without having your environment. – Axel Richter Sep 05 '17 at 03:47
  • Also please take care of the [JETT Requirements](http://jett.sourceforge.net/#Requirements), especially do not have mixed libraries of different `apache poi` versions but have **all** libraries of version `3.14`. – Axel Richter Sep 05 '17 at 03:47

1 Answers1

0

I discovered that xls is actually being corrupted by maven ... when I try to open the file that is in the wildfly deploy folder it has already been corrupted ... I have tried some solutions to solve this problem of data corruption but I have not yet found it nothing that worked, but at least I already know what the real mistake is. Thank you.

philabreu
  • 55
  • 1
  • 7