using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.OleDb; namespace Stone.Common { public class MyExcelDatabase : MyOleDbDatabase { public static void OpenDatabase(string DbPath, bool IsHead) { string HDR = ""; if (IsHead) { HDR = "HDR=YES;"; } else { HDR = "HDR=NO;"; } if (DbPath.ToLower().Substring(DbPath.Length - 3) == "xls") //excel 2003格式 { m_oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DbPath + ";Extended Properties='Excel 8.0;" + HDR + "'"); } else //excel 2007 格式 { m_oleconn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DbPath + ";Extended Properties='Excel 12.0 Xml;" + HDR + "'"); } m_oleconn.Open(); m_olecmd = m_oleconn.CreateCommand(); } } }