Caused by: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this dat

Olá, eu estou recebendo uma exceção ao tentar escrever escrever em um arquivo xlsx com a biblioteca Apache POI 3.16.

@FXML public void export() throws IOException{
		FileChooser fileChooser = new FileChooser();
		InputStream inp = new FileInputStream(fileChooser.showOpenDialog(this.getWindow()));
		FileOutputStream out = new FileOutputStream("C:\\Users\\Thallysson\\Desktop\\workbook.xlsx");	
	    POIFSFileSystem fs = new POIFSFileSystem(inp); 
		HSSFWorkbook wb = new HSSFWorkbook(fs);
		HSSFSheet s = wb.createSheet();
		Row r = null;
		org.apache.poi.ss.usermodel.Cell c = null;
		r = s.getRow(0);
		c = r.getCell(11);
		c.setCellValue("Thallysson");
		wb.write(out);
		out.close();
	}

Exceção:

Caused by: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
	at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:152)
	at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:140)
	at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:302)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:85)
	at controller.Controller.export(Controller.java:283)
	... 53 more

Controller.java:283:

POIFSFileSystem fs = new POIFSFileSystem(inp); 

Alguém sabe me explicar o que se passa por aqui?

Alguém?

Já tentou traduzir a mensagem de erro? me parece clara:
Vc está tentando abrir um documento do office 2007 ou superior. Onde aparentemente não pode. E que então deveria usar XSSF ao invés do HSSF.
Troque o POIFSFileSystem fs = new POIFSFileSystem(inp);
por:
XSSFWorkbook wb = (XSSFWorkbook) WorkbookFactory.create(inp);

Tá faltando pesquisa, apareceu isso nos primeiros resultados do google.

Cara, eu já tentei fazer isso. Foi a primeira coisa que eu tentei.
Mas aparentemente essa classe não existe.

Tenta:
Workbook wb = WorkbookFactory.create(myExcelFile);

WorkbookFactory também não existe.

Opaaaa, resolvi. Estava faltando alguns .jar :joy:. Realmente a solução era aquela, porém a classe não existia porque faltava .jar.