示例#1
0
  public Cell getCell(CellCoord cell) {
    int sheet = getSheet(cell);

    try {
      return workbook.getSheetAt(sheet).getRow(cell.getRow()).getCell(cell.getCol());
    } catch (Exception ex) {
      return null;
    }
  }
示例#2
0
  public String getStringValue(CellCoord cellCoord) {
    int sheet = getSheet(cellCoord);

    if (sheet < 0 || cellCoord.getCol() < 0 || cellCoord.getRow() < 0) return null;

    Cell cell = getCell(cellCoord);

    if (cell == null) return null;

    switch (cell.getCellType()) {
      case Cell.CELL_TYPE_NUMERIC:
        Double _value = cell.getNumericCellValue();
        return _value == _value.longValue()
            ? String.format("%d", _value.longValue())
            : String.format("%s", _value);
      case Cell.CELL_TYPE_STRING:
        return cell.getStringCellValue();
      default:
        break;
    }

    return "";
  }
示例#3
0
  public Double getDoubleValue(CellCoord cellCoord) {
    int sheet = getSheet(cellCoord);

    if (sheet < 0 || cellCoord.getCol() < 0 || cellCoord.getRow() < 0) return null;

    Double result = 0d;
    Cell cell = getCell(cellCoord);

    int cellType =
        cell.getCellType() == Cell.CELL_TYPE_FORMULA
            ? cell.getCachedFormulaResultType()
            : cell.getCellType();

    switch (cellType) {
      case Cell.CELL_TYPE_NUMERIC:
        return cell.getNumericCellValue();
      case Cell.CELL_TYPE_STRING:
        return ParserUtils.getDoubleResult(cell.getStringCellValue());
      default:
        break;
    }

    return result;
  }
示例#4
0
 private int getSheet(CellCoord cell) {
   return cell.getSheet() >= 0 ? cell.getSheet() : defaultSheet;
 }