Esempio n. 1
0
 public static void ApplyBalanceTrendConditionalFormatting(Worksheet sheet)
 {
     ConditionalFormattingCollection   conditionalFormattings = sheet.ConditionalFormattings;
     ConditionalFormattingIconSetValue minPoint = sheet.ConditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Formula, "=MIN($F$6:$F$22)", ConditionalFormattingValueOperator.GreaterOrEqual);
     ConditionalFormattingIconSetValue midPoint = sheet.ConditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "0", ConditionalFormattingValueOperator.GreaterOrEqual);
     ConditionalFormattingIconSetValue maxPoint = sheet.ConditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "0.0001", ConditionalFormattingValueOperator.GreaterOrEqual);
     IconSetConditionalFormatting      cfRule   = conditionalFormattings.AddIconSetConditionalFormatting(sheet["Table[Balance]"], IconSetType.Triangles3, new ConditionalFormattingIconSetValue[] { minPoint, midPoint, maxPoint });
 }
Esempio n. 2
0
        public static void ApplyPressureConditionalFormatting(Worksheet sheet)
        {
            ConditionalFormattingCollection   conditionalFormattings = sheet.ConditionalFormattings;
            ConditionalFormattingIconSetValue minPoint = conditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "-1", ConditionalFormattingValueOperator.GreaterOrEqual);
            ConditionalFormattingIconSetValue midPoint = conditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "0", ConditionalFormattingValueOperator.GreaterOrEqual);
            ConditionalFormattingIconSetValue maxPoint = conditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "1", ConditionalFormattingValueOperator.GreaterOrEqual);
            IconSetConditionalFormatting      cfRule   = conditionalFormattings.AddIconSetConditionalFormatting(sheet.Range["$I$4:$I$60"], IconSetType.Triangles3, new ConditionalFormattingIconSetValue[] { minPoint, midPoint, maxPoint });

            cfRule.ShowValue = false;
        }
Esempio n. 3
0
 static void AddIconSetConditionalFormatting(IWorkbook workbook)
 {
     workbook.Calculate();
     workbook.BeginUpdate();
     try
     {
         Worksheet worksheet = workbook.Worksheets["cfBooks"];
         workbook.Worksheets.ActiveWorksheet = worksheet;
         #region #IconSetConditionalFormatting
         ConditionalFormattingCollection conditionalFormattings = worksheet.ConditionalFormattings;
         // Set the first threshold to the lowest value in the range of cells using the MIN() formula.
         ConditionalFormattingIconSetValue minPoint = conditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Formula, "=MIN($E$2:$E$15)", ConditionalFormattingValueOperator.GreaterOrEqual);
         // Set the second threshold to 0.
         ConditionalFormattingIconSetValue midPoint = conditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "0", ConditionalFormattingValueOperator.GreaterOrEqual);
         // Set the third threshold to 0.01.
         ConditionalFormattingIconSetValue maxPoint = conditionalFormattings.CreateIconSetValue(ConditionalFormattingValueType.Number, "0.01", ConditionalFormattingValueOperator.GreaterOrEqual);
         // Create the rule to apply a specific icon from the three arrow icon set to each cell in the range  E2:E15 based on its value.
         IconSetConditionalFormatting cfRule = conditionalFormattings.AddIconSetConditionalFormatting(worksheet.Range["$E$2:$E$15"], IconSetType.Arrows3, new ConditionalFormattingIconSetValue[] { minPoint, midPoint, maxPoint });
         // Specify the custom icon to be displayed if the second condition is true.
         // To do this, set the IconSetConditionalFormatting.IsCustom property to true, which is false by default.
         cfRule.IsCustom = true;
         // Initialize the ConditionalFormattingCustomIcon object.
         ConditionalFormattingCustomIcon cfCustomIcon = new ConditionalFormattingCustomIcon();
         // Specify the icon set where you wish to get the icon.
         cfCustomIcon.IconSet = IconSetType.TrafficLights13;
         // Specify the index of the desired icon in the set.
         cfCustomIcon.IconIndex = 1;
         // Add the custom icon at the specified position in the initial icon set.
         cfRule.SetCustomIcon(1, cfCustomIcon);
         // Hide values of cells to which the rule is applied.
         cfRule.ShowValue = false;
         #endregion #IconSetConditionalFormatting
         // Add an explanation to the created rule.
         CellRange ruleExplanation = worksheet.Range["A17:G18"];
         ruleExplanation.Value = "Identify upward and downward cost trends.";
     }
     finally
     {
         workbook.EndUpdate();
     }
 }