0

I am using maven repository with dependency of apache poi-ooxml 3.15. I am not able to read/write due to error below.

My office is activated by the way.
Please help, Thanks

public static void saveIntoExcel(List<WebElement> title, List<WebElement> price) throws IOException, InvalidFormatException{

        File file = new File("./file/ReadExcel.xlsx");  
        FileOutputStream fis =  new FileOutputStream(file);

        XSSFWorkbook wb = new XSSFWorkbook(file);
        XSSFSheet sheet = wb.getSheetAt(0);     

        System.out.println(sheet.getPhysicalNumberOfRows());


        for(int i = 0; i < 30 ; i++){

            int j = 0;

                sheet.getRow(i+1).createCell(j).setCellValue(title.get(i).getText());
                sheet.getRow(i+1).createCell(j+1).setCellValue(price.get(i).getText());
                wb.write(fis);

        }

        wb.close();

 org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open XML) file
    at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:290)
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:774)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:308)
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
naqash
  • 63
  • 2
  • 6
  • See if this helps https://stackoverflow.com/questions/6758364/getting-exceptionorg-apache-poi-openxml4j-exception-no-content-type-m1-13 – Tarun Lalwani Sep 17 '17 at 19:04
  • This is not working actually. Please help ? – naqash Sep 18 '17 at 09:31
  • What is the file really? If you open it in Excel and do a save-as, what does Excel claim it to be? What happens if you run the Unix File utility or Apache Tika in `--detect` mode on it? – Gagravarr Sep 18 '17 at 20:54

1 Answers1

0

This exception is thrown when we try to open a file that doesn't seem to actually be an OOXML (Office Open XML) file after all. Reference from here

L.L Dong
  • 1
  • 1