示例#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();
     }
 }
示例#2
0
 static void AddColorScale3ConditionalFormatting(IWorkbook workbook)
 {
     #region #ColorScale3ConditionalFormatting
     Worksheet worksheet = workbook.Worksheets["cfBooks"];
     workbook.Worksheets.ActiveWorksheet = worksheet;
     ConditionalFormattingValue       minPoint = worksheet.ConditionalFormattings.CreateValue(ConditionalFormattingValueType.Formula, "=MIN($E$5:$F$18)");
     ConditionalFormattingValue       midPoint = worksheet.ConditionalFormattings.CreateValue(ConditionalFormattingValueType.Percentile, "50");
     ConditionalFormattingValue       maxPoint = worksheet.ConditionalFormattings.CreateValue(ConditionalFormattingValueType.Number, "=MAX($E$5:$F$18)");
     ColorScale3ConditionalFormatting cfRule   = worksheet.ConditionalFormattings.AddColorScale3ConditionalFormatting(worksheet.Range["$D$5:$E$18"], minPoint, Color.Red, midPoint, Color.Yellow, maxPoint, Color.SkyBlue);
     worksheet["B2"].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.";
     worksheet.Visible     = true;
     #endregion #ColorScale3ConditionalFormatting
 }