小数据的导出 最大只能65536条



@SuppressWarnings("unused")
@RequestMapping(params = "excelExport")
public void excelExport(@RequestParam HashMap paramMap, HttpServletRequest request,HttpServletResponse response) {
response.setContentType("application/vnd.ms-excel");
String codedFileName = null;
OutputStream fOut = null;
HttpSession session = request.getSession();
try {
codedFileName = "用户信息";
// 根据浏览器进行转码,使其支持中文文件名
if (BrowserUtils.isIE(request)) {
response.setHeader("content-disposition","attachment;filename=" + java.net.URLEncoder.encode(codedFileName,"UTF-8") + ".xls");
} else {
String newtitle = new String(codedFileName.getBytes("UTF-8"),"ISO8859-1");
response.setHeader("content-disposition","attachment;filename=" + newtitle + ".xls");
}
// 产生工作簿对象
HSSFWorkbook workbook = null;
List dataList = sysUserService.getByCondition(paramMap);
workbook = exportExcel("用户信息", dataList);
fOut = response.getOutputStream();
workbook.write(fOut);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fOut.flush();
fOut.close();
} catch (IOException e) {


}
}
}

public  HSSFWorkbook exportExcel(String sheetName, List dataList) {
HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet(sheetName);  
        CellStyle titleStyle = ExcelUtil.getTitleStyle(workbook);
        HSSFRow row = sheet.createRow((int) 0);  
        row.setHeight((short) 900);
        HSSFCell cell = null;
        int i = 0;
        cell = row.createCell(i++);
        cell.setCellValue("真实姓名"); 
        cell.setCellStyle(titleStyle); 
        cell = row.createCell(i++);
        cell.setCellValue("用户名"); 
        cell.setCellStyle(titleStyle); 
        cell = row.createCell(i++);
        cell.setCellValue("手机号"); 
        cell.setCellStyle(titleStyle); 
        cell = row.createCell(i++);
        cell.setCellValue("联系电话"); 
        cell.setCellStyle(titleStyle); 
        cell = row.createCell(i++);
        cell.setCellValue("邮箱地址"); 
        cell.setCellStyle(titleStyle); 
        
        int b = 1;
        for(SysUser data : dataList) {
        row = sheet.createRow(b); 
       int a = 0;
        row.createCell(a++).setCellValue(data.getRealName());
        row.createCell(a++).setCellValue(data.getUserName());
        row.createCell(a++).setCellValue(data.getPhone());
        row.createCell(a++).setCellValue(data.getUserTel());
        row.createCell(a++).setCellValue(data.getEmail());
        b++;
        }


        for(int a = 0; a < i; a++){
            sheet.autoSizeColumn(a); 
        }
        
return workbook;
}

你可能感兴趣的:(Java)