jxl WritableCellFormat 实例不能太多

读写文件,一个输出流《——》一个文件,对应一个读写操作。
jxl写文件,一个输出流flush后,WritableCellFormat 需要重新初始化。
即使,这个变量是类静态变量,这个object仍存在,但写excel时格式化信息失效。
所以如下提供format没任何意义,要提供每次请求都实例话的方法
public static WritableCell getNormalAlignLeftContentCell(int column, int row,
String content) {
return new jxl.write.Label(column, row, content,
CellFormat.initNormalAlignLeftCellFormat());
}

jxl对format实例数量有限制,百个左右。
所以要处理好,文件操作和重新实例化方法调用。
****


cell 格式实例 < 100, 否则回抛
Warning: Maximum number of format records exceeded. Using default format.

使用静态变量

public abstract class CellFormat {

private CellFormat() { }
//format 格式
private static WritableCellFormat defaultFormat1;
private static WritableCellFormat defaultFormat2;
private static WritableCellFormat dateFormat1;
private static WritableCellFormat dateFormat2;
private static WritableCellFormat numFormat1;
private static WritableCellFormat numFormat2;
static {
try {
defaultFormat1 = new WritableCellFormat();
defaultFormat1.setAlignment(jxl.format.Alignment.CENTRE);
defaultFormat1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

defaultFormat2 = new WritableCellFormat();
defaultFormat2.setAlignment(jxl.format.Alignment.LEFT);
defaultFormat2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

dateFormat1 = new WritableCellFormat(new jxl.write.DateFormat("yyyy-MM-dd hh:mm:ss"));
dateFormat1.setAlignment(jxl.format.Alignment.CENTRE);
dateFormat1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

dateFormat2 = new WritableCellFormat(new jxl.write.DateFormat("yyyy年MM月dd日"));
dateFormat2.setAlignment(jxl.format.Alignment.CENTRE);
dateFormat2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

numFormat1 = new WritableCellFormat(new NumberFormat("¥0.00"));
numFormat1.setAlignment(jxl.format.Alignment.CENTRE);
numFormat1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

numFormat2 = new WritableCellFormat(new NumberFormat("0.00"));
numFormat2.setAlignment(jxl.format.Alignment.CENTRE);
numFormat2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
} catch (Exception e) {
e.printStackTrace();
}
}

public static WritableCellFormat initNormalCellFormat() {
return defaultFormat1;
}


public static WritableCellFormat initNormalAlignLeftCellFormat() {
return defaultFormat2;
}


public static WritableCellFormat initDateCellFormat() {
return dateFormat1;
}


public static WritableCellFormat initBirthdayCellFormat() {
return dateFormat2;
}


public static WritableCellFormat initAmountCellFormat() {
return numFormat1;
}


public static WritableCellFormat initFloatMiscCellFormat() {
return numFormat2;
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值