正如标题所述,当我从文件夹下载Excel工作表时,我收到此消息
这是我的代码
RequestMapping(value = "/descargar-datos-entrada/{idSimulacion}", method = RequestMethod.GET)
public void descargarDatosEntrada(@PathVariable("idSimulacion") String idSimulacion, HttpServletResponse response)
throws IOException {
Properties properties = new Properties();
properties = Util.getProperties("mongo");
FileInputStream inputStream = null;
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=Hoja-Resultados-Descarga.xls");
try {
Simulacion simulacion = simulacionService.finById(idSimulacion);
inputStream = new FileInputStream(
properties.getProperty("ruta.copia.resultados.excel") + idSimulacion + ".xls");
int c;
while ((c = inputStream.read()) != -1) {
response.getWriter().write(c);
}
} catch (SimulacionException | IOException e) {
Util.autoLogError(e);
} finally {
if (inputStream != null)
inputStream.close();
response.getWriter().close();
}
}
结果.xls文件将如下所示:
我希望获得一些帮助或建议,在此先感谢您,这是我的第一个问题,请原谅,如果我提出的问题不正确。
用getOutputStream
执行二进制输出,而不是文本输出getWriter
:
Path path = Paths.get(properties.getProperty("ruta.copia.resultados.excel")
+ idSimulacion + ".xls");
Files.copy(path, response.getOutputStream());