Exemplo n.º 1
0
 static void AddColorScale3ConditionalFormatting(IWorkbook workbook)
 {
     workbook.Calculate();
     workbook.BeginUpdate();
     try
     {
         Worksheet worksheet = workbook.Worksheets["cfBooks"];
         workbook.Worksheets.ActiveWorksheet = worksheet;
         #region #ColorScale3ConditionalFormatting
         ConditionalFormattingCollection conditionalFormattings = worksheet.ConditionalFormattings;
         // Set the minimum threshold to the lowest value in the range of cells using the MIN() formula.
         ConditionalFormattingValue minPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.Formula, "=MIN($C$2:$D$15)");
         // Set the midpoint threshold to the 50th percentile.
         ConditionalFormattingValue midPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.Percentile, "50");
         // Set the maximum threshold to the highest value in the range of cells using the MAX() formula.
         ConditionalFormattingValue maxPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.Number, "=MAX($C$2:$D$15)");
         // Create the three-color scale rule to determine how values in cells C2 through D15 vary. Red represents the lower values, yellow represents the medium values and sky blue represents the higher values.
         ColorScale3ConditionalFormatting cfRule = conditionalFormattings.AddColorScale3ConditionalFormatting(worksheet.Range["$C$2:$D$15"], minPoint, Color.Red, midPoint, Color.Yellow, maxPoint, Color.SkyBlue);
         #endregion #ColorScale3ConditionalFormatting
         // Add an explanation to the created rule.
         CellRange ruleExplanation = worksheet.Range["A17:G18"];
         ruleExplanation.Value = "Examine cost distribution using a gradation of three colors. Red represents the lower values, yellow represents the medium values and sky blue represents the higher values.";
     }
     finally
     {
         workbook.EndUpdate();
     }
 }
Exemplo n.º 2
0
        public static void ApplyTemperatureConditionalFormatting(Worksheet sheet)
        {
            ConditionalFormattingCollection conditionalFormattings = sheet.ConditionalFormattings;
            ConditionalFormattingValue      minPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.MinMax);
            ConditionalFormattingValue      midPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.Percentile, "50");
            ConditionalFormattingValue      maxPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.MinMax);

            conditionalFormattings.AddColorScale3ConditionalFormatting(sheet.Range["$C$4:$C$60"], minPoint, Color.FromArgb(255, 0x65, 0x92, 0xAF), midPoint, Color.FromArgb(255, 0xF2, 0xA1, 0x6A), maxPoint, Color.FromArgb(255, 0xFF, 0xD5, 0x55));
            ExpressionConditionalFormatting cfRule = conditionalFormattings.AddExpressionConditionalFormatting(sheet.Range["$C$4:$C$60"], ConditionalFormattingExpressionCondition.GreaterThan, "40");

            cfRule.Formatting.Font.Color = Color.White;
        }