using Spire.Xls;
using System.Drawing;

namespace HightDuplicateData_XLS
{
class Program
{
static void Main(string[] args)
{
//实例化Workbook类,加载测试文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xlsx");

        //获取第一个工作表
        Worksheet sheet = workbook.Worksheets[0];

        //应用条件格式1到指定数据范围,高亮重复数值的单元格
        ConditionalFormatWrapper format1 = sheet.Range["A3:A13"].ConditionalFormats.AddCondition();
        format1.FormatType = ConditionalFormatType.DuplicateValues;
        format1.BackColor = Color.Cyan;

        //应用条件格式2到指定数据范围,高亮唯一值的单元格
        ConditionalFormatWrapper format2 = sheet.Range["A3:A13"].ConditionalFormats.AddCondition();
        format2.FormatType = ConditionalFormatType.UniqueValues;
        format2.BackColor = Color.Yellow;

        //保存文档并打开            
        workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
        System.Diagnostics.Process.Start("result.xlsx");
    }
}

}
复制代码
using Spire.Xls;
using System.Drawing;

namespace HighlightTopData_XLS
{
class Program
{
static void Main(string[] args)
{
//实例化workbook类
Workbook workbook = new Workbook();
//加载测试文档
workbook.LoadFromFile("test.xlsx");

        //获取第一个工作表
        Worksheet sheet = workbook.Worksheets[0];

        //应用条件格式1到指定范围,并高亮最高(依次排序)的两个数值
        ConditionalFormatWrapper format1 = sheet.Range["B17:B24"].ConditionalFormats.AddCondition();
        format1.FormatType = ConditionalFormatType.TopBottom;
        format1.TopBottom.Type = TopBottomType.Top;
        format1.TopBottom.Rank = 2;
        format1.BackColor = Color.Green;

        //应用条件格式2到指定范围,并高亮最低(依次排序)的两个数值
        ConditionalFormatWrapper format2 = sheet.Range["B17:B24"].ConditionalFormats.AddCondition();
        format2.FormatType = ConditionalFormatType.TopBottom;
        format2.TopBottom.Type = TopBottomType.Bottom;
        format2.TopBottom.Rank = 2;
        format2.BackColor = Color.RosyBrown;

        //保存并打开文档
        workbook.SaveToFile("output.xlsx", ExcelVersion.Version2013);
        System.Diagnostics.Process.Start("output.xlsx");
    }
}

}
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Core;
using Spire.Xls.Core.Spreadsheet.Collections;

namespace Average_Condition
{
class Program
{
static void Main(string[] args)
{
//实例化workbook类
Workbook workbook = new Workbook();
//加载文档
workbook.LoadFromFile("test.xlsx");

        //获取第一个工作表
        Worksheet sheet = workbook.Worksheets[0];

        //添加条件格式1并应用到指定数据范围
        XlsConditionalFormats format1 = sheet.ConditionalFormats.Add();
        format1.AddRange(sheet.Range["B17:B24"]);
        //高亮低于平均数值的单元格
        IConditionalFormat cf1 = format1.AddAverageCondition(AverageType.Below);
        cf1.BackColor = Color.SkyBlue;

        //添加条件格式2并应用到指定数据范围
        XlsConditionalFormats format2 = sheet.ConditionalFormats.Add();
        format2.AddRange(sheet.Range["B17:B24"]);
        //高亮高于平均数值的单元格
        IConditionalFormat cf2 = format1.AddAverageCondition(AverageType.Above);
        cf2.BackColor = Color.Orange;

        //保存并打开文档
        workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
        System.Diagnostics.Process.Start("result.xlsx");
    }
}

}
深圳网站建设www.sz886.com