2013-01-12 53 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在上面的链接已经提供..