精华内容
下载资源
问答
  • POI 设置单元格背景色

    2017-10-14 11:29:04
    POI 设置单元格背景色,背景色编码与实际颜色对照表 转载 2015年06月27日 16:29:58 标签: </ul

    POI 设置单元格背景色,背景色编码与实际颜色对照表

    This example shows you Excel cell fills and colors using Apache POI.

    In our example i have used all the possible colors and set it as Fills background colors of cells.

    Below is the example code.

    package com.java.connect.poi;
    

    import java.io.FileOutputStream;
    import java.io.IOException;

    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.CellStyle;
    import org.apache.poi.ss.usermodel.IndexedColors;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;

    public class POIFillAndColorExample {
    public static void main(String[] args) throws IOException {
    // Create a workbook object
    Workbook workbook = new XSSFWorkbook();
    // Create sheet
    Sheet sheet = workbook.createSheet();

    	// Create a row and put some cells in it.
    	Row row = sheet.createRow((short) 1);
    
    	// Aqua background
    	CellStyle style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.AQUA.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	Cell cell = row.createCell((short) 1);
    	cell.setCellValue("X1");
    	cell.setCellStyle(style);
    
    	// Orange "foreground", foreground being the fill foreground not the
    	// font color.
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.AUTOMATIC.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row.createCell((short) 2);
    	cell.setCellValue("X2");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row.createCell((short) 3);
    	cell.setCellValue("X3");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row.createCell((short) 4);
    	cell.setCellValue("X4");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row.createCell((short) 5);
    	cell.setCellValue("X5");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row2 = sheet.createRow((short) 2);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.BROWN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row2.createCell((short) 1);
    	cell.setCellValue("X6");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.CORAL.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row2.createCell((short) 2);
    	cell.setCellValue("X7");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row2.createCell((short) 3);
    	cell.setCellValue("X8");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row2.createCell((short) 4);
    	cell.setCellValue("X9");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.DARK_GREEN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row2.createCell((short) 5);
    	cell.setCellValue("X10");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row3 = sheet.createRow((short) 3);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.DARK_RED.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row3.createCell((short) 1);
    	cell.setCellValue("X11");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.DARK_TEAL.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row3.createCell((short) 2);
    	cell.setCellValue("X12");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.DARK_YELLOW.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row3.createCell((short) 3);
    	cell.setCellValue("X13");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.GOLD.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row3.createCell((short) 4);
    	cell.setCellValue("X14");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row3.createCell((short) 5);
    	cell.setCellValue("X15");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row4 = sheet.createRow((short) 4);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row4.createCell((short) 1);
    	cell.setCellValue("X16");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row4.createCell((short) 2);
    	cell.setCellValue("X17");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row4.createCell((short) 3);
    	cell.setCellValue("X18");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row4.createCell((short) 4);
    	cell.setCellValue("X19");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.INDIGO.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row4.createCell((short) 5);
    	cell.setCellValue("X20");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row5 = sheet.createRow((short) 5);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LAVENDER.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row5.createCell((short) 1);
    	cell.setCellValue("X21");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row5.createCell((short) 2);
    	cell.setCellValue("X22");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row5.createCell((short) 3);
    	cell.setCellValue("X23");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row5.createCell((short) 4);
    	cell.setCellValue("X24");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row5.createCell((short) 5);
    	cell.setCellValue("X25");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row6 = sheet.createRow((short) 6);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE
    			.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row6.createCell((short) 1);
    	cell.setCellValue("X26");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row6.createCell((short) 2);
    	cell.setCellValue("X27");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row6.createCell((short) 3);
    	cell.setCellValue("X28");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row6.createCell((short) 4);
    	cell.setCellValue("X29");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row6.createCell((short) 5);
    	cell.setCellValue("X30");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row7 = sheet.createRow((short) 7);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.LIME.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row7.createCell((short) 1);
    	cell.setCellValue("X31");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.MAROON.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row7.createCell((short) 2);
    	cell.setCellValue("X32");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.OLIVE_GREEN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row7.createCell((short) 3);
    	cell.setCellValue("X33");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row7.createCell((short) 4);
    	cell.setCellValue("X34");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.ORCHID.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row7.createCell((short) 5);
    	cell.setCellValue("X35");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row8 = sheet.createRow((short) 8);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row8.createCell((short) 1);
    	cell.setCellValue("X36");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.PINK.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row8.createCell((short) 2);
    	cell.setCellValue("X37");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.PLUM.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row8.createCell((short) 3);
    	cell.setCellValue("X38");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.RED.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row8.createCell((short) 4);
    	cell.setCellValue("X39");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.ROSE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row8.createCell((short) 5);
    	cell.setCellValue("X40");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row9 = sheet.createRow((short) 9);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row9.createCell((short) 1);
    	cell.setCellValue("X41");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.SEA_GREEN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row9.createCell((short) 2);
    	cell.setCellValue("X42");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row9.createCell((short) 3);
    	cell.setCellValue("X43");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.TAN.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row9.createCell((short) 4);
    	cell.setCellValue("X44");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.TEAL.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row9.createCell((short) 5);
    	cell.setCellValue("X45");
    	cell.setCellStyle(style);
    
    	// Create a row and put some cells in it.
    	Row row10 = sheet.createRow((short) 10);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.TURQUOISE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row10.createCell((short) 1);
    	cell.setCellValue("X46");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.VIOLET.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row10.createCell((short) 2);
    	cell.setCellValue("X47");
    	cell.setCellStyle(style);
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row10.createCell((short) 3);
    	cell.setCellValue("X48");
    	cell.setCellStyle(style);
    
    	style = workbook.createCellStyle();
    	style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	cell = row10.createCell((short) 3);
    	cell.setCellValue("X49");
    	cell.setCellStyle(style);
    
    	// Write the output to a file
    	FileOutputStream fileOut = new FileOutputStream(
    			"POIFillAndColorExample.xlsx");
    	workbook.write(fileOut);
    	fileOut.close();
    
    }
    

    }

    The generated excel files looks like below images.

    展开全文
  • HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 style.setFillForegroundColor(IndexedColors.CORNFLOWER...// 设置背景色 style.setFillPattern

    转载自:https://www.cnblogs.com/linvan/p/10860538.html

    HSSFCellStyle style = wb.createCellStyle();
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
    style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());// 设置背景色
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //设置加粗
    
    HSSFFont font = wb.createFont();
    font.setFontName("黑体");
    font.setFontHeightInPoints((short) 12);//设置字体大小
    style.setFont(font);
    
    // 创建标题
    for (int i = 0; i < title.length; i++) {
        cell = row.createCell(i);
        cell.setCellValue(title[i]);
        cell.setCellStyle(style);
    }
    

    在这里插入图片描述
    上面的单元格颜色对应下面的英语颜色表示,从X1-X49 按顺序对应;
    将下面对应的code填入上述代码加粗斜体位置即可。

    IndexedColors.AQUA.getIndex();
            IndexedColors.AUTOMATIC.getIndex(); 
            IndexedColors.BLUE.getIndex(); 
            IndexedColors.BLUE_GREY.getIndex();
            IndexedColors.BRIGHT_GREEN.getIndex();
            IndexedColors.BROWN.getIndex();
            IndexedColors.CORAL.getIndex();
            IndexedColors.CORNFLOWER_BLUE.getIndex();
            IndexedColors.DARK_BLUE.getIndex();
            IndexedColors.DARK_GREEN.getIndex();
            IndexedColors.DARK_RED.getIndex();
            IndexedColors.DARK_TEAL.getIndex();
            IndexedColors.DARK_YELLOW.getIndex();
            IndexedColors.GOLD.getIndex();
            IndexedColors.GREEN.getIndex();
            IndexedColors.GREY_25_PERCENT.getIndex();
            IndexedColors.GREY_40_PERCENT.getIndex();
            IndexedColors.GREY_50_PERCENT.getIndex();
            IndexedColors.GREY_80_PERCENT.getIndex();
            IndexedColors.INDIGO.getIndex();
            IndexedColors.LAVENDER.getIndex();
            IndexedColors.LEMON_CHIFFON.getIndex();
            IndexedColors.LIGHT_BLUE.getIndex();
            IndexedColors.LEMON_CHIFFON.getIndex();
            IndexedColors.LIGHT_BLUE.getIndex();
            IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex();
            IndexedColors.LIGHT_GREEN.getIndex();
            IndexedColors.LIGHT_ORANGE.getIndex();
            IndexedColors.LIGHT_TURQUOISE.getIndex();
            IndexedColors.LIGHT_YELLOW.getIndex();
            IndexedColors.LIME.getIndex();
            IndexedColors.MAROON.getIndex();
            IndexedColors.OLIVE_GREEN.getIndex();
            IndexedColors.ORANGE.getIndex();
            IndexedColors.ORCHID.getIndex();
            IndexedColors.PALE_BLUE.getIndex();
            IndexedColors.PINK.getIndex();
            IndexedColors.PLUM.getIndex();
            IndexedColors.RED.getIndex();
            IndexedColors.ROSE.getIndex();
            IndexedColors.ROYAL_BLUE.getIndex();
            IndexedColors.SEA_GREEN.getIndex();
            IndexedColors.SKY_BLUE.getIndex();
            IndexedColors.TAN.getIndex();
            IndexedColors.TEAL.getIndex();
            IndexedColors.TURQUOISE.getIndex();
            IndexedColors.VIOLET.getIndex();
            IndexedColors.WHITE.getIndex();
            IndexedColors.YELLOW.getIndex();
    
    展开全文
  • style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.AUTOMATIC.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); ...HSSFCellStyle style = workbook....

     本次用的poi的版本是4.1.2
     SXSSFWorkbook wb = new SXSSFWorkbook(); 
     CellStyle style = wb.createCellStyle();
     style.setAlignment(HSSFCellStyle.ALIGN_CENTER)
     style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());// 设置背景色
     style.setFillPattern(FillPatternType.SOLID_FOREGROUND); 

     如果是3版本一下 
     style.setFillPattern(CellStyle.SOLID_FOREGROUND);

        上面的单元格颜色对应下面的英语颜色表示,从X1-X49 按顺序对应;
            IndexedColors.AQUA.getIndex();
            IndexedColors.AUTOMATIC.getIndex(); 
            IndexedColors.BLUE.getIndex(); 
            IndexedColors.BLUE_GREY.getIndex();
            IndexedColors.BRIGHT_GREEN.getIndex();
            IndexedColors.BROWN.getIndex();
            IndexedColors.CORAL.getIndex();
            IndexedColors.CORNFLOWER_BLUE.getIndex();
            IndexedColors.DARK_BLUE.getIndex();
            IndexedColors.DARK_GREEN.getIndex();
            IndexedColors.DARK_RED.getIndex();
            IndexedColors.DARK_TEAL.getIndex();
            IndexedColors.DARK_YELLOW.getIndex();
            IndexedColors.GOLD.getIndex();
            IndexedColors.GREEN.getIndex();
            IndexedColors.GREY_25_PERCENT.getIndex();
            IndexedColors.GREY_40_PERCENT.getIndex();
            IndexedColors.GREY_50_PERCENT.getIndex();
            IndexedColors.GREY_80_PERCENT.getIndex();
            IndexedColors.INDIGO.getIndex();
            IndexedColors.LAVENDER.getIndex();
            IndexedColors.LEMON_CHIFFON.getIndex();
            IndexedColors.LIGHT_BLUE.getIndex();
            IndexedColors.LEMON_CHIFFON.getIndex();
            IndexedColors.LIGHT_BLUE.getIndex();
            IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex();
            IndexedColors.LIGHT_GREEN.getIndex();
            IndexedColors.LIGHT_ORANGE.getIndex();
            IndexedColors.LIGHT_TURQUOISE.getIndex();
            IndexedColors.LIGHT_YELLOW.getIndex();
            IndexedColors.LIME.getIndex();
            IndexedColors.MAROON.getIndex();
            IndexedColors.OLIVE_GREEN.getIndex();
            IndexedColors.ORANGE.getIndex();
            IndexedColors.ORCHID.getIndex();
            IndexedColors.PALE_BLUE.getIndex();
            IndexedColors.PINK.getIndex();
            IndexedColors.PLUM.getIndex();
            IndexedColors.RED.getIndex();
            IndexedColors.ROSE.getIndex();
            IndexedColors.ROYAL_BLUE.getIndex();
            IndexedColors.SEA_GREEN.getIndex();
            IndexedColors.SKY_BLUE.getIndex();
            IndexedColors.TAN.getIndex();
            IndexedColors.TEAL.getIndex();
            IndexedColors.TURQUOISE.getIndex();
            IndexedColors.VIOLET.getIndex();
            IndexedColors.WHITE.getIndex();
            IndexedColors.YELLOW.getIndex();        
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillBackgroundColor(HSSFColor.AQUA.index);
    cell.setCellStyle(style);
    

    参考  https://www.cnblogs.com/linvan/p/10860538.html

    展开全文
  • apache poi 设置单元格背景色

    千次阅读 2012-08-20 14:44:10
    点击打开链接 这个链接是我收藏的
  • 关于POI单元格背景色设置(转) csdn 中找到了用Apache POI 实现单元格背景色的小例子 我用了JDK6 + POI 3.17 ,调试中报错 最终将 CellStyle.SOLID_FOREGROUND 替换为 FillPatternType.SOLID_...
  • Apache-POI-设置单元格背景色 版本:3.14 XSSFCell mobileCell = row.getCell(0); XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex()); cellStyle....
  • POI 设置Excel单元格背景色前言一、冲~~~1.代码实现2.颜色对应3.填充对应总结 前言 POI 设置单元格背景颜色 一、冲~~~ 1.代码实现 注: 本人用的是目前最新的依赖 4.1.2 代码如下(示例): HSSFWorkbook ...
  • CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.AQUA.getIndex());... //这一步说是设置前景色,其实是excel里面设置表格的背景色。 style.setFillPattern(Fil...
  • 颜色盘 /** * */ package com.totest.poiDemo; ...import java.io.FileOutputStream;...import org.apache.poi.ss.usermodel.Cell;...import org.apache.poi.ss.usermodel.FillPatternType; impo.
  • XSSFCellStyle 自定义单元格背景颜色 此代码可用于2007(xlsx)之后的版本使用。 XSSFWorkbook wb = new XSSFWorkbook();//此行代码可以忽略 XSSFCellStyle style = wb.createCellStyle();//创建一个单元格style ...
  • POI设置单元格背景色

    千次阅读 2017-12-05 18:08:12
    该篇文章为转载,原文地址:POI操作Excel:cell的背景颜色类型 POI背景颜色设置方法如下: HSSFCellStyle style = workbook.createCellStyle(); style.setFillBackgroundColor(HSSFColor.AQU
  • POI 设置单元格背景颜色

    万次阅读 多人点赞 2017-04-05 17:32:24
    转载:http://xiaohewoai.iteye.com/blog/1300817 This example shows you Excel cell fills and colors using Apache POI. In our example i have used all the possible colors and set it as Fills backgrou
  • java使用poi如何给单个单元格设置背景颜色,我已做过判断行和列都不行,都会是整个excel表格都有背景颜色,求好心人解答呀
  • POI导出Excel设置单元格背景色

    千次阅读 2019-08-25 15:16:46
    POI导出Excel设置单元格背景色 导出Excel的时候,没有设置背景色,用2003版本的Excel工具打开会出现文档单元格背景自动填充黑色的情况,没有找到好的解决方法,就主动给他填充一种颜色,问题就算解决了。在WPS中...
  • This example shows you Excel cell fills and colors using Apache POI. In our example i have used all the possible colors and set it as Fills background colors of cells. Below is the example code.
  • import java.io.FileOutputStream; import java.io.IOException; ...import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; ...
  • 图片对应位置: 1.IndexedColors.AQUA.getIndex() 2.IndexedColors.AUTOMATIC.getIndex() 3.IndexedColors.BLUE.getIndex() 4.IndexedColors.BLUE_GREY.getIndex() 5.IndexedColors.BRIGHT_GREEN.getIndex() ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,229
精华内容 891
关键字:

poi设置单元格背景色