setValueRowCol method

void setValueRowCol(
  1. String value,
  2. int iRow,
  3. int iColumn
)

Sets value for the specified cell.

Implementation

void setValueRowCol(String value, int iRow, int iColumn) {
  final Range range = getRangeByIndex(iRow, iColumn);
  final CellType valType = range.type;
  if (value.isNotEmpty && value[0] == '=') {
    range.setFormula(value.substring(1));
  } else {
    double? doubleValue;
    DateTime? dateValue;
    if (value.runtimeType == double) {
      doubleValue = double.tryParse(value);
    } else {
      dateValue = DateTime.tryParse(value);
    }

    final CultureInfo cultureInfo = book.getCultureInfo();
    final bool bDateTime =
        !value.contains(cultureInfo.dateTimeFormat.dateSeparator) &&
            dateValue != null;
    bool isNumber = doubleValue != null;
    bool isboolean = false;
    bool iserrorStrings = false;
    bool istext = false;

    if (value == 'TRUE' || value == 'FALSE') {
      isboolean = true;
    } else if (value == 'Exception: #N/A' ||
        value == 'Exception: #VALUE!' ||
        value == 'Exception: #REF!' ||
        value == 'Exception: #DIV/0!' ||
        value == 'Exception: #NUM!' ||
        value == 'Exception: #NAME?' ||
        value == 'Exception: #NULL!') {
      iserrorStrings = true;
    } else if (isNumber) {
      // Checks whether the decimal and group separator at correct position.
      isNumber = _checkIsNumber(value, cultureInfo);
    }

    if (value.isNotEmpty && calcEngine!.formulaErrorStrings.contains(value)) {
      istext = true;
    }

    if (valType == CellType.formula) {
      if (isNumber && !bDateTime && doubleValue != null) {
        range.setFormulaNumberValue(doubleValue);
      } else if (bDateTime) {
        range.setFormulaDateValue(dateValue);
      } else if (isboolean) {
        range.setFormulaBooleanValue(value);
      } else if (iserrorStrings) {
        range.setFormulaErrorStringValue(value);
      } else if (value.contains('Exception:') || istext) {
        range.setText(value);
      } else {
        range.setFormulaStringValue(value);
      }
    } else {
      if (isNumber && !bDateTime && doubleValue != null) {
        range.setNumber(doubleValue);
      } else if (bDateTime) {
        range.setDateTime(dateValue);
      } else {
        range.setText(value);
      }
    }
  }
}