-3

如何使用 JExcel API 将颜色格式添加到 excel 单元格。我有一个现有的 excel 文件并想要如何将颜色格式添加到所需的单元格

4

1 回答 1

1

请参阅我的答案modifying 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上面的链接中已经提供了获取..

于 2013-01-12T18:45:05.227 回答