马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
说明:本文是jxls根据模板导出Excel直接下载。
使用版本:jxls V2.10.0
excel模板版本:.xlsx格式
jxls官网地址:https://jxls.sourceforge.net/index.html
1、pom引用- <dependency>
- <groupId>org.jxls</groupId>
- <artifactId>jxls</artifactId>
- <version>2.10.0</version>
- </dependency>
- <dependency>
- <groupId>org.jxls</groupId>
- <artifactId>jxls-poi</artifactId>
- <version>2.10.0</version>
- </dependency>
- <dependency>
- <groupId>org.jxls</groupId>
- <artifactId>jxls-jexcel</artifactId>
- <version>1.0.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-jexl</artifactId>
- <version>2.1.1</version>
- </dependency>
复制代码 2、Controller调用方法- @PostMapping("/export")
- public AjaxResult export(HttpServletResponse response, Data data) throws IOException {
- String fileName = "test.xlsx";
- Map<String, Object> model = dataService.getExportData(data,fileName);//拼接需要导出的内容
- response.addHeader("Content-Disposition", "attachment; filename="" + fileName + """);
- return JxlsUtils.exportExcelWithOS(response.getOutputStream(),fileName, model);
- }
复制代码 3、拼接数据
[code]public Map getExportData(Data data,String fileName) { Map model = new HashMap(); // 绑定数据 try { //可绑定单个参数,Excel模板中单元格直接用${test1}获取 model.put("test1", "ttt"); //可绑定list,使用${item.参数名}获取,需在列表首个单元格中增加批注 List taskItems = new ArrayList();//Data1为某个数据类 for (int i=0;i |