代码拉取完成,页面将自动刷新
package cn.afterturn.easypoi.view;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
/**
* @author jueyue
*/
@Controller
@RequestMapping("/EasypoiMapExcelViewTest")
public class EasypoiMapExcelViewTest {
@RequestMapping()
public String download(ModelMap modelMap) {
List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
ExcelExportEntity excelentity = new ExcelExportEntity("姓名", "name");
excelentity.setNeedMerge(true);
entity.add(excelentity);
entity.add(new ExcelExportEntity("性别", "sex"));
excelentity = new ExcelExportEntity(null, "students");
List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
temp.add(new ExcelExportEntity("姓名", "name"));
temp.add(new ExcelExportEntity("性别", "sex"));
excelentity.setList(temp);
entity.add(excelentity);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
for (int i = 0; i < 10; i++) {
map = new HashMap<String, Object>();
map.put("name", "1" + i);
map.put("sex", "2" + i);
List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
tempList.add(map);
tempList.add(map);
map.put("students", tempList);
list.add(map);
}
ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF);
params.setFreezeCol(2);
modelMap.put(MapExcelConstants.MAP_LIST, list);
modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
modelMap.put(MapExcelConstants.PARAMS, params);
modelMap.put(MapExcelConstants.FILE_NAME, "EasypoiMapExcelViewTest");
return MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW;
}
/**如果上面的方法不行,可以使用下面的用法
* 同样的效果,只不过是直接问输出了,不经过view了
* @param map
* @param request
* @param response
*/
@RequestMapping("load")
public void downloadByPoiBaseView(ModelMap modelMap, HttpServletRequest request,
HttpServletResponse response) {
List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
ExcelExportEntity excelentity = new ExcelExportEntity("姓名", "name");
excelentity.setNeedMerge(true);
entity.add(excelentity);
entity.add(new ExcelExportEntity("性别", "sex"));
excelentity = new ExcelExportEntity(null, "students");
List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
temp.add(new ExcelExportEntity("姓名", "name"));
temp.add(new ExcelExportEntity("性别", "sex"));
excelentity.setList(temp);
entity.add(excelentity);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
for (int i = 0; i < 10; i++) {
map = new HashMap<String, Object>();
map.put("name", "1" + i);
map.put("sex", "2" + i);
List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
tempList.add(map);
tempList.add(map);
map.put("students", tempList);
list.add(map);
}
ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF);
params.setFreezeCol(2);
modelMap.put(MapExcelConstants.MAP_LIST, list);
modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
modelMap.put(MapExcelConstants.PARAMS, params);
modelMap.put(MapExcelConstants.FILE_NAME, "EasypoiMapExcelViewTest");
PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。