1

sqlsheet ライブラリを使用して、Excel シートからデータを読み取ります。ライブラリは正常に動作しますが、数式によって計算されるフィールドには問題があります。そのセルの値は常に空です。

データ クエリを実行する前にセルの数式を評価するように sqlsheet に指示する方法はありますか?

4

1 に答える 1

1

ドライバーを逆コンパイルし、次の hssf セル チェックで追加された net.pcal.sqlsheet の XLSResultSet 内で:

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;
}

次に、既存の文字列チェックを変更して、次のようにします。

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;
    }
}

これにより、数式と参照セルの両方の問題が解決されました。

于 2015-05-04T19:28:09.427 に答える