在JavaWeb中Excel文件如何使用POI实现导出-创新互联

在Java Web中Excel文件如何使用POI实现导出?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联长期为千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为玄武企业提供专业的成都网站制作、做网站,玄武网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。

采用Spring mvc架构:

Controller层代码如下

@Controller
public class StudentExportController{
  @Autowired
  private StudentExportService studentExportService;
  @RequestMapping(value = "/excel/export")
  public void exportExcel(HttpServletRequest request, HttpServletResponse response)
  throws Exception {
    List list = new ArrayList();
    list.add(new Student(1000,"zhangsan","20"));
    list.add(new Student(1001,"lisi","23"));
    list.add(new Student(1002,"wangwu","25"));
    HSSFWorkbook wb = studentExportService.export(list);
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachment;filename=student.xls");
    OutputStream ouputStream = response.getOutputStream();
    wb.write(ouputStream);
    ouputStream.flush();
    ouputStream.close();
  }
}

网页名称:在JavaWeb中Excel文件如何使用POI实现导出-创新互联
网站链接:http://scyanting.com/article/cedjeo.html