HSSFCellStyle style = null
// 创建表头style
HSSFCellStyle cellStyleTitle = workbook.createCellStyle()
cellStyleTitle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND)// 填充单元格
cellStyleTitle.setFillForegroundColor(HSSFColor.YELLOW.index)
cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER)// //居中显示
HSSFRow titleRow = sheet.createRow(0)
for (int i = 0i <titles.lengthi++) {
HSSFCell cell = titleRow.createCell(i)
// cell.setCellStyle(createCellColorStyle(workbook))
cell.setCellStyle(cellStyleTitle)
cell.setCellValue(titles[i])// 给单元格赋值
}
//自定义背景颜色
HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette()
palette.setColorAtIndex(HSSFColor.LIME.index, (byte)234, (byte)234, (byte)234)
titleStyle.setFillForegroundColor(HSSFColor.LIME.index)
titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND)
//自定义字体颜色
palette.setColorAtIndex(HSSFColor.SEA_GREEN.index, (byte)23, (byte)110, (byte)169)
Font titleFont = wb.createFont()
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD)
titleFont.setFontHeight((short)200)
titleFont.setColor(HSSFColor.SEA_GREEN.index)
titleStyle.setFont(titleFont)
titleStyle.setFillBackgroundColor(Font.COLOR_NORMAL)
1、创建字体,设置其为红色、粗体:Java代码
HSSFFont font = workbook.createFont()
font.setColor(HSSFFont.COLOR_RED)
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD)
2、创建格式
Java代码
HSSFCellStyle cellStyle= workbook.createCellStyle()
cellStyle.setFont(font)
3、应用格式
Java代码
HSSFCell cell = row.createCell((short) 0)
cell.setCellStyle(cellStyle)
cell.setCellType(HSSFCell.CELL_TYPE_STRING)
cell.setCellValue("标题 ")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)