话不多说直接来干货。。。。
连接类 Excel 通过 OleDb 类进行操作。
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Data.OleDb; 6 7 /// <summary> 8 /// ExcelHelper 的摘要说明 9 /// </summary> 10 public class ExcelHelper 11 { 12 private OleDbConnection conn; 13 private string connStr = "Provider=Microsoft.Ace.OleDb.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=yes'"; 14 public ExcelHelper(string fileName) 15 { 16 connStr = string.Format(connStr, fileName);//操作的文件路径早调用对象时给定 17 Conn = new OleDbConnection(connStr); 18 } 19 20 public OleDbConnection Conn 21 { 22 get 23 { 24 return conn; 25 } 26 27 set 28 { 29 conn = value; 30 } 31 } 32 }