1、直接献出代码

Map<String,List<ConfidentialInformation>> typeMap = new HashMap<>();
try {
//设置导出
response.addHeader("Cache-Control","no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream;charset=UTF-8");
String ua = request.getHeader("user-agent");
ua = ua == null ? null : ua.toLowerCase();
String docFileName = dateMonth.toString()+"月凭证信息情况.zip";
if(ua != null && (ua.indexOf("firefox") > 0 || ua.indexOf("safari")>0)){
try {
docFileName = new String(docFileName.getBytes(),"ISO8859-1");
response.addHeader("Content-Disposition","attachment;filename=" + docFileName);
} catch (Exception e) {
}
}else{
try {
docFileName = URLEncoder.encode(docFileName, "utf-8");
response.addHeader("Content-Disposition","attachment;filename=" + docFileName);
} catch (Exception e) {
}
} ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(out); byte[]buffer=new byte[1024];
for (String names:typeMap.keySet()){
Map<String,Object> outMaps = new HashMap<>(); outMaps.put( "datac",typeMap.get( names ) ); //Excel处理成zip包
XLSTransformer transformer = new XLSTransformer();
String srcFilePath = request.getServletContext().getRealPath("/")+"/export/template/credentialReport.xls"; InputStream is = new BufferedInputStream(new FileInputStream(srcFilePath));
Workbook workbook =null; workbook = transformer.transformXLS(is, outMaps); //压缩包zip留。
ByteArrayOutputStream outtemp = new ByteArrayOutputStream();
workbook.write(outtemp);
ByteArrayInputStream bais =new ByteArrayInputStream(outtemp.toByteArray());
String nickname = ResourceUtil.getCacheDicDetail("apportion",names,"typename");
zipOut.putNextEntry(new ZipEntry(nickname+"凭证信息表.xls"));
int dataLen;
//读入需要下载的文件的内容,打包到zip文件
while((dataLen=bais.read(buffer))>0){
zipOut.write(buffer,0,dataLen); }
zipOut.closeEntry();
bais.close();
outtemp.close();
is.close(); }
zipOut.close();
out.close(); byte[] zipByte=out.toByteArray(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
toClient.write(zipByte);
toClient.flush(); }catch (Exception e){
e.printStackTrace();
}

  

jeecg项目将workbook 的Excel流添加到zip压缩包里导出的更多相关文章

  1. [java][JEECG] Maven settings.xml JEECG项目初始化 RouYi settings.xml配置

    好吧一下是经验之谈,原本这些坑不应该躺的,从头看手册完全可以避免这些. 懒得整理了,看懂了就看,看不懂自己琢磨JEECG的帮助文档去,不过嘛我喜欢用Intelij IDEA,他里面都是别的IDE,不喜 ...

  2. Excel中添加并使用宏实现批量更新数据

    一.状况描述    当我们需要后台更新大量数据的时候,可以使用该功能.二.解決方案    (1)新建一个Excel文件,并另存为启用宏的Excel工作簿,扩展名为.xlsm.    (2)在Excel ...

  3. Myeclipse的web项目移植到Eclipse中需要添加的包

    3.jstl.jar 4.standard-1.1.2.jar 把Myeclipse的web项目一直到Eclipse当中需要添加的包主要有一下4个: 1.servlet-api.jar 2.jsp-a ...

  4. jeecg项目子窗口获得父窗口元素id

    jeecg项目子窗口获得父窗口元素id, var parentWin = frameElement.api.opener;alert($(parentWin.document).find(" ...

  5. 给你的流添加缓冲装置——字节块ByteChunk

    这是一个很重要的一个字节数组处理缓冲工具,它封装了字节缓冲器及对字节缓冲区的操作,包括对缓冲区的写入.读取.扩展缓冲区大小等等,另外还提供相应字符编码的转码操作.此工具让缓冲操作变得更加方便,除了缓冲 ...

  6. iOS - UICollectionView 瀑布流 添加表头视图的坑

    UICollectionView 瀑布流 添加表头视图的坑 首先是,需求加了个头视图在顶部,在collectionView中的头视图跟TableView的不一样,TableView的表头只要设置tab ...

  7. excel怎么设置密码保护?Excel文件添加密码保护教程

    excel怎么设置密码保护?Excel文件添加密码保护教程 众所周知,Excel具有强大的数据处理和数据分析能力,广泛应用于加工学统计及金融统计中.特别是金融统计需要较高的安全性,那么就一定要为Exc ...

  8. 基于.NetCore开发博客项目 StarBlog - (10) 图片瀑布流

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  9. python 导出数据到excel 中,一个好用的导出数据到excel模块,XlsxWriter

    最近公司有项目需要导出数据到excel,首先想到了,tablib,xlwt,xlrd,xlwings,win32com[还可以操作word],openpyxl,等模块但是 实际操作中tablib 写入 ...

随机推荐

  1. ActiveMQ与Spring / SpringBoot 整合(四)

    1. 对 Spring 的整合 1.1 所需jar 包 <!-- activeMQ jms 的支持 --> <dependency> <groupId>org.sp ...

  2. Java并发编程实战 第10章 避免活跃性危险

    死锁 经典的死锁:哲学家进餐问题.5个哲学家 5个筷子 如果没有哲学家都占了一个筷子 互相等待筷子 陷入死锁 数据库设计系统中一般有死锁检测,通过在表示等待关系的有向图中搜索循环来实现. JVM没有死 ...

  3. Java基本的程序结构设计 控制流程

    控制流程 java的控制流程和C和C++基本一致,只是不能使用goto语句,不过break语句可以带标签,实现从内层循环跳出的目的.标签可以放在for或者while前面.如下: package com ...

  4. 【UOJ#77】A+B Problem

    传送门 题目描述 略 Sol 看到选择黑白收益不同,然后还可能有代价. 我们想到用网络流解决,并且这应该是用总可能收益-最小割得到答案. 考虑初步建图,发现那个限制可以直接 \(n^2\) 解决. 我 ...

  5. List集合中对象的排序

    使用到的是: Collections.sort(); 用法是: List<Book> list_book = new ArrayList<Book>(); Book book= ...

  6. C2MIF软件使用说明

    1.右击---管理员身份运行 2.打开文件txt---搞定!

  7. Python 爬虫十六式 - 第二式:urllib 与 urllib3

    Python请求标准库 urllib 与 urllib3 学习一时爽,一直学习一直爽!   大家好,我是 Connor,一个从无到有的技术小白.上一次我们说到了什么是HTTP协议,那么这一次我们就要动 ...

  8. sh_02_快速体验

    sh_02_快速体验 import sh_01_九九乘法表 sh_01_九九乘法表.multiple_table()

  9. 【C++】关键字struct

    网址连接 https://www.cnblogs.com/zhengfa-af/p/8144786.html 主要内容: 1. C语言中,结构体的3中不同声明和定义方式: 2. struct在C和C+ ...

  10. (C#- 多线程) 在线程中创建object,共享问题。

    研究如下问题: 1. 在一个进程的主线程中创建一个Object,其他线程都可以访问这个Object,并操作Object的方法. - 多线程同步问题. 2. 在一个进程的多个线程里面,每个线程都创建同一 ...