0

是否可以创建一个包含 Font、NumberFormat、BackgroundColor 和 Border 的 jxl.WritableCellFormat 属性?

这有效:

public static final NumberFormat numberformatter = new NumberFormat("#,###0.00");  
public static final WritableFont defaultfont = new WritableFont(WritableFont.TAHOMA, 10); 
public static final WritableCellFormat numberCellFormat = new WritableCellFormat(defaultfont, numberformatter); '

但我无法获得边框和颜色,认为创建工作表时需要多次使用相同类型的单元格。

4

2 回答 2

2

实例化单元格后,您可以通过WritableCellFormat.setBorder()和方法设置边框和背景。WritableCellFormat.setBackground()

你可以在那里看到 API 。

如果你必须做很多事情,你可以像这样创建一个辅助函数:

public static makeCell(NumberFormat format, WritableFont font, Color backgrd, Border border){
    final WritableCellFormat result = new WritableCellFormat(defaultfont, numberformatter);
    result.setBorder(border);
    result.setBackground(backgrd);
    return result;
}
于 2011-01-05T12:30:29.753 回答
0

你可以通过2个步骤做到这一点

  1. 创建可写字体

  2. 以 WritableFont,NumberFormats 作为参数创建 WritableCellFormat

附上代码片段

int fontSize = 8;  
WritableFont wfontStatus = new WritableFont(WritableFont.ARIAL, fontSize);
wfontStatus.setColour(Colour.BLACK);
wfontStatus.setBoldStyle(WritableFont.BOLD);

WritableCellFormat fCellstatus = new WritableCellFormat(wfontStatus, NumberFormats.TEXT); // You can use any NumberFormats I have used TEXT for my requirement
try {
    fCellstatus.setWrap(true);
    fCellstatus.setBorder(Border.ALL,BorderLineStyle.THIN);
    fCellstatus.setAlignment(Alignment.CENTRE);
    fCellstatus.setBackground(Colour.YELLOW);
} 
catch (WriteException e) {
    e.printStackTrace();
 }
于 2015-07-28T11:01:14.130 回答