• excel导出出现弹框


    @RequestMapping(value = "exportExcel")
    public void exportExcel(@Valid Date startPayDate, @Valid Date endPayDate,
    HttpServletResponse response) {
    String startDate = null;
    String endDate = null;
    String context = "";
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    if(startPayDate == null && endPayDate != null){
    endDate = sf.format(endPayDate);
    context = "(到"+endDate+"为止)";
    }else if(startPayDate != null && endPayDate == null){
    startDate = sf.format(startPayDate);
    context = "("+startDate+"至今)";
    }else if(startPayDate != null && endPayDate != null){
    startDate = sf.format(startPayDate);
    endDate = sf.format(endPayDate);
    context = "("+startDate+"至"+endDate+")";
    }
    //中文会出现乱码,将其换成中文格式输出
    String zhStr = "商品订单详情";
    String filename = null;
    try {
    /* 根据request的locale 得出可能的编码,中文操作系统通常是gb2312 */
    filename = new String(zhStr.getBytes("GB2312"), "ISO_8859_1");
    context = new String(context.getBytes("GB2312"), "ISO_8859_1");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    zhStr = filename+context;
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition",
    "attachment;filename="+zhStr+".xlsx");
    OutputStream out = null;
    try {
    out = new BufferedOutputStream(response.getOutputStream());
    ExportExcel excel = shopUserOrderService.exportExcel(startPayDate,
    endPayDate);
    excel.write(out);
    } catch (Exception e) {
    throw new RuntimeException("系统异常");
    } finally {
    try {
    out.flush();
    out.close();
    } catch (Exception e) {
    throw new RuntimeException("导出数据有误");
    }
    }
    }

  • 相关阅读:
    从远程库克隆(转载)
    添加远程库(转载)
    远程仓库(转载)
    maven+hudson构建集成测试平台
    maven_基本配置
    crawler_基础之_httpclient 访问网络资源
    crawler_jsoup HTML解析器_使用选择器语法来查找元素
    oracle_job 清空冗余数据 ,每一分钟执行一次
    oracle_根据ID(字符型)建立分区表
    crawler_基础之_java.net.HttpURLConnection 访问网络资源
  • 原文地址:https://www.cnblogs.com/shenggege5240/p/9041512.html
Copyright © 2020-2023  润新知