• 将 excel 导出到指定的路径 play!


    /**
         * 导出验证用户的操作日志的表格
         *
         * @throws Exception
         */
        public static void exportWeChatUserLogs(String searchCriteria) {
            // 根据需求生成excel表格
            HSSFWorkbook wb = createHSSFWorkbook(searchCriteria);

            Date dt = new Date();// 如果不需要格式,可直接用dt,dt就是当前系统时间
            DateFormat df = new SimpleDateFormat(Const.TIME_FORMATE);// 设置显示格式
            String nowTime = "";
            nowTime = df.format(dt);
            // 设置默认的保存文件的文件名:当前时间戳.xls格式
            String filename = nowTime + Const.EXCEL_FORMATE;
            // 这里存放的是指定的目录data(一般是从配置文件中读取)
            String filePath = Play.applicationPath + Const.FILE_EXCEL_PATH;
            File dirFile = new File(filePath);
            if (!dirFile.exists()) {
                dirFile.mkdirs();
            }
            try {
                // 输出文件流
                FileOutputStream fout = new FileOutputStream(filePath + "/" + filename);
                wb.write(fout);
                fout.flush();
                fout.close();
                // 保存到指定文件夹的文件中
                File file = new File(filePath + "/" + filename);
                // 返回文件,让用户下载
                renderBinary(file);
            } catch (Exception e) {
                e.printStackTrace();
                // 返回操作失败,请重新操作的提示语
                // 出错时,直接跳到微信用户操作日志展示的页面
                flash.put(Const.MSG_ERROR, Messages.get("export_excel_fail"));
                weChatUserStatisticalLogs(0, searchCriteria);
            }
        }

  • 相关阅读:
    javase程序设计上机作业2
    操作系统课堂笔记——01,操作系统介绍
    javase程序设计上机作业1
    Matlab学习笔记1—MATLAB基础知识
    Matlab学习笔记0—课程导入
    【转】WEB技术发展简史
    leetcode-79-单词搜索(用dfs解决)
    leetcode-78-子集(用bfs解决)
    leetcode-74-搜索二维矩阵
    leetcode-46-全排列
  • 原文地址:https://www.cnblogs.com/xunfang123/p/4224331.html
Copyright © 2020-2023  润新知