重写jxl中可用的颜色实现自定义颜色

在jxl组建中没有提供直接的自定义16进制颜色的方法,但是可以通过他的某些方法来实现

参考方法如下:

package com.manager.util;

import java.awt.Color;
 import java.io.File;

import jxl.Workbook;
 import jxl.format.Colour;
 import jxl.write.Label;
 import jxl.write.WritableCellFormat;
 import jxl.write.WritableFont;
 import jxl.write.WritableSheet;
 import jxl.write.WritableWorkbook;
 /**
  * 
  * @author Free Everyday
  * jxl通过重现颜色对象,实现自定义颜色
  */
 public class GetJxlColour {
  public static void main(String[] args) {
   try {
    WritableWorkbook book = Workbook.createWorkbook(new File("测试.xls"));
    Color color = Color.decode("#FFFFFF");//自定义的颜色
    //重写一个颜色值,以Colour.ORANGE为例
    book.setColourRGB(Colour.ORANGE, color.getRed(), color.getGreen(), color.getBlue());
    Colour testColour = Colour.ORANGE;
    //格式化
    WritableFont font = new WritableFont(WritableFont.TIMES,12);//字体样式
    font.setColour(testColour);
    WritableCellFormat format = new WritableCellFormat(font);//单元格样式
    WritableSheet sheet = book.createSheet("测试", 0);
    Label label = new Label(0,0,"测试颜色",format);
    sheet.addCell(label);//添加到表单
    book.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
 }

 

 

你可能感兴趣的:(JXL,自定义颜色)