jasperReport导出excel(springMvc)
来源:互联网 发布:最简单的c语言程序例子 编辑:程序博客网 时间:2024/06/05 17:20
代码
@RequestMapping(value="/exexcel") public void exportExcel(HttpServletRequest request,HttpServletResponse response) throws JRException, IOException{ //打印程序当前路径 System.out.println(System.getProperty("user.dir")); WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); ServletContext servletContext = webApplicationContext.getServletContext(); String jasperPath = servletContext.getRealPath( "/WEB-INF/jasper/report13.jasper"); Map<String,Object> params = new HashMap<String,Object>(); //UserJs.getUser()是List类型数据源 JRDataSource dataSource = new JRBeanCollectionDataSource(UserJs.getUser(), true); //print文件 JasperPrint print = JasperFillManager.fillReport(jasperPath, params, dataSource); //以附件形式保存文件 String generateFileName = "My文件.xlsx"; response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(generateFileName,"utf8")); //设置导出时参数 SimpleXlsxReportConfiguration conf = new SimpleXlsxReportConfiguration(); conf.setWhitePageBackground(false); conf.setDetectCellType(true); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setConfiguration(conf); //设置输入项 ExporterInput exporterInput = new SimpleExporterInput(print); exporter.setExporterInput(exporterInput); //设置输出项 OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(response.getOutputStream()); exporter.setExporterOutput(exporterOutput); exporter.exportReport(); }
UserJs.java
package com.xie.vo;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * 用于测试jasperReport * @author xie * */public class UserJs { private int id; private String name; private int age; private String title; public UserJs() { super(); } public UserJs(int id, String name, int age, String title) { super(); this.id = id; this.name = name; this.age = age; this.title=title; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public static List<UserJs> getUser(){ List<UserJs> listUserJs=new ArrayList<>(); listUserJs.add(new UserJs(0,"xx",20,"user表")); listUserJs.add(new UserJs(1,"写好",23,"user表")); listUserJs.add(new UserJs(2, "pp", 32,"user表")); return listUserJs; } public static Map<String,Object> getUserMap(){ Map<String,Object> map=new HashMap<>(); map.put("id",0); map.put("name","好啊"); map.put("age", 23); map.put("title", "表格"); return map; } public String gettitle() { return title; } public void settitle(String title) { this.title = title; }}
说明
参考(复制)了网上好多人的,比如:
http://blog.csdn.net/wangjun5159/article/details/51152403
http://blog.csdn.net/wangjun5159/article/details/51152403
http://blog.csdn.net/zhuhuiby/article/details/8569516
阅读全文
0 0
- jasperReport导出excel(springMvc)
- JasperReport导出Excel的问题
- JasperReport导出excel包含公式
- jasperReport 导出 excel 提供多种设置
- 在Struts2中利用JasperReport导出excel
- ireport、jasperreport 导出excel的java代码
- 使用JasperReport和poi导出Excel
- springmvc导出excel
- springmvc导出excel
- SpringMVC POI导出EXCEL
- springmvc 导出excel
- SpringMVC导出Excel
- springmvc导出excel
- springMVC+poi导出excel
- jxl 导出excel springMVC
- Springmvc导出excel表
- springMVC导出excel
- SpringMVC导出Excel
- 字符串-leetcode 242 Valid Anagram
- 2017 iOS最新面试题汇总(三)
- android H5 webview 无法自动播放音乐 autoplay
- 落单的数
- Linux安装WebSphere MQ
- jasperReport导出excel(springMvc)
- VS2015安装教程(带图解+下载地址+超详细)
- Grunt 新手一日入门
- 2017-06-15T00:00:00+08:00 时间转换
- STM8+STVD+COSMIC 学习笔记 address is out of range and is ignored
- BAPI_SALESORDER_CHANGE修改销售订单价格
- babel-ployfill
- Cmake3.8+VS2013+Win10编译OpenCV3.2+opencv_contrib遇到的问题
- tesseract OCR Engine overview字符识别学习