public List<PkAccountManager> selectPkAccountManagerList() throws IOException {
// 创建工作薄
HSSFWorkbook workbook = new HSSFWorkbook();
// 创建工作表
HSSFSheet sheet = workbook.createSheet("sheet1");
//创建首行名称
HSSFRow name = sheet.createRow(0);
name.createCell(0).setCellValue("经理id");
name.createCell(1).setCellValue("战队名称");
name.createCell(2).setCellValue("组数");
//从数据库查数据
List<PkAccountManager> pkAccountManagers = pkAccountManagerDao.selectPkAccountManagerList();
for (int row = 0; row < pkAccountManagers.size(); row++) {
//row+1从第二行开始插
HSSFRow rows = sheet.createRow(row+1);
PkAccountManager pkAccountManager = pkAccountManagers.get(row);
// 向工作表中添加数据
if (pkAccountManager.getManagerId() == null){
rows.createCell(0).setCellValue("");
}else{
rows.createCell(0).setCellValue(pkAccountManager.getManagerId());
}
rows.createCell(1).setCellValue(pkAccountManager.getTeamName());
if (pkAccountManager.getTeamCount() == null){
rows.createCell(2).setCellValue("");
}else{
rows.createCell(2).setCellValue(pkAccountManager.getTeamCount());
}
}
File xlsFile = new File("D:/poi.xls");
FileOutputStream xlsStream = new FileOutputStream(xlsFile);
workbook.write(xlsStream);
return pkAccountManagers;
}
12-08
89
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)