直接上方法说明
public void outputExcel(HttpServletResponse response,Page page) throws IOException{
OutputStream os = null;
HSSFWorkbook workbook = null;
List<PageData> list=loanTaskOverService.callLoanOverExl(page);
for(int i=0;i<list.size();i++){
PageData pdd=new PageData();
pdd.put("call_loan_nid", list.get(i).get("call_loan_nid"));
pdd.put("repayment_id", list.get(i).get("repayment_id"));
pdd.put("real_name", list.get(i).get("real_name"));
}
response.reset();// 清空输出流
os=response.getOutputStream();//取得输出流
String fname="loginfo";
response.setHeader("Content-disposition",
"attachment; filename=" + new String(fileName.getBytes("gbk"), "iso8859-1") + ".xls");// 设定输出文件头,new String(fileName.getBytes("gbk"),一定要加上,防止表头中文乱码
response.setContentType("application/msexcel");// EXCEL格式
//列表头
workbook=new HSSFWorkbook();
HSSFSheet sheet=workbook.createSheet();// 生成名为sheet1的工作表
HSSFFont headerFont = workbook.createFont(); //标题字体
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle headerStyle = workbook.createCellStyle(); //标题样式
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平布局:居中
//headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
headerStyle.setFont(headerFont);
HSSFRow row = sheet.createRow(0);// 标题行
HSSFCell cell = row.createCell(0);// 单元格
cell.setCellStyle(headerStyle);//给标题加样式
row=sheet.createRow(0);
//添加列表头
cell=row.createCell(0);
cell.setCellValue("催收编号");
cell=row.createCell(1);
cell.setCellValue("还款订单号");
cell=row.createCell(2);
cell.setCellValue("借款人姓名");
//添加数据列表
for(int i=0;i<list.size();i++){
HSSFRow rows=sheet.createRow(i);//创建数据列表行
cell=rows.createCell(0);
cell.setCellValue(list.get(i).get("call_loan_nid").toString());
cell=rows.createCell(1);
cell.setCellValue(list.get(i).get("repayment_id").toString());
cell=rows.createCell(2);
cell.setCellValue(list.get(i).get("real_name").toString());
}
workbook.write(os);
os.flush();
os.close();
}