设置样式:
private CellStyle setRowStyle(Workbook wb) {
CellStyle style = wb.createCellStyle();
// 边框填充
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 居中对齐
style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
// 设置字体
Font font = wb.createFont();
font.setFontName("黑体");
style.setFont(font);
// 填充颜色
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
style.setWrapText(true);
return style;
}
设置过滤和排序:
sheet.setAutoFilter(CellRangeAddress.valueOf("C1:D1"));