当前位置:软件学习 > Excel >>

c# 导出excell 改变标题颜色

1.引入类库C1.C1Excel.2.dll
 2.建立2个实体类,只要拷贝就可以。
 A。XlsMapEntry 数据库表字段与excell 标题对应类
   代码如下:
   View Code
  [Serializable]
     public struct XlsMapEntry
     {
         private string excelColumn;
         private string tableColumn;
 
        public string ExcelColumn
         {
             get { return this.excelColumn; }
             set { this.excelColumn = value; }
         }
 
        public string TableColumn
         {
             get { return this.tableColumn; }
             set { this.tableColumn = value; }
         }
 
        public XlsMapEntry(string excelColumn, string tableColumn)
         {
             this.excelColumn = excelColumn;
             this.tableColumn = tableColumn;
         }
     }
 
 B.建立一个集合类,用于放这些实体
 代码如下:
   View Code
  public class XlsMapDictionary : IEnumerable
     {
         private List<XlsMapEntry> items;
         private Int32 ItemsInUse = 0;
 
        public XlsMapDictionary()
         {
             items = new List<XlsMapEntry>();
         }
 
        public bool IsReadOnly { get { return false; } }
         public bool Contains(string tableColumn)
         {
             Int32 index;
             return TryGetIndexOfKey(tableColumn, out index);
         }
         public bool IsFixedSize { get { return false; } }
         public void Remove(string tableColumn)
         {
             if (tableColumn.Equals(string.Empty)) throw new ArgumentNullException("control");
             Int32 index;
             if (TryGetIndexOfKey(tableColumn, out index))
             {
                 items.RemoveAt(index);
                 ItemsInUse--;
             }
             else
             {
 
            }
         }
         public void Clear()
         {
             items.Clear();
             ItemsInUse = 0;
         }
         public void Add(string excelColumn, string tableColumn)
         {
             items.Add(new XlsMapEntry(excelColumn, tableColumn));
             ItemsInUse++;
         }
         public ICollection ExcelColumns
         {
             get
             {
                 Object[] excelColumns = new Object[ItemsInUse];
                 for (Int32 n = 0; n < ItemsInUse; n++)
                     excelColumns[n] = items[n].ExcelColumn;
                 return excelColumns;
             }
         }
         public ICollection TableColumns
         {
             get
             {
                 Object[] tableColumns = new Object[ItemsInUse];
                 for (Int32 n = 0; n < ItemsInUse; n++)
                     tableColumns[n] = items[n].TableColumn;
                 return tableColumns;
             }
         }
         public object this[int index]
         {
             get
             {
                 return items[index];
             }
 
            set
             {
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,