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("导出数据有误");
    }
    }
    }

  • 相关阅读:
    P1410 子序列 (动态规划)
    P2085 最小函数值 (堆)
    [ZJOI2007]棋盘制作 (单调栈,动态规划)
    [ZJOI2005]午餐 (贪心,动态规划)
    黑匣子_NOI导刊2010提高 (对顶堆)
    [BZOJ1455] 罗马游戏 (左偏树||并查集)
    P1651 塔 (动态规划)
    两类斯特林数 (组合数学)
    从编程到工程
    失败的过程也是过程
  • 原文地址:https://www.cnblogs.com/shenggege5240/p/9041512.html
Copyright © 2011-2022 走看看