ConditionalFormattingIconCollection

ConditionalFormattingIconCollection class

代表一个集合ConditionalFormattingIcon对象.

public class ConditionalFormattingIconCollection : CollectionBase<ConditionalFormattingIcon>

特性

姓名描述
Capacity { get; set; }
Count { get; }
Item { get; }获取指定索引处的 ConditionalFormattingIcon 元素。
Item { get; set; }

方法

姓名描述
Add(ConditionalFormattingIcon)添加ConditionalFormattingIcon对象.
Add(IconSetType, int)添加ConditionalFormattingIcon对象.
BinarySearch(ConditionalFormattingIcon)
BinarySearch(ConditionalFormattingIcon, IComparer<ConditionalFormattingIcon>)
BinarySearch(int, int, ConditionalFormattingIcon, IComparer<ConditionalFormattingIcon>)
Clear()
Contains(ConditionalFormattingIcon)
CopyTo(ConditionalFormattingIcon[])
CopyTo(ConditionalFormattingIcon[], int)
CopyTo(int, ConditionalFormattingIcon[], int, int)
Exists(Predicate<ConditionalFormattingIcon>)
Find(Predicate<ConditionalFormattingIcon>)
FindAll(Predicate<ConditionalFormattingIcon>)
FindIndex(Predicate<ConditionalFormattingIcon>)
FindIndex(int, Predicate<ConditionalFormattingIcon>)
FindIndex(int, int, Predicate<ConditionalFormattingIcon>)
FindLast(Predicate<ConditionalFormattingIcon>)
FindLastIndex(Predicate<ConditionalFormattingIcon>)
FindLastIndex(int, Predicate<ConditionalFormattingIcon>)
FindLastIndex(int, int, Predicate<ConditionalFormattingIcon>)
GetEnumerator()
IndexOf(ConditionalFormattingIcon)
IndexOf(ConditionalFormattingIcon, int)
IndexOf(ConditionalFormattingIcon, int, int)
LastIndexOf(ConditionalFormattingIcon)
LastIndexOf(ConditionalFormattingIcon, int)
LastIndexOf(ConditionalFormattingIcon, int, int)
RemoveAt(int)

例子


[C#]

//实例化一个工作簿对象
Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

//获取条件格式
ConditionalFormattingCollection cformattings = sheet.ConditionalFormattings;

//添加一个空的条件格式
int index = cformattings.Add();

//获取新添加的条件格式
FormatConditionCollection fcs = cformattings[index];

//设置条件格式范围。
CellArea ca = new CellArea();

ca.StartRow = 0;

ca.EndRow = 0;

ca.StartColumn = 0;

ca.EndColumn = 0;

fcs.AddArea(ca);

ca = new CellArea();

ca.StartRow = 1;

ca.EndRow = 1;

ca.StartColumn = 1;

ca.EndColumn = 1;

fcs.AddArea(ca);

//设置条件
 int idx = fcs.AddCondition(FormatConditionType.IconSet);
 
 FormatCondition cond = fcs[idx];
   
 //设置条件's type
 cond.IconSet.Type = IconSetType.ArrowsGray3;

//添加自定义图标集条件。
 ConditionalFormattingIcon cfIcon = cond.IconSet.CfIcons[0];
 
 cfIcon.Type = IconSetType.Arrows3;
 
 cfIcon.Index = 0;
 
 ConditionalFormattingIcon cfIcon1 = cond.IconSet.CfIcons[1];
 
  cfIcon1.Type = IconSetType.ArrowsGray3;
  
  cfIcon1.Index = 1;
  
  ConditionalFormattingIcon cfIcon2 = cond.IconSet.CfIcons[2];
  
  cfIcon2.Type = IconSetType.Boxes5;
  
  cfIcon2.Index = 2;

//保存Excel文件
workbook.Save("output.xls");

[VB.NET]

'实例化工作簿对象
Dim workbook As Workbook = New Workbook()

Dim sheet As Worksheet = workbook.Worksheets(0)

'获取条件格式
Dim cformattings As ConditionalFormattingCollection = sheet.ConditionalFormattings

'添加一个空的条件格式
Dim index As Integer = cformattings.Add()

'获取新添加的条件格式
Dim fcs As FormatConditionCollection = cformattings(index)

'设置条件格式范围。
Dim ca As New CellArea()

ca.StartRow = 0

ca.EndRow = 0

ca.StartColumn = 0

ca.EndColumn = 0

fcs.AddArea(ca)

ca = New CellArea()

ca.StartRow = 1

ca.EndRow = 1

ca.StartColumn = 1

ca.EndColumn = 1

fcs.AddArea(ca)

//设置条件
Dim idx As Integer =fcs.AddCondition(FormatConditionType.IconSet)

Dim cond As FormatCondition=fcs[idx]

//设置条件's type
cfIcon.Type = IconSetType.ArrowsGray3

'添加自定义图标集条件。
Dim cfIcon As ConditionalFormattingIcon = cond.IconSet.CfIcons[0]

cfIcon.Type = IconSetType.Arrows3

cfIcon.Index=0

Dim cfIcon1 As ConditionalFormattingIcon = cond.IconSet.CfIcons[1]

cfIcon1.Type = IconSetType.ArrowsGray3

cfIcon1.Index=1

Dim cfIcon2 As ConditionalFormattingIcon = cond.IconSet.CfIcons[2]

cfIcon2.Type = IconSetType.Boxes5

cfIcon2.Index=2

'保存 Excel 文件
workbook.Save("output.xls")

也可以看看