CellStyle style = sheet.getWorkbook().createCellStyle();
//置成黄色
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
//表头的边界线清晰可见
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
Row header = sheet.createRow(0);
int columnIndex = 0;
for (...) {
Cell cell = createCell(header, columnIndex);
cell.setCellValue(headerText);
cell.setCellStyle(style);
//表头cell的宽度适应文字
sheet.autoSizeColumn(columnIndex);
columnIndex++;
}