C#コード例条件付きフォーマットを適用して、重複、一意の数値をハイライトする

3157 ワード

using Spire.Xls;using System.Drawing;
namespace HightDuplicateData_XLS{class Program{static void Main(string[]args){//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){//ワークブッククラスワークブック=newワークブック();//テストドキュメントワークブック.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){//ワークブッククラスワークブック=newワークブック();//ドキュメントワークブック.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.sz 886.com