1. 程式人生 > >C# 獲取excel操作

C# 獲取excel操作

OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileDlg.FileName + ";" + "Extended Properties=Excel 8.0;");
                objConn.Open();
                DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);


                comboBox_.Items.Clear();//設定工作表名
                for (int i = 0; i < schemaTable.Rows.Count; i++)
                {
                    comboBox_.Items.Add(schemaTable.Rows[i][2].ToString());
                }
                if (comboBox_.Items.Count>0)
                {
                    comboBox_.SelectedIndex = 0;
                }