esayexcel下载问题

 /**
     * @description: 系统管理-下载导入用户分析结果excel文件
     * @return: 导入结果提示
     * @auther: wangwei
     * @date: 2020/4/11 15:05
     */
    @PostMapping("/download/analysis/result")
//    public ResultWrapper<Boolean> downloadAnalysisResult(@RequestBody RequestWrapper<String> data,
//    public void  downloadAnalysisResult(@RequestBody RequestWrapper<String> data,
//                                                         HttpServletRequest request,
//                                                         HttpServletResponse response) throws Exception {
//        List<ExportExcelUserVo> exportExcelUserVos = this.userCenterService.downloadAnalysisResult(data.getData());
    public void  downloadAnalysisResult(@RequestParam("resultJson") String resultJson,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        List<ExportExcelUserVo> exportExcelUserVos = this.userCenterService.downloadAnalysisResult(resultJson);
        ExcelWriter writer = null;
        OutputStream out = null;
        try {
            String fileName = "导入用户数据的反馈结果";
            final String userAgent = request.getHeader("USER-AGENT");
            if (userAgent.contains("MSIE") || userAgent.contains("Edge")) {// IE浏览器
                fileName = URLEncoder.encode(fileName, "UTF8");
            } else if (userAgent.contains("Mozilla")) {// google,火狐浏览器
                fileName = new String(fileName.getBytes(), "ISO8859-1");
            } else {
                fileName = URLEncoder.encode(fileName, "UTF8");// 其他浏览器
            }
            out = response.getOutputStream();
            writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

            Sheet sheet = new Sheet(1, 0, ExportExcelUserVo.class);
            sheet.setSheetName("导入用户数据的反馈结果");
            writer.write(exportExcelUserVos, sheet);
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");//导出xlsx格式
//            response.setContentType("application/vnd.ms-excel");//导出xls格式
            response.setCharacterEncoding("utf8");
            response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
            response.setHeader("Pragma", "public");
            response.setHeader("Cache-Control", "no-store");
            response.addHeader("Cache-Control", "max-age=0");
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                writer.finish();
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

 

 /**
     * @description: 系统管理-下载导入用户分析结果excel文件
     * @return: 导入结果提示
     * @auther: wangwei
     * @date: 2020/4/11 15:05
     */
    @PostMapping("/download/analysis/result")
//    public ResultWrapper<Boolean> downloadAnalysisResult(@RequestBody RequestWrapper<String> data,
//    public void  downloadAnalysisResult(@RequestBody RequestWrapper<String> data,
//                                                         HttpServletRequest request,
//                                                         HttpServletResponse response) throws Exception {
//        List<ExportExcelUserVo> exportExcelUserVos = this.userCenterService.downloadAnalysisResult(data.getData());
    public void  downloadAnalysisResult(@RequestParam("resultJson") String resultJson,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        List<ExportExcelUserVo> exportExcelUserVos = this.userCenterService.downloadAnalysisResult(resultJson);
        ExcelWriter writer = null;
        OutputStream out = null;
        try {
            String fileName = "导入用户数据的反馈结果";
            final String userAgent = request.getHeader("USER-AGENT");
            if (userAgent.contains("MSIE") || userAgent.contains("Edge")) {// IE浏览器
                fileName = URLEncoder.encode(fileName, "UTF8");
            } else if (userAgent.contains("Mozilla")) {// google,火狐浏览器
                fileName = new String(fileName.getBytes(), "ISO8859-1");
            } else {
                fileName = URLEncoder.encode(fileName, "UTF8");// 其他浏览器
            }
            out = response.getOutputStream();
            writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

            Sheet sheet = new Sheet(1, 0, ExportExcelUserVo.class);
            sheet.setSheetName("导入用户数据的反馈结果");
            writer.write(exportExcelUserVos, sheet);
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");//导出xlsx格式
//            response.setContentType("application/vnd.ms-excel");//导出xls格式
            response.setCharacterEncoding("utf8");
            response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
            response.setHeader("Pragma", "public");
            response.setHeader("Cache-Control", "no-store");
            response.addHeader("Cache-Control", "max-age=0");
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                writer.finish();
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

 

import com.alibaba.excel.converters.date.DateStringConverter;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.DateUtils;

import java.util.Date;

/**
 * @Description:
 * @Auther: wangwei
 * @Date: 2020/5/23 13:31
 */
public class MyDateConvert extends DateStringConverter {
    @Override
    public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {

        return value != null ? new CellData(DateUtils.format(value, "yyyy/MM/dd")) : new CellData(DateUtils.format(value, (String)null));
    }
}
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读