Reputation: 989
I am reading .xltx and I want to export .xlsx.
protected static final String ruta = ResourcesPathEnum.ROOT.getId() + "plantillas" + File.separator;
public static final String CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
protected abstract Workbook xlsx() throws FileNotFoundException, IOException;
/**
* Genera excel
*
* @return InputStream
*/
public InputStream getFile() {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
xlsx().write(bos);
} finally {
bos.close();
}
return new ByteArrayInputStream(bos.toByteArray());
} catch (FileNotFoundException e) {
Logger.error(e.getMessage());
} catch (IOException e) {
Logger.error(e.getMessage());
}
return null;
}
public StreamedContent getFile() {
ControllerReportSuceso aux = new ControllerReportSuceso(suceso, sucesosAvionWrapper);
return new DefaultStreamedContent(aux.getFile(), ControllerReportSuceso.CONTENT_TYPE, "parte suceso: " + suceso.getEntidad().getNumeroOrden() + ".xlsx");
}
When I export, .xlsx always give me a error when open the file, that Excel cannot open file because format or extension is not correct. If I change extension to .xls I can open it.
I am using POI 3.12.
Upvotes: 3
Views: 1307