Spring MVC 导出EXCEL
poi需要的jar包
核心导出工具类
- 主要是通过反射获取相应的字段,并从model中获取传入的数据,对应的插入表格中
- class 对象需要在调用的时候传入
- 数据需要在调用前放入数据模型中
- 表头信息需要自己传入
public class ExcelView <T>extends AbstractXlsView{
private String modelName;
private String fileName;
private String []headNames;
private Class<T> clas;
public ExcelView(String modelName, String fileName, String[] headNames, Class<T> clas) {
super();
this.modelName = modelName;
this.fileName = fileName;
this.headNames = headNames;
this.clas = clas;
}
@Override
protected void buildExcelDocument(Map<String, Object> model,
Workbook workbook, HttpServletRequest request,
HttpServletResponse response) throws Exception {