123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- namespace Biff8Excel.Excel
- {
- public class WorkSheetCollection : CollectionBase, IDisposable
- {
- Dictionary<string, ExcelWorksheet> Dictionary;
- public void Add(ExcelWorksheet worksheet)
- {
- this.Dictionary.Add(worksheet.SheetName, worksheet);
- this.List.Add(worksheet);
- }
- public ExcelWorksheet this[int index]
- {
- // used when referencing an element in the collection
- // vntIndexKey contains either the Index or Key to the collection,
- // this is why it is declared as a Variant
- // Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
- set
- {
- if (index < 1)
- throw new System.ArgumentException(" smaller than ","index");
- //外部索引从1开始,内部从0开始,要得到外部索引的值必须是内部值-1
- this.List[index-1] = value;
- }
- get
- {
- if (index < 1)
- throw new System.ArgumentException( " smaller than ","index");
- //外部索引从1开始,内部从0开始,要得到外部索引的值必须是内部值-1
- return this.List[index - 1] as ExcelWorksheet;
- }
- }
- public ExcelWorksheet this[string key]
- {
- set
- {
- if (this.Dictionary.ContainsKey(key))
- this.Dictionary[key] = value;
- else
- throw new Biff8ExcelException("no this key" + key);
- }
- get
- {
- ExcelWorksheet ew ;
- if ( this.Dictionary.TryGetValue(key, out ew))
- return ew;
- else
- throw new Biff8ExcelException("no this key" + key);
- //return this.Dictionary[key] as ExcelWorksheet;
- }
- }
- public bool Contains(ExcelWorksheet sheet)
- {
- return this.List.Contains(sheet);
- }
- public void CopyTo(ExcelWorksheet[] sheets, int index)
- {
- this.List.CopyTo(sheets, index);
- }
- public new int Count
- {
- // used when retrieving the number of elements in the
- // collection. Syntax: Debug.Print x.Count
- get { return this.Dictionary.Count; }
- }
- public int IndexOf(ExcelWorksheet sheet)
- {
- return this.List.IndexOf(sheet);
- }
- public void Remove(string vntIndexKey)
- {
- // used when removing an element from the collection
- // vntIndexKey contains either the Index or Key, which is why
- // it is declared as a Variant
- // Syntax: x.Remove(xyz)
- this.Dictionary.Remove(vntIndexKey);
- this.List.Remove(vntIndexKey);
- }
- public WorkSheetCollection()
- {
- Dictionary = new Dictionary<string, ExcelWorksheet>();
- }
- #region IDisposable 成员
- public void Dispose()
- {
- Dictionary = null;
- }
- #endregion
- }
- }
|