在excelutil类里面添加
public class ExcelUtil { public static Workbook fillExcelData(ResultSet rs, Workbook wb, String[] headers) throws Exception { int rowIndex = 0; //定义行的初始值 Sheet sheet = wb.createSheet(); //创建sheet页 Row row = sheet.createRow(rowIndex++); //行数自增+1 //改变字体颜色 wb.createCellStyle(); CellStyle style = wb.createCellStyle(); HSSFFont font=(HSSFFont) wb.createFont(); font.setColor(HSSFColor.RED.index); style.setFont(font); //将头信息填进单元格 for (int i = 0; i < headers.length; i++) { Cell cell = row.createCell(i); cell.setCellValue(headers[i]); cell.setCellStyle(style);//将字体样式给单元格 } while (rs.next()) { row = sheet.createRow(rowIndex++); //增加行数 for (int i = 0; i < headers.length; i++) { // 添加内容 row.createCell(i).setCellValue(rs.getObject(i + 1).toString()); } } return wb; } }