Display evaluated formula with entered values
<p>I need help to script the function which will evaluate a formula.</p>

<p>Example:</p>

<pre><code>Cell A1 = 1
Cell B1 = 2
Cell C1 = A1 + B1, which displays the sum of two numbers = 3
Cell D1 `= 1 + 2, which displays above formula with entered values
</code></pre>

<p>How can I do this?</p>

<p><strong>UPDATE</strong></p>

<p>I have found only script which takes the formula and display it as it is without entered values in formula parameters, i.e. `= A1 + B1</p>

<pre><code>function GETFORMULA(reference) {
  var ss = SpreadsheetApp;
  var sheet = ss.getActiveSheet();
  var formula = ss.getActiveRange().getFormula();
  var args = formula.match(/=\w+\((.*)\)/i);
  try {
    var range = sheet.getRange(args[1]);
  }
  catch(e) {
    throw new Error(args[1] + ' is not a valid range');
  }
  return range.getFormula();
}
</code></pre>