java 把数据导出成表格下载

java 把数据导出成表格下载

现在有很多poi把数据导出的,本篇博客使用的jxls poi 把数据导出到xls 表格中的.

//使用jxls poi需要在pom.xml中加上依赖配置
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-poi</artifactId>
            <version>1.0.13</version>
        </dependency>
//然后就需要使用jxls进行操作
Context context=new Context();
List<Entity>  lawFirmAnnualInspections=new ArrayList<>();
context.putVar("zoneName", "测试的数据");//存入你想在xls模板中表达式展示的值
context.putVar("lawFirmAnnualInspections", "测试的数据");
Map<String,Object> map=new HashMap<>();
//此处的属性对应模板中取值的属性(ps:我就不一一罗列出来了)
map.put("index", i++);
map.put("name", $display(lawyer_annualInspection, "practiceOrg"));
lawFirmAnnualInspections.add(map);
URL url= ResourceUtils.getURL("classpath:/****.xls");//获取xls的url
try(ByteArrayOutputStream byteArrayOutputStream =new  ByteArrayOutputStream();){
JxlsHelper.getInstance().processTemplate(url.openStream(),byteArrayOutputStream,context);
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename*=utf-8'zh_cn'" + URLEncoder.encode("下载下来的文件名", "UTF-8"));
response.setHeader("Content-Length", byteArrayOutputStream.size() + "");
response.getOutputStream().write(byteArrayOutputStream.toByteArray());
}
[模板链接地址](https://download.csdn.net/download/qq_42718938/12465610)
/*
这里使用了spring-core-3.1.2.ReLEASE-sources.jar包的方法(ps:以下是getURL()封装的代码)
Thread.currentThread().getContextClassLoader().getResource();
*/
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值