コード例 #1
0
        public void RecalcCellReferences(SheetChange sheetChange)
        {
            foreach (var i in this.Cells())
            {
                var c = i.Value;
                if (c.Formula != null)
                {
                    c.Formula.Text      = ExcelFormula.TranslateForSheetChange(c.Formula.Text, sheetChange, _wsheet.Name);
                    c.Formula.R1        = ExcelRange.TranslateForSheetChange(c.Formula.R1, sheetChange, _wsheet.Name);
                    c.Formula.R2        = ExcelRange.TranslateForSheetChange(c.Formula.R2, sheetChange, _wsheet.Name);
                    c.Formula.Reference = ExcelRange.TranslateForSheetChange(c.Formula.Reference, sheetChange, _wsheet.Name);
                }
            }

            // Adjust conditional formatting
            List <ConditionalFormatting> cfToRemoveList = new List <ConditionalFormatting>();

            foreach (var cf in this.GetElements <ConditionalFormatting>())
            {
                bool removeCf          = false;
                List <StringValue> lst = new List <StringValue>();
                foreach (var sqrefItem in cf.SequenceOfReferences.Items)
                {
                    string newRef = ExcelRange.TranslateForSheetChange(sqrefItem.Value, sheetChange, _wsheet.Name);
                    if (!newRef.StartsWith("#")) // no error
                    {
                        lst.Add(new StringValue(newRef));
                    }
                    else
                    {
                        cfToRemoveList.Add(cf);
                        removeCf = true;
                        break;
                    }
                }
                if (removeCf)
                {
                    break;
                }
                cf.SequenceOfReferences = new ListValue <StringValue>(lst);
                foreach (var f in cf.Descendants <Formula>())
                {
                    f.Text = ExcelFormula.TranslateForSheetChange(f.Text, sheetChange, _wsheet.Name);
                }
            }
            foreach (ConditionalFormatting cf in cfToRemoveList)
            {
                this.RemoveElement(cf);
            }
        }
コード例 #2
0
        public void RecalcCellReferences(SheetChange sheetChange)
        {
            foreach (KeyValuePair <ulong, CellProxy> pair in this.Cells())
            {
                CellProxy proxy = pair.Value;
                if (proxy.Formula != null)
                {
                    proxy.Formula.Text      = ExcelFormula.TranslateForSheetChange(proxy.Formula.Text, sheetChange, this._wsheet.Name);
                    proxy.Formula.R1        = ExcelRange.TranslateForSheetChange(proxy.Formula.R1, sheetChange, this._wsheet.Name);
                    proxy.Formula.R2        = ExcelRange.TranslateForSheetChange(proxy.Formula.R2, sheetChange, this._wsheet.Name);
                    proxy.Formula.Reference = ExcelRange.TranslateForSheetChange(proxy.Formula.Reference, sheetChange, this._wsheet.Name);
                }
            }
            List <ConditionalFormatting> list = new List <ConditionalFormatting>();

            foreach (ConditionalFormatting formatting in this.GetElements <ConditionalFormatting>())
            {
                bool flag = false;
                List <StringValue> list2 = new List <StringValue>();
                foreach (StringValue value2 in formatting.SequenceOfReferences.Items)
                {
                    string str = ExcelRange.TranslateForSheetChange(value2.Value, sheetChange, this._wsheet.Name);
                    if (!str.StartsWith("#"))
                    {
                        list2.Add(new StringValue(str));
                    }
                    else
                    {
                        list.Add(formatting);
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
                formatting.SequenceOfReferences = new ListValue <StringValue>(list2);
                foreach (Formula formula in formatting.Descendants <Formula>())
                {
                    formula.Text = ExcelFormula.TranslateForSheetChange(formula.Text, sheetChange, this._wsheet.Name);
                }
            }
            foreach (ConditionalFormatting formatting2 in list)
            {
                this.RemoveElement(formatting2);
            }
        }