1. 程式人生 > >Excel轉Html(七)--Excel-cell>背景和紋理-setFillPattern

Excel轉Html(七)--Excel-cell>背景和紋理-setFillPattern

  1. HSSFCellStyle style = workbook.createCellStyle();
  2. style.setFillForegroundColor(HSSFColor.GREEN.index);//設定圖案顏色
  3. style.setFillBackgroundColor(HSSFColor.RED.index);//設定圖案背景色
  4. style.setFillPattern(HSSFCellStyle.SQUARES);//設定圖案樣式
  5. cell.setCellStyle(style);

     圖案樣式及其對應的值:

CellStyle:

    public static final short NO_FILL = 0;
    
    public static final short SOLID_FOREGROUND = 1;
    
    public static final short FINE_DOTS = 2;
    
    public static final short ALT_BARS = 3;
    
    public static final short SPARSE_DOTS = 4;
    
    public static final short THICK_HORZ_BANDS = 5;
    
    public static final short THICK_VERT_BANDS = 6;
    
    public static final short THICK_BACKWARD_DIAG = 7;
    
    public static final short THICK_FORWARD_DIAG = 8;
    
    public static final short BIG_SPOTS = 9;
    
    public static final short BRICKS = 10;
    
    public static final short THIN_HORZ_BANDS = 11;
    
    public static final short THIN_VERT_BANDS = 12;
    
    public static final short THIN_BACKWARD_DIAG = 13;
    
    public static final short THIN_FORWARD_DIAG = 14;
    
    public static final short SQUARES = 15;
    
    public static final short DIAMONDS = 16;
    
    public static final short LESS_DOTS = 17;
    
    public static final short LEAST_DOTS = 18;

圖案樣式

常量

HSSFCellStyle. NO_FILL

  HSSFCellStyle. SOLID_FOREGROUND

HSSFCellStyle. ALT_BARS

HSSFCellStyle. FINE_DOTS

HSSFCellStyle. SPARSE_DOTS

HSSFCellStyle. LESS_DOTS

HSSFCellStyle. LEAST_DOTS

HSSFCellStyle. BRICKS

HSSFCellStyle. BIG_SPOTS

HSSFCellStyle. THICK_FORWARD_DIAG

HSSFCellStyle. THICK_BACKWARD_DIAG

HSSFCellStyle. THICK_VERT_BANDS

HSSFCellStyle. THICK_HORZ_BANDS

HSSFCellStyle. THIN_HORZ_BANDS

HSSFCellStyle. THIN_VERT_BANDS

HSSFCellStyle. THIN_BACKWARD_DIAG

HSSFCellStyle. THIN_FORWARD_DIAG

HSSFCellStyle. SQUARES

HSSFCellStyle. DIAMONDS