easyExcel导出

postman导出可能会出现导出文件名中文乱码
可以用浏览器测试


@Override
    public void printLopStatistical(HttpServletResponse response, LopReportStatisticalRequest statisticalRequest) {
        //查询数据
        List<LopReportStatisticalResponse> responseList = queryLopStatistical(statisticalRequest);
            List<LopReportStatisticalExcel> statisticalExcels = BeanUtil.convert(responseList, LopReportStatisticalExcel.class);
            // 表头样式
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            // 设置表头居中对齐
            headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            // 内容样式
            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
            // 设置内容靠左对齐
            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
            try {
                String fileName = "lop清单统计数据";
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
                response.setHeader("Content-disposition", "attachment;filename=" +
                        URLEncoder.encode(fileName, "UTF-8") + "-" + DateFormatUtils.format(new Date(), "yyyyMMddhhmmssSSS") + ".xlsx");
                EasyExcel.write(response.getOutputStream(), LopReportStatisticalExcel.class).excelType(ExcelTypeEnum.XLSX).sheet("lop清单统计数据")
                        .registerWriteHandler(horizontalCellStyleStrategy).doWrite(statisticalExcels);
            }catch (IOException e){
                throw new ServiceException(QmsErrorEnum.EXCEL_EXPORT_ERROR);
            }


    }

你可能感兴趣的:(java,开发语言)