阅读背景:

C#GetOleDbSchemaTable。第一个Excel工作表的名称及其列

来源:互联网 
            try
            {
                string connectionString = string.Empty;

                if (Path.GetExtension(fileName) == ".xlsx")
                {
                    connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName +
                        ";Extended Properties=Excel 12.0;";
                }
                else
                {
                    Debug.Print(connectionString);
                    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.Combine(Server.MapPath("~/Content"), fileName) + ";Extended Properties=Excel 8.0;";
                    //connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path.Combine(Server.MapPath("~/Content"), fileName) + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
                }

                OleDbCommand selectCommand = new OleDbCommand();
                OleDbConnection connection = new OleDbConnection();
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                connection.ConnectionString = connectionString;

                if (connection.State != ConnectionState.Open)
                    connection.Open();

                //connection.Get
                DataTable dtSchema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);


            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }
            try
            {
                s



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: