设置POI单元格合并以及样式
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("sheet1");
XSSFCell Cell = sheet.createRow(0).createCell(0);
Cell.setCellValue("我的第一个excel程序");
//合并单元格
CellRangeAddress Range = new CellRangeAddress(0,0,0,1);
FileOutputStream fos = new FileOutputStream(new File("D:\\a.xlsx"));// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setAlignment(XSSFCellStyle.ALIGN_CENTER);//水平居中
style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);//垂直居中
// 背景色
style.setFillForegroundColor(new XSSFColor((new Color(23, 220, 1))));
style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
style.setFillBackgroundColor(new XSSFColor());
// 设置边框
style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
style.setBorderRight(XSSFCellStyle.BORDER_THIN);
style.setBorderTop(XSSFCellStyle.BORDER_THIN);
// 自动换行
style.setWrapText(true);
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 10);
font.setColor(new XSSFColor(new Color(220, 230, 241)));
font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
font.setFontName("宋体");
// 把字体 应用到当前样式
style.setFont(font);
//style设置好后,为cell设置样式
Cell.setCellStyle(style);//cell为已有的单元格
workbook.write(fos);