C#excel 문서 업로드

1982 단어 Excel
if (fileExt.ToUpper() == ".XLS" || fileExt.ToUpper() == ".XLSX" || fileExt.ToUpper() == ".XLSM" || fileExt.ToUpper() == ".XLSB")

                {

                    int Sp_Count = orFilePath.Split(Convert.ToChar("\\")).Length;

                    //string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=No;IMEX=1';" + "data source=" + filePath;

                    string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0; HDR=NO; IMEX=1\"";

                    OleDbConnection Conn = new OleDbConnection(connStr);

                    Conn.Open();

                    // excel Sheet1  ( )

                    //string SheetName = "[Sheet1$]";

                    //DataSet ds = new DataSet();

                    //OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("SELECT * FROM {0}", SheetName), Conn);

                    //odda.Fill(ds, SheetName);

                    //Conn.Close();



                   // 

                   // Excel , sheet , ,  

                    DataTable dtSheetName = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });

                    // excel 

                    string[] strTableNames = new string[dtSheetName.Rows.Count];

                    for (int k = 0; k < dtSheetName.Rows.Count; k++)

                    {

                        strTableNames[k] = dtSheetName.Rows[k]["TABLE_NAME"].ToString();

                    }

                    DataSet ds = new DataSet();

                    OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", strTableNames[0]), Conn);

                    odda.Fill(ds, strTableNames[0]);

                    Conn.Close();



                }

좋은 웹페이지 즐겨찾기