【发布时间】:2015-10-13 06:14:20
【问题描述】:
我正在阅读 .xltx,我想导出 .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");
}
当我导出时,.xlsx 在打开文件时总是给我一个错误,Excel 无法打开文件,因为格式或扩展名不正确。如果我将扩展名更改为 .xls,我可以打开它。
我正在使用 POI 3.12。
【问题讨论】:
标签: java excel apache-poi