因此,在excel中,您可以使用由公式确定的列表来创建数据验证规则。有谁知道如何使用C#和ClosedXML做到这一点?
您可以使用ICollection
或IList
实现自己的集合,并实现添加和删除操作的规则。
public class myList : IList
{
private List<string> _list;
public myList()
{
_list = new List<string>();
}
public object this[int index] { get => _list[index]; set => throw new NotImplementedException(); }
public bool IsFixedSize => throw new NotImplementedException();
public bool IsReadOnly => throw new NotImplementedException();
public int Count => throw new NotImplementedException();
public bool IsSynchronized => throw new NotImplementedException();
public object SyncRoot => throw new NotImplementedException();
public int Add(object value)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(object value)
{
throw new NotImplementedException();
}
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
public int IndexOf(object value)
{
throw new NotImplementedException();
}
public void Insert(int index, object value)
{
throw new NotImplementedException();
}
public void Remove(object value)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
}
对于某些不需要任何更改的操作,请在_list
中使用相同的操作来实现它们,例如索引设置器。