Exemple #1
0
        /// <summary>
        /// Translate a fornula due to a sheet change, e.g. insertion of rows.
        /// </summary>
        /// <param name="formula">Formula, e.g. SUM(A1,Sheet2!B2)</param>
        /// <param name="sheetChange">Details of change</param>
        /// <param name="currentSheetName">The sheet where the range is, to determine if this range is affected. If sheetChange.SheetName is null and currentSheetName is null, translation is always applied.</param>
        /// <param name="currentSheetName">The sheet where the range is, to determine if this range is affected. If sheetChange.SheetName is null and currentSheetName is null, translation is always applied.</param>
        /// <returns></returns>
        public static string TranslateForSheetChange(string formula, SheetChange sheetChange, string currentSheetName)
        {
            if (formula == null)
            {
                return(null);
            }

            ParseTree     tree    = ExcelFormula.Parse(formula);
            StringBuilder rebuilt = new StringBuilder();

            if (tree.Errors.Count > 0)
            {
                throw new ArgumentException("Error in parsing formula");
            }
            BuildTranslated(rebuilt, tree,
                            n => TranslateRangeParseNodeForSheetChange(n, sheetChange, currentSheetName));
            return(rebuilt.ToString());
        }
Exemple #2
0
        /// <summary>
        /// Translate a formula.
        /// </summary>
        /// <param name="formula">Formula, e.g. SUM(A1,Sheet2!B2)</param>
        /// <param name="rowDelta">Number of rows to move up(+) or down(-)</param>
        /// <param name="colDelta">Number of columns to move right(+) or left(-)</param>
        /// <returns></returns>
        public static string Translate(string formula, int rowDelta, int colDelta)
        {
            if (formula == null)
            {
                return(null);
            }

            ParseTree     tree    = ExcelFormula.Parse(formula);
            StringBuilder rebuilt = new StringBuilder();

            if (tree.Errors.Count > 0)
            {
                throw new ArgumentException("Error in parsing formula");
            }
            BuildTranslated(rebuilt, tree,
                            n => TranslateRangeParseNodeWithOffset(n, rowDelta, colDelta));
            return(rebuilt.ToString());
        }