Excel文件导出工具类

Excel文件导出工具类

/**
 * 输出Excel文件
 *
 * @param response 响应通道
 * @param falg     模板对象
 * @return ExcelWriterSheetBuilder
 */
public static <T> ExcelWriterSheetBuilder WriteAFileExcel(HttpServletResponse response, Class<? extends T> falg) {
    try {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
        ExcelWriterSheetBuilder sheet = EasyExcel.write(response.getOutputStream(), falg).sheet(String.valueOf(DateTime.now().getTime()));
        return sheet;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

文件导出,直接响应和泛型即可完成导出

THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容