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-->
jeecg根据模板自定义导出的更多相关文章
- Excel 按模板格式导出
最近遇到一个问题,就是导出数据的时候需要自定义的表头,如图 如果自己用代码写表头的话,可能会有点复杂,而且代码量很多,所以我就想了一个办法,直接在Excel里面把表头定义好,然后把数据写入Excel模 ...
- Freemaker基于word模板动态导出压缩文件汇总整理
Freemaker基于word模板动态导出压缩文件汇总整理 Freemaker基于word模板动态导出单个文件思路和代码详情见连接: https://www.cnblogs.com/lsy-blogs ...
- Freemaker基于word模板动态导出汇总整理
Freemaker基于word模板动态导出汇总整理 一.使用的jar包: 二.Word模板动态导出的基本思路: 1.首先通过自己在word中创建好需要导出的word文本+表格的模板,模板中需要填写内容 ...
- (原创)将Datatable数据按照Excel模板格式导出
最近遇到一个问题,就是导出数据的时候需要自定义的表头,如图 如果自己用代码写表头的话,可能会有点复杂,而且代码量很多,所以我就想了一个办法,直接在Excel里面把表头定义好,然后把数据写入Excel模 ...
- 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...
- (转) ThinkPHP模板自定义标签使用方法
这篇文章主要介绍了ThinkPHP模板自定义标签使用方法,需要的朋友可以参考下 转之--http://www.jb51.net/article/51584.htm 使用模板标签可以让网站前台开发 ...
- OpenCMS模板的导出和OpenCMS网站的导出
1.OpenCMS模板的导出 (1)切换到Administration视图,单击Module Management,如图所示: (2)导出位置:tomcat根目录\webapps\opencms\ ...
- python 全栈开发,Day70(模板自定义标签和过滤器,模板继承 (extend),Django的模型层-ORM简介)
昨日内容回顾 视图函数: request对象 request.path 请求路径 request.GET GET请求数据 QueryDict {} request.POST POST请求数据 Quer ...
- java操作Excel之POI(5)利用POI实现使用模板批量导出数据
后台导出方法: 在源文件夹src下面放个准备好的模板:/com/cy/template/userExportTemplate.xls,这个模板有头部一行: /** * 后台导出方法 * 利用POI实现 ...
随机推荐
- storm 的分组策略深入理解(-)
目录 storm的分组策略 根据实例来分析分组策略 common配置: Shuffle grouping shuffle grouping的实例代码 ShuffleGrouping 样例分析 Fiel ...
- python产生错误:can only concatenate str (not "int") to str
代码为: #!/usr/bin/python # _*_ coding:utf-8_*_ # print("hello world!") name = input("na ...
- 解决Ubuntu下ssh无法启动
Ubuntu ssh一直无法启动. 通过 systemctl status ssh.service 查看到的错误是 Dec 16 13:35:22 iZm5eckxl2tqyka9eoe7b3Z ...
- 通过shell发送邮件
安装mailx CentOS 7自带有mailx软件包, 有/usr/bin/mail命令, 配置文件为/etc/mail.rc. 如果没有软件包, 可以安装 CentOS/Fedora yum in ...
- QQ气泡效果剖析
对于QQ汽泡效果我想不用多说了,都非常的熟悉,而且当时这效果出来简直亮瞎眼了,挺炫的,这里再来感受下: 而这次只实现单个汽泡的效果,并不涉及到加入Listview上的处理,一步步来,先上一下最终这次要 ...
- jQuery.fn.extend() 函数详解
jQuery.fn.extend()函数用于为jQuery扩展一个或多个实例属性和方法(主要用于扩展方法). jQuery.fn是jQuery的原型对象,其extend()方法用于为jQuery的原型 ...
- P3254——DP&&入门
题目 给定一个$n \times m$的$01$矩形,选择其中为$1$的位置,要求互不相邻,问方案数. 解决方案 直接dp因为状态较多,数组很难直接表示出来,我们采用二进制状态压缩存储. 用$dp[i ...
- [2019HDU多校第一场][HDU 6590][M. Code]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6590 题目大意(来自队友):二维平面上有\(n\)个点,每个点要么是黑色要么是白色,问能否找到一条直线 ...
- mysql自增主键清零方法
MySQL数据库自增主键归零的几种方法 如果曾经的数据都不需要的话,可以直接清空所有数据,并将自增字段恢复从1开始计数: truncate table table_name; 1 当用户没有trunc ...
- 题解 [51nod1201] 整数划分
题面 解析 首先,因为是不同的数字, 可以从小到大依次枚举加上每一个数字的贡献,再枚举每个数. 然而这样会T掉... 考虑到\(n\)只有\(50000\), 当分成的数最多时,设最大的数为\(m\) ...