关闭

对日志创建处理下载为excel格式的文件续(3) 下载

115人阅读 评论(0) 收藏 举报

//根据条件在数据库中找到日志信息并且设置到Excle表中

public boolean exportToTxt(File file, String level, String beginTimeStr, String endTimeStr) {

        List<PropertyFilter> filters = new ArrayList<PropertyFilter>();
        if (StringUtils.isNotBlank(level)) {
            PropertyFilter levelFilter = new PropertyFilter("EQ_level", LogLevel.valueOf(level));
            filters.add(levelFilter);
        }
        if (StringUtils.isNotBlank(beginTimeStr)) {
            Date beginTime = DateUtils.parseDate(beginTimeStr);
            PropertyFilter beginTimeFilter = new PropertyFilter("GT_date", beginTime);
            filters.add(beginTimeFilter);
        }
        if (StringUtils.isNotBlank(endTimeStr)) {
            Date endTime = DateUtils.parseDate(endTimeStr);
            PropertyFilter endTimeFilter = new PropertyFilter("LT_date", endTime);
            filters.add(endTimeFilter);
        }
        List<Log> logList = this.find(filters);
        WritableWorkbook workbook = null;
        try {
            workbook = Workbook.createWorkbook(file);
            WritableSheet sheet = workbook.createSheet("日志表", 0);
            initGridSize(sheet);
            initTitle(sheet);
            writeContent(logList, sheet);
            workbook.write();
        } catch (Exception e) {
            logger.error("create excel is field!", e);
            return false;
        } finally {
            closeWritableWorkbook(workbook);
        }
        return true;

    }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:40310次
    • 积分:877
    • 等级:
    • 排名:千里之外
    • 原创:52篇
    • 转载:8篇
    • 译文:1篇
    • 评论:0条
    文章分类