美文网首页
Excel导出时乱码显示

Excel导出时乱码显示

作者: 爱恨_交加 | 来源:发表于2021-12-28 16:54 被阅读0次

文件格式和拓展名不匹配

打开导出的excel文件提示其文件格式和拓展名不匹配。点击“是”后,其内容是乱码。

后端代码如下:

    @GetMapping({"/export"})
    public ResponseEntity<byte[]> export(AlarmTiredNoticeDetailExportForm form) throws IOException {
        ...
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ExcelUtils.write(result, mapping(), "严重疲劳通知详情", stream);
        ResponseEntity<byte[]> response = ServletUtils.getFileResponse(fileName, stream.toByteArray());
        stream.close();
        return response;
    }

最后问题定位在前端
前端需要在请求中添加如下参数:

responseType: 'blob'

相关文章

网友评论

      本文标题:Excel导出时乱码显示

      本文链接:https://www.haomeiwen.com/subject/xbipqrtx.html