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

采用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();
}
}