Beispiel #1
0
 static void AddRankConditionalFormatting(IWorkbook workbook)
 {
     workbook.Calculate();
     workbook.BeginUpdate();
     try
     {
         Worksheet worksheet = workbook.Worksheets["cfBooks"];
         workbook.Worksheets.ActiveWorksheet = worksheet;
         #region #RankConditionalFormatting
         // Create the rule to identify top three values in cells F2 through F15.
         RankConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddRankConditionalFormatting(worksheet["$F$2:$F$15"], ConditionalFormattingRankCondition.TopByRank, 3);
         // Specify formatting options to be applied to cells if the condition is true.
         // Set the background color to dark orchid.
         cfRule.Formatting.Fill.BackgroundColor = Color.DarkOrchid;
         // Set the outline borders.
         cfRule.Formatting.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
         // Set the font color to white.
         cfRule.Formatting.Font.Color = Color.White;
         #endregion #RankConditionalFormatting
         // Add an explanation to the created rule.
         CellRange ruleExplanation = worksheet.Range["A17:G18"];
         ruleExplanation.Value = "Identify the top three price values.";
     }
     finally
     {
         workbook.EndUpdate();
     }
 }
Beispiel #2
0
        public static void ApplyTopImportsConditionalFormatting(Worksheet sheet)
        {
            ConditionalFormattingCollection conditionalFormattings = sheet.ConditionalFormattings;
            RankConditionalFormatting       cfRule2 = conditionalFormattings.AddRankConditionalFormatting(sheet["Table[Imports]"], ConditionalFormattingRankCondition.TopByRank, 5);

            cfRule2.Formatting.Fill.BackgroundColor = Color.FromArgb(0xFC, 0xB3, 0xB3);
        }
Beispiel #3
0
 static void AddRankConditionalFormatting(IWorkbook workbook)
 {
     #region #RankConditionalFormatting
     Worksheet worksheet = workbook.Worksheets["cfBooks"];
     workbook.Worksheets.ActiveWorksheet = worksheet;
     RankConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddRankConditionalFormatting(worksheet["$G$5:$G$18"], ConditionalFormattingRankCondition.TopByRank, 3);
     cfRule.Formatting.Fill.BackgroundColor = Color.DarkOrchid;
     cfRule.Formatting.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
     cfRule.Formatting.Font.Color = Color.White;
     worksheet["B2"].Value        = "In the report below identify the top three price values.";
     worksheet.Visible            = true;
     #endregion #RankConditionalFormatting
 }