使用Spring提供的一个下载Office文档的接口报错(具体是使用Apache POI生成OfficeExcel和Word文件),直接输出到HttpServletResponse的OutputStream流,如下报错:
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/core.xml failed to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@f598ff7 at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:554) at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1505) at org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:242)
直接生成的Office(World或者Excel),输出到HttpServletResponse的OutputStream流
改成套一个BufferedOutputStream,起到一个缓存的作用,例如:
OutputStream out = response.getOutputStream(); template.writeAndClose(new BufferedOutputStream(out)); // 原来是 template.writeAndClose(out); out.flush();
文章评论