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实现 ...
随机推荐
- Linux入门基础
计算机及运维介绍 如何学习Linux 要想学好任何一门学问,不仅要眼睛看,耳朵听,还要动手记,勤思考,多交流甚至尝试着去教会别人 1.1 运维核心职责 网站数据不能丢 网站7*24小时运行 提升用户体 ...
- shell脚本编程进阶及RAID和LVM应用1
bash脚本编程 脚本文件格式: 第一行,顶格写: #!/bin/bash 注释行:#开头 代码注释:写清楚注释 规范写脚本:适度缩进,添加空白行 编程语言:有编程语法格式,库,算法和数据结构 编程思 ...
- Centos7下搭建WebGoat 8和DVWA环境
搭建WebGoat 安装前置条件说明 我们这里选择WebGoat的jar版本,由于WebGoat 8的jar文件已自带了tomcat和数据库,所以不需要再另外安装tomcat和mysql这种东西,只需 ...
- LoadRunner(7)
一.参数化策略 1.Select next row(How? 如何取?)取值方式 选择下一行 1)Sequential:顺序的 每个VU都从第一行开始,顺序依次向下取值: 数据取完可以从头循环重复使用 ...
- 详解mpstat等性能监测命令的使用
mpstat是Multiprocessor Statistics的缩写,是实时监控工具,报告与cpu的一些统计信息这些信息都存在/proc/stat文件中,在多CPU系统里,其不但能查看所有的CPU的 ...
- bat 判断命令是否执行成功
bat 判断命令是否执行成功 连接符形式,&& 表示成功,|| 表示失败,例如: call xxx.bat && (goto succeed) || goto fail ...
- fonts/font-awesome-woff2 404问题
报错环境: vue 开发的项目 npm 引入的font-awesome, 页面正常显示,就是控制台会报这个错误 产生原因:因为服务器IIS不认SVG,WOFF/WOFF2 这几个文件类型,只要在IIS ...
- [转载]ac mysql 无法远程连接
Mac mysql 无法远程连接 2018年07月23日 10:56:02 feixiang2039 阅读数 2866 版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附 ...
- Windows下安装配置Apache+PHP+Mysql环境
1.下载相关安装包 Apache下载: http://archive.apache.org/dist/httpd/binaries/win32/ ,选择httpd-2.2.25-win32-x86-n ...
- PHP函数相关知识点
回调函数 <?php function myfunc($funcname,$name) { $name = "喜欢".$name; $funcname($name); } f ...