C# EXCEL 파일을 가져올 때 전체 작업 내역

1297 단어
      var strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=\'Excel 8.0;HDR=YES;IMEX=1\'", FullPath);
                        System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
                        using (var oledbConn = new System.Data.OleDb.OleDbConnection(strConn))
                        {
                            oledbConn.Open();
                            var sheetName = oledbConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new[] { null, null, null, "Table" });
                            var sheet = new string[sheetName.Rows.Count];
                            for (int i = 0, j = sheetName.Rows.Count; i < j; i++)
                            {
                                sheet[i] = sheetName.Rows[i]["TABLE_NAME"].ToString();
                            }
		 var adapter = new System.Data.OleDb.OleDbDataAdapter(string.Format("select * from [{0}]", sheet[0]), oledbConn);
                            adapter.Fill(ImportDS, "ImportData");
                            oledbConn.Close();
                         }

좋은 웹페이지 즐겨찾기