环境:easyUi框架和ssm集成框架,java语言 ,maven管理jar包,tomcat服务器版本8.5 jdk1.8
案例:
导入poi依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10.1</version>
</dependency>
controller
@RequestMapping("/excel")
public ModelAndView exportUser(@RequestParam(value="page",defaultValue="1")Integer page,
@RequestParam(value="rows",defaultValue="5") Integer rows) {
System.out.println("aaa");
ModelAndView mv = new ModelAndView();
EasyUIpage uipage = userService.queryAll(page,rows);
List<User>users = (List<User>)uipage.getRows();
mv.addObject("userList",users);
mv.setViewName("export-user");
return mv;
}
自定义excel 视图
public class UserExcelView extends AbstractExcelView {
/**
* 以下完成视图的渲染
*/
@Override
protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// 从model对象