jeecg根据模板自定义导出
//1.获取模板的路径:
String lujing = request.getSession().getServletContext().getRealPath("/")+ "export\\template\\test.xlsx";
//2.准备数据(一个List<Map<String, Object>>对象)
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
//3.读取InputStream流并且写入XSSFWorkbook中
InputStream in;
try {
in = new FileInputStream(new File(lujing1));
XSSFWorkbook work = null;
work = new XSSFWorkbook(in);
//4.把map里的值复写入Excel模板里
//获取第一个sheet
XSSFSheet sheetAt = work.getSheetAt(0);
//从第三行开始赋值
XSSFRow row = sheetAt.createRow(i+2);
row.createCell(0).setCellValue("");
//......依次循环赋值
//5.导出前台的一些设置
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel"); //保证不乱码
Date date=new Date();
SimpleDateFormat format=new SimpleDateFormat("MMddHHmmss");
String time="bb"+format.format(date)+".xlsx";//导出的Excel的名字
response.setHeader("Content-Disposition","attachment;" + " filename=" + new String(time.getBytes("utf-8"), "ISO-8859-1"));
ByteArrayOutputStream oss =new ByteArrayOutputStream();
OutputStream os = response.getOutputStream();
work.write(oss);
byte temp[] = oss.toByteArray();
ByteArrayInputStream in1 = new ByteArrayInputStream(temp);
int n = 0;
while ((n = in1.read(temp)) >0) {
os.write(temp, 0, n);
}
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
//附:引入的jar包的pom.xml依赖
<!-- poi start -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>jeasypoi-base</artifactId>
<version>${jeasypoi.version}</version>
<exclusions>
<exclusion>
<groupId>org.jeecgframework</groupId>
<artifactId>jeasypoi-annotation</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>jeasypoi-web</artifactId>
<version>${jeasypoi.version}</version>
<exclusions>
<exclusion>
<groupId>org.jeecgframework</groupId>
<artifactId>jeasypoi-base</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>jeasypoi-annotation</artifactId>
<version>${jeasypoi.version}</version>
</dependency>
<!-- poi end-->
最新文章
- Oracle体系结构总结
- sql 中实现往表中插入一条记录并返回当前记录的ID
- table插件实现
- vs2013_arcgis_developer_kit_101_install
- IOS中的网络编程
- 利用IronJs在.NET程序里面跑javascript脚本
- Nginx 笔记与总结(5)访问日志管理:计划任务 + 日志切割
- Android view的requestLayout()
- 域用户允许更改IP地址
- 让动态创建的ActiveX控件响应Windows消息
- 2014阿里实习生面试题——mysql如何实现的索引
- C++小技巧之CONTAINING_RECORD
- Jquery常用操作:checkbox、select取值,radio、checkbox、select选中及其相关
- Java SE学习笔记 --->;高级类特性 --->; toString() 方法
- 痞子衡嵌入式:飞思卡尔i.MX RT系列MCU开发那些事 - 索引
- docker服务各个模块
- 【转】Kaggle注册问题-验证码和手机短信
- ueditor保存出现 从客户端(Note=";<;p>;12345<;/p>;";)中检测到有潜在危险的 Request.Form 值
- SQL记录-解锁和dbms_job操作
- c++默认参数函数注意事项