可以创建一个包含字体、NumberFormat、BackgroundColor和边框的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); '但是我无法获得边框和颜色,因为在创建工作表时需要多次使用相同类型的单元格。
发布于 2011-01-05 20:30:30
在实例化单元格之后,可以通过WritableCellFormat.setBorder()和WritableCellFormat.setBackground()方法设置边框和背景。
您可以看到there接口。
如果你不得不经常这样做,你可以像这样做一个helper函数:
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;
}发布于 2015-07-28 19:01:14
您可以通过以下两个步骤完成此操作
附加代码片段
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();
}https://stackoverflow.com/questions/4603605
复制相似问题