示例#1
0
        public void MakePreview(BBAddIn addIn)
        {
            addIn.bbColorSmells.decolorCells(transformationCells);
            if (addIn.theRibbon.dropDown1.Items.Count > 0) //if we have transformations available
            {
                FSharpTransformationRule T = AllTransformations.FirstOrDefault(x => x.Name == addIn.theRibbon.dropDown1.SelectedItem.Label);

                Excel.Range R       = (addIn.Application.Selection);
                string      formula = BBTransformations.RemoveFirstSymbol((string)R[1, 1].Formula);
                addIn.theRibbon.Preview.Text           = T.ApplyOn(formula);
                addIn.theRibbon.valuePreview.Text      = getValue((ExcelRaw.Range)R[1, 1].UnderlyingObject, addIn.theRibbon.Preview.Text);
                addIn.theRibbon.valuePreview.ShowImage = (addIn.theRibbon.valuePreview.Text != R[1, 1].Value.ToString());

                if (R.Count == 1)
                {
                    foreach (Excel.Worksheet worksheet in addIn.Application.Worksheets)
                    {
                        applyInRange(T, (ExcelRaw.Range)worksheet.UsedRange.UnderlyingObject, true);
                    }
                }
                else
                {
                    applyInRange(T, addIn.Application.Selection, true);
                }
            }
        }
示例#2
0
        private void readTransformationRules(ExcelRaw.Worksheet rules)
        {
            //find last filled cells
            int Lower = 50;

            AllTransformations.Clear();

            for (int i = 1; i <= Lower; i++)
            {
                string From = (string)rules.Cells[i, 1].Value;
                if (From != null)
                {
                    string To   = (string)rules.Cells[i, 2].Value;
                    double prio = (double)rules.Cells[i, 3].Value;
                    string Name = (string)rules.Cells[i, 4].Value;

                    AllTransformations.Add(new FSharpTransformationRule(Name, From, To, prio));
                }
            }


            //order by priority
            AllTransformations.Sort();
        }
示例#3
0
        public void ApplyTransformation(ApplyTo scope)
        {
            if (addIn.theRibbon.dropDown1.SelectedItem == null)
            {
                addIn.Log("ApplyTransformation tried with empty dropdown");
                return;
            }

            addIn.bbColorSmells.decolorCells(transformationCells);

            addIn.Log("Apply in " + scope.ToString() + " transformation " + addIn.theRibbon.dropDown1.SelectedItem.Label);

            FSharpTransformationRule T = AllTransformations.FirstOrDefault(x => x.Name == addIn.theRibbon.dropDown1.SelectedItem.Label);

            switch (scope)
            {
            case ApplyTo.Range:
                applyInRange(T, addIn.Application.Selection);
                break;

            case ApplyTo.Worksheet:
                applyInRange(T, addIn.Application.ActiveSheet.UsedRange);
                break;

            case ApplyTo.Workbook:
                foreach (ExcelRaw.Worksheet worksheet in addIn.Application.Worksheets)
                {
                    applyInRange(T, worksheet.UsedRange);
                }
                break;
            }

            //after applying, we want to empty the preview box, find new rewrites and show them (in dropdown and preview)
            FindApplicableTransformations();
            addIn.bbTransformations.MakePreview(addIn);
        }