技術交流群:233513714
HSSFCellStyle setBorder1 = workbook.createCellStyle();
HSSFFont font1 = workbook.createFont();
font1.setFontName("Arial");
font1.setFontHeightInPoints((short) 14);//設置字體大小
setBorder1.setFont(font1);//選擇需要用到的字體格式
setBorder1.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
setBorder1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
setBorder1.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); //設置前景色
//setBorder1.setFillForegroundColor(HSSFColor.RED.index); //設置背景色
HSSFSheet sheet = workbook.createSheet("list");
getCell(sheet, i, 0).setCellValue("日期");
getCell(sheet, i, 0).setCellStyle(setBorder1);//設置樣式
這里需要特別注意的是在設置背景色和前景色的時候一定要加上setBorder1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);這行代碼,否則設置顏色不起作用