Exemple #1
0
 /// <summary>
 /// Helper method that evaluates the cell's _value, given its content.
 ///
 /// The value of a cell can be (1) a string, (2) a double, or (3) a FormulaError.
 /// (By analogy, the value of an Excel cell is what is displayed in that cell's position
 /// in the grid.)
 ///
 /// If a cell's contents is a string, its value is that string.
 ///
 /// If a cell's contents is a double, its value is that double.
 ///
 /// If a cell's contents is a Formula, its value is either a double or a FormulaError.
 /// The value of a Formula, of course, can depend on the values of variables.  The value
 /// of a Formula variable is the value of the spreadsheet cell it names (if that cell's
 /// value is a double) or is undefined (otherwise).  If a Formula depends on an undefined
 /// variable or on a division by zero, its value is a FormulaError.  Otherwise, its value
 /// is a double, as specified in Formula.Evaluate.
 /// </summary>
 public void Evaluate(Formula.Lookup lookup)
 {
     if (_contents is Formula)
     {
         try
         {
             _value = _contents.Evaluate(lookup);
         }
         catch (FormulaEvaluationException)
         {
             _value = new FormulaError("Formula could not be evaluated.");
         }
     }
     else if (_contents is string || _contents is double)
     {
         _value = _contents;
     }
     else
     {
         throw new Microsoft.CSharp.RuntimeBinder.RuntimeBinderException();
     }
 }
Exemple #2
0
 /// <summary>
 /// Initializes this cell, which will be named (name) and contain content (content).
 ///
 /// Note: content will necessarily, by virtue of SetCellContents, be of type string, double,
 /// or Formula. However, this constructor still calls SetContent to make sure the object
 /// parameter is always an allowable type.
 /// </summary>
 public Cell(dynamic content, Formula.Lookup lookup)
 {
     SetContent(content);
     Evaluate(lookup);
 }