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;
}
java 将数据库数据插入excel表格中
最新推荐文章于 2023-05-18 15:10:36 发布
