跳到主要内容

Excel模板导出View

模板导出提供的AutopoiTemplateExcelView以及对应的bean TemplateExcelConstants 案例

@RequestMapping()
public String download(ModelMap modelMap) {
Map<String, Object> map = new HashMap<String, Object>();
TemplateExportParams params = new TemplateExportParams(
"doc/foreach.xlsx");
List<TemplateExcelExportEntity> list = new ArrayList<TemplateExcelExportEntity>();

for (int i = 0; i < 4; i++) {
TemplateExcelExportEntity entity = new TemplateExcelExportEntity();
entity.setIndex(i + 1 + "");
entity.setAccountType("开源项目");
entity.setProjectName("EasyPoi " + i + "期");
entity.setAmountApplied(i * 10000 + "");
entity.setApprovedAmount((i + 1) * 10000 - 100 + "");
list.add(entity);
}
map.put("entitylist", list);
map.put("manmark", "1");
map.put("letest", "12345678");
map.put("fntest", "12345678.2341234");
map.put("fdtest", null);
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 1; i++) {
Map<String, Object> testMap = new HashMap<String, Object>();

testMap.put("id", "xman");
testMap.put("name", "小明" + i);
testMap.put("sex", "1");
mapList.add(testMap);
}
map.put("maplist", mapList);

mapList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 6; i++) {
Map<String, Object> testMap = new HashMap<String, Object>();

testMap.put("si", "xman");
mapList.add(testMap);
}
map.put("sitest", mapList);
modelMap.put(TemplateExcelConstants.FILE_NAME, "用户信息"); //文件名
modelMap.put(TemplateExcelConstants.PARAMS, params);//参数
modelMap.put(TemplateExcelConstants.MAP_DATA, map);//数据
return TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW;//view名称

}

具体案例AutopoiTemplateExcelViewTest