解决方案 »

  1.   


    http://www.dotblogs.com.tw/rainmaker/archive/2013/07/11/109542.aspx
      

  2.   

    链接内容:
    透过GetOleDbSchemaTable来取到Excel的Sheet Name( Microsoft Jet database engine could not find the object 'sheet1$'. ),这样就不用写死在程式中了,如下,using (OleDbConnection excelConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=@你的ExcelPath@;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"))
    {
    excelConn.Open();
    DataTable excelShema = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    string firstSheetName = excelShema.Rows[0]["TABLE_NAME"].ToString();
    string query = string.Format("Select * from [{0}]", firstSheetName);
    using (OleDbDataAdapter DataAdapter = new OleDbDataAdapter(query, excelConn))
    {
    DataTable excelData = new DataTable("ExcelData");
    DataAdapter.Fill(excelData);
    }
    excelConn.Close();
    }
      

  3.   

    以后读取Excel  还是用NOPI吧