calculatedValue property

String? get calculatedValue

Gets the calculated value of a formula in the Range. Read-only.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.worksheets[0];
sheet.getRangeByName('A1').number = 44;
Range range = sheet.getRangeByName('C1');
range.formula = '=A1';
//Initializes Calculate Engine to perform calculation
sheet.enableSheetCalculations();
String calculatedValue = range.calculatedValue;
List<int> bytes = workbook.saveAsStream();
File('CalculatedValue.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

String? get calculatedValue {
  if (formula != null) {
    if (worksheet.calcEngine != null) {
      final String cellRef = _getAddressLocalFromCalculatedValue(
          row, column, lastRow, lastColumn);
      return worksheet.calcEngine!._pullUpdatedValue(cellRef);
    }
    return null;
  } else {
    return '';
  }
}