C# 读EXCEL读出不存在表

发布网友 发布时间:2024-10-18 22:12

我来回答

1个回答

热心网友 时间:2024-10-18 22:54

这样看看

string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + dataSource + ";Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);

DataTable dt = new DataTable();
cnnxls.Open();

dt = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

String sheetName = dt.Rows[0]["TABLE_NAME"].ToString();
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from ["+ sheetName +"]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs);

热心网友 时间:2024-10-18 23:02

这样看看

string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + dataSource + ";Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);

DataTable dt = new DataTable();
cnnxls.Open();

dt = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

String sheetName = dt.Rows[0]["TABLE_NAME"].ToString();
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from ["+ sheetName +"]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs);

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com