博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Excel的OleDb处理

Posted on 2010-12-07 15:00  Adam哥  阅读(228)  评论(0编辑  收藏  举报

一、获取所有sheet

 

 try
            {
                string strFileName = "d:\\Book1.xls";
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +  "Data Source=" + strFileName + ";" +   "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                DataTable schemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
                foreach (DataRow row in schemaTable.Rows)
                {
                    for (int i = 0; i < schemaTable.Columns.Count; i++)   {
                        Response.Write(row[i].ToString() + "    ");
                    }
                    Response.Write("<br/>");
                }
                conn.Close();
            }
            catch (Exception ex)
            { 
            }



counter