博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 动态导出excel表单 无模板本地生成
阅读量:3966 次
发布时间:2019-05-24

本文共 1395 字,大约阅读时间需要 4 分钟。

java 动态导出excel表单 无模板本地生成

这里使用的是alibaba的公共类excelWriter,注意在pom文件中要引入easyExcel的依赖

public void exportExcel(Long signupId){        MettingSignup mettingSignup = mettingSignupService.getById(signupId);        // 文件输出位置        String outPath = "D:\\"+mettingSignup.getPageName()+".xlsx";        List
> mapLists = signupUserinfoService.selectBySignupId(signupId,1,1000); try ( FileOutputStream fileOutputStream = new FileOutputStream(outPath); ) { // 所有行的集合 List
> list = new ArrayList
>(); ExcelWriter excelWriter = EasyExcelFactory.getWriter(fileOutputStream); // 表单 Sheet sheet = new Sheet(1,0); sheet.setSheetName("报名表单"); // 创建一个表格 Table table = new Table(1); // 动态添加 表头 headList --> 所有表头行集合 List
> headList = new ArrayList
>(); List
mapList = formTemplateService.selectFormTitleBySignupId(signupId); // 第 n 行 的表头 for (Map map:mapList) { List
headTitle = new ArrayList
(); headTitle.add((String) map.get("form_title")); headList.add(headTitle); } table.setHead(headList); // 第 n 行的数据 for (Map
maps : mapLists) { List
row = new ArrayList(); for (Map map:mapList) { row.add(maps.get(map.get("form_title"))); } list.add(row); } excelWriter.write1(list,sheet,table); // 记得 释放资源 excelWriter.finish(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }

转载地址:http://ujyki.baihongyu.com/

你可能感兴趣的文章
用户态切换到内核态的3种方式
查看>>
内核库函数
查看>>
Linux 系统内核空间与用户空间通信的实现与分析
查看>>
64位int类型用printf输出问题
查看>>
进程的状态转换
查看>>
如何查看进程的信息(线程数)
查看>>
Linux中的chage命令
查看>>
linux-详细解析密码文件passwd与shadow
查看>>
su- 与su的区别
查看>>
linux下发邮件mail
查看>>
echo如何手动输出换行
查看>>
身份证的正确使用方法——非常重要的知识
查看>>
ExtJS & Ajax
查看>>
Tomcat在Windows下的免安装配置
查看>>
JMeter常用测试元件
查看>>
JMeter——使用技巧
查看>>
Hibernate 实体层设计--Table per subclass
查看>>
Ruby解决方案:The 'ffi' native gem requires installed build tools ; 含最新DevKit下载地址
查看>>
Python之操作MySQL数据库(二)
查看>>
简单介绍如何使用robotium进行自动化测试
查看>>