XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(title); //创建一个表 // 生成一个样式 XSSFCellStyle style = workbook.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(new XSSFColor(java.awt.Color.lightGray)); style.setAlignment(XSSFCellStyle.ALIGN_CENTER);//对其方式 style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); //是否自动换行 XSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 14);//字体大小 font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); //标题行 XSSFRow row0 = sheet.createRow(0); row0.setHeightInPoints(25); sheet.addMergedRegion(new CellRangeAddress(0, 0 , 0, 20)); Cell cell0 = row0.createCell(0); cell0.setCellStyle(style); cell0.setCellValue(title);