zoukankan      html  css  js  c++  java
  • 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("导出数据有误");
    }
    }
    }

  • 相关阅读:
    从应用到平台,云服务架构的演进过程
    从应用到平台,云服务架构的演进过程
    武汉小猫科技-工作总结(1):一图胜万言
    武汉小猫科技-工作总结(1):一图胜万言
    一个App带你学会Retrofit2.0,麻麻再也不用担心我的网络请求了!
    关于创业公司产品开发原则
    关于创业公司产品开发原则
    【Deep learning book】
    【NLP】word2vec
    【python】好书
  • 原文地址:https://www.cnblogs.com/shenggege5240/p/9041512.html
Copyright © 2011-2022 走看看