2013-01-12 94 views
-3

如何色彩格式添加到使用JExcel API.I的Excel單元格有現成的excel文件,並想如何顏色格式添加到所需的細胞Excel文件操作

+1

這將是有益的,看看你的努力。 – Lion

回答

1

my answermodifying the excel cells using JExcel API。該答案僅適用於您:)


要將顏色格式添加到excel單元格,請嘗試下面的代碼。

// Create cell font and format 
private static WritableCellFormat getCellFormat(Colour colour, Pattern pattern) throws WriteException { 
    WritableFont cellFont = new WritableFont(WritableFont.TIMES, 16); 
    WritableCellFormat cellFormat = new WritableCellFormat(cellFont); 
    cellFormat.setBackground(colour, pattern); 
    return cellFormat; 
} 

// Create the label, specifying content and format 
Label label = new Label(1, 2, "ABC", getCellFormat(Colour.GREEN, Pattern.GRAY_25)); 
Label label2 = new Label(1, 4, "PQR", getCellFormat(Colour.BLUE, Pattern.GRAY_50)); 
Label label3 = new Label(1, 6, "XYZ", getCellFormat(Colour.ORANGE, Pattern.GRAY_75)); 

sheet.addCell(label); 
sheet.addCell(label2); 
sheet.addCell(label3); 

越來越sheet在上面的鏈接已經提供..