我新的C#和我想讀一個Excel用下面的代碼閱讀Excel文件C#
string conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFilePath +
";Extended Properties=Excel 12.0;";
using (OleDbConnection connection = new OleDbConnection(conStr))
{
connection.Open();
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
using (OleDbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
var row1Col0 = dr[0];
Console.WriteLine(row1Col0);
}
}
}
我收到以下錯誤文件:
Sheet1$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
誰能告訴我我做錯了什麼?
Excel工作表的名稱是sheet.xlsx
這是該文件的名稱。文件中標籤上的名稱是什麼? IIRC這是牀單。 – CaffGeek
我附上excel表格的圖片 – wearybands
表格底部的標籤名稱是什麼。 – CaffGeek