/// <summary>
        /// Initializes a new instance of the <see cref="FormulaRecordAggregate"/> class.
        /// </summary>
        /// <param name="formulaRec">The formula rec.</param>
        /// <param name="stringRec">The string rec.</param>
        /// <param name="svm">The SVM.</param>
        public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm)
        {
            if (svm == null)
            {
                throw new ArgumentException("sfm must not be null");
            }
            if (formulaRec.HasCachedResultString)
            {
                if (stringRec == null)
                {
                    throw new RecordFormatException("Formula record flag is set but String record was not found");
                }
                _stringRecord = stringRec;
            }
            else
            {
                // Usually stringRec is null here (in agreement with what the formula rec says).
                // In the case where an extra StringRecord is erroneously present, Excel (2007)
                // ignores it (see bug 46213).
                _stringRecord = null;
            }

            _formulaRecord = formulaRec;
            _sharedValueManager = svm;
            if (formulaRec.IsSharedFormula)
            {
                CellReference firstCell = formulaRec.Formula.ExpReference;
                if (firstCell == null)
                {
                    HandleMissingSharedFormulaRecord(formulaRec);
                }
                else
                {
                    _sharedFormulaRecord = svm.LinkSharedFormulaRecord(firstCell, this);
                }
            }
        }
 public override Object Clone()
 {
     FormulaRecord rec = new FormulaRecord();
     CopyBaseFields(rec);
     rec.field_4_value = field_4_value;
     rec.field_5_options = field_5_options;
     rec.field_6_zero = field_6_zero;
     rec.field_8_parsed_expr = field_8_parsed_expr.Copy();
     rec.specialCachedValue = specialCachedValue;
     return rec;
 }
 /**
  * Sometimes the shared formula flag "seems" to be erroneously Set, in which case there is no 
  * call to <c>SharedFormulaRecord.ConvertSharedFormulaRecord</c> and hence the 
  * <c>ParsedExpression</c> field of this <c>FormulaRecord</c> will not Get updated.<br/>
  * As it turns out, this is not a problem, because in these circumstances, the existing value
  * for <c>ParsedExpression</c> is perfectly OK.<p/>
  * 
  * This method may also be used for Setting breakpoints to help diagnose Issues regarding the
  * abnormally-Set 'shared formula' flags. 
  * (see TestValueRecordsAggregate.testSpuriousSharedFormulaFlag()).<p/>
  * 
  * The method currently does nothing but do not delete it without Finding a nice home for this 
  * comment.
  */
 static void HandleMissingSharedFormulaRecord(FormulaRecord formula)
 {
     // could log an info message here since this is a fairly Unusual occurrence.
 }
Exemple #4
0
 /// <summary>
 /// Checks the type of the formula cached value.
 /// </summary>
 /// <param name="expectedTypeCode">The expected type code.</param>
 /// <param name="fr">The fr.</param>
 private void CheckFormulaCachedValueType(CellType expectedTypeCode, FormulaRecord fr)
 {
     CellType cachedValueType = fr.CachedResultType;
     if (cachedValueType != expectedTypeCode)
     {
         throw TypeMismatch(expectedTypeCode, cachedValueType, true);
     }
 }
 /// <summary>
 /// Sometimes the shared formula flag "seems" to be erroneously set (because the corresponding
 /// SharedFormulaRecord does not exist). Normally this would leave no way of determining
 /// the Ptg tokens for the formula.  However as it turns out in these
 /// cases, Excel encodes the unshared Ptg tokens in the right place (inside the FormulaRecord). 
 /// So the the only thing that needs to be done is to ignore the erroneous
 /// shared formula flag.
 /// 
 /// This method may also be used for setting breakpoints to help diagnose issues regarding the
 /// abnormally-set 'shared formula' flags.
 /// </summary>
 /// <param name="formula">The formula.</param>
 private static void HandleMissingSharedFormulaRecord(FormulaRecord formula)
 {
     // make sure 'unshared' formula is actually available
     Ptg firstToken = formula.ParsedExpression[0];
     if (firstToken is ExpPtg)
     {
         throw new RecordFormatException(
                 "SharedFormulaRecord not found for FormulaRecord with (isSharedFormula=true)");
     }
     // could log an info message here since this is a fairly unusual occurrence.
     formula.IsSharedFormula = false; // no point leaving the flag erroneously set
 }
        /**
 * @return the equivalent {@link Ptg} array that the formula would have, were it not shared.
 */
        public Ptg[] GetFormulaTokens(FormulaRecord formula)
        {
            int formulaRow = formula.Row;
            int formulaColumn = formula.Column;
            //Sanity checks
            if (!IsInRange(formulaRow, formulaColumn))
            {
                throw new Exception("Shared Formula Conversion: Coding Error");
            }
            SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);
            return sf.ConvertSharedFormulas(field_7_parsed_expr.Tokens, formulaRow, formulaColumn);
            //return ConvertSharedFormulas(field_7_parsed_expr.Tokens, formulaRow, formulaColumn);
        }
 public FormulaRecordAggregate CreateFormula(int row, int col)
 {
     FormulaRecord fr = new FormulaRecord();
     fr.Row=(row);
     fr.Column=((short)col);
     return new FormulaRecordAggregate(fr, null, _sharedValueManager);
 }