POI IndexedColors 編碼與顏色對照

 

使用方法:

  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 POIFillAndColorDemo {
      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(1);

          // Orange "foreground", foreground being the fill foreground not the
          // font color.
          style = workbook.createCellStyle();
          style.setFillForegroundColor(IndexedColors.AUTOMATIC.getIndex());
          style.setFillPattern(CellStyle.SOLID_FOREGROUND);
          Font headerFont = wb.createFont();
		  headerFont.setFontName("Arial");
		  headerFont.setFontHeightInPoints((short) 10);
		  headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		  headerFont.setColor(IndexedColors.WHITE.getIndex());
          style.setFont(cellFont);
          cell = row.createCell(2);
          cell.setCellValue("Color");   
          cell.setCellStyle(style);
}

}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章