我们使用sqlsheet库从Excel工作表中读取数据。 lib工作正常,但有一个问题,字段由公式计算。该单元格的值始终为空。
有没有办法告诉sqlsheet在执行数据查询之前评估单元格公式?
答案 0 :(得分:1)
I decompiled the driver and within the XLSResultSet of the net.pcal.sqlsheet added in the following hssf cell check:
public static String getStrVal(Cell cell) {
long ival = 0;
Boolean bool = false;
String cData = "";
switch(cell.getCellType()){
case Cell.CELL_TYPE_BLANK:
cData = null;
break;
case Cell.CELL_TYPE_STRING:
cData = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_FORMULA:
switch(cell.getCachedFormulaResultType()) {
case Cell.CELL_TYPE_NUMERIC:
cData = String.valueOf(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
cData = String.valueOf(cell.getRichStringCellValue());
break;
}
break;
default:
cData = "unsupported cell type";
break;
}
return cData;
}
Then to the existing string check modified it so it is as follows:
public String getString(String jdbcColumn) throws SQLException {
Cell cell = getCell(jdbcColumn);
if (cell == null) {
return cell == null ? null : formatter.formatCellValue(cell);
}else{
String myCell = getStrVal(cell);
return myCell;
}
}
This resolved the issue for both formulas and for referenced cells.