String exName = "fileName";
ExcelUtil excel = new ExcelUtil(exName); //创建一个excel模型
List<String> titles1 = new ArrayList<String>(); //创建一个list用来存放文件的标题
titles1.add("片区ID");
titles1.add("片区名称");
titles1.add("负责人");
titles1.add("中心点区域");
titles1.add("片区状态");
titles1.add("室分数量");
titles1.add("天线数量");
int tatolRecord ;//数据数量
List<Area> list = null; //要显示的数据列表
if(tatolRecord >0){
paramMap.put("maxResults", 50000);
int sheetNum = 1;
do{
paramMap.put("startIndex", startIdx);
list = areaService.findAreas(paramMap);
if (sheetNum == 1){
excel.open("sheet" + sheetNum);
}else{
excel.newSheet("sheet" + sheetNum);
}
excel.setExcelTitle(titles1,HSSFFont.BOLDWEIGHT_BOLD);//title
for (int j = 0; j < list.size(); j++) {//fill data
fillClikeCellData(excel, j + 1, list.get(j));
}
sheetNum++;
startIdx =startIdx+50000;
}while((null != list) && (sheetNum -1) * 50000 + list.size() < tatolRecord);
}
excel.export(request, response);
void export(){
ServletOutputStream out = null;
try {
String UserAgent = request.getHeader("User-Agent");
Boolean flag= UserAgent.indexOf("like Gecko")>0;
if (request.getHeader("User-Agent").toLowerCase().indexOf("msie") >0||flag) {
fileName=URLEncoder.encode(fileName,"UTF-8");
}
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=\""
+ encode(fileName, request) + "\"");
out = response.getOutputStream();
workbook.write(out);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != out) {
try {
out.flush();
out.close();
out = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}