public boolean toOutList(List billList) throws IOException {
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("订单");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
HSSFCell cell = row.createCell(0);
cell.setCellValue("订单编码");
cell.setCellStyle(style);
cell = row.createCell( 1);
cell.setCellValue("患者姓名");
cell.setCellStyle(style);
cell = row.createCell( 2);
cell.setCellValue("医护姓名");
cell.setCellStyle(style);
cell = row.createCell( 3);
cell.setCellValue("账单金额");
cell.setCellStyle(style);
// 第五步,写入实体数据,
int x=billList.size();
for (int i = 0; i < x; i++){
Bill b= billList.get(i);
// 第四步,创建单元格,并设置值
row.createCell(0).setCellValue( b.getOrderNum());
row.createCell(1).setCellValue(b.getPaName());
row.createCell(2).setCellValue(b.getYihuName());
row.createCell(3).setCellValue(b.getBillMoney());
System.out.println(b);
}
FileOutputStream fout = new FileOutputStream("F:/students.xls");
wb.write(fout);
fout.flush();
fout.close();
return true;
}
}