[英]Apache POI: changing CellType causes IllegalStateException
为什么在Apache POI中更改单元格类型是非法的? 下面的代码导致IllegalStateException: Cannot get a error value from a numeric cell
。
Cell mycell = myrow.createCell(0);
// Make it numeric by default.
mycell.setCellType(Cell.CELL_TYPE_NUMERIC);
if (someCondition) {
mycell.setCellType(Cell.CELL_TYPE_STRING); // IllegalStateException
}
也许有办法解决这个问题(例如不引入其他逻辑)?
我不确定这是否会避免您的“没有其他逻辑”,但是这里有:
Cell mycell = myrow.createCell(0);
// Make it numeric by default.
int cellType = Cell.CELL_TYPE_NUMERIC;
if (someCondition) {
cellType = Cell.CELL_TYPE_STRING;
}
mycell.setCellType(cellType);
Javadoc没有说明为什么会抛出IllegalStateException
所以我只是避免这样做(通过执行上述操作)或在源代码中进行挖掘。
修复。 更换流版本(后org.apache.poi.xssf.streaming.SXSSFWorkbook
与非流之一)( org.apache.poi.xssf.usermodel.XSSFWorkbook
)除外不见了。 我对XSSFWorkbook没问题,因为我仅用几行填充XLSX。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.