读取excel文件给出错误"无法更新只读文件"

时间:2015-04-16 14:48:53

标签: c# .net excel oledb

我正在尝试阅读excel文件,但它给出了错误

Cannot update.  Database or object is read-only.

我的代码正在关注

var fileName = string.Format("{0}\\aa.xlsx.", Directory.GetCurrentDirectory());
    var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);

    var adapter = new OleDbDataAdapter("SELECT * FROM [shell$]", connectionString);
    var ds = new DataSet();

    adapter.Fill(ds, "shell$");

    DataTable data = ds.Tables["shell$"];

我从未使用过excel文件而且不确定这个错误是什么。它说"无法更新,因为只准备好"但我没有更新。我想要的只是在c#

中读取文件

更新:我不知道什么是shell $。我刚从其他来源(代码)

获得它

1 个答案:

答案 0 :(得分:0)

我认为您需要将shell$'替换为您要从中选择的Excel文件中的工作表名称。如果仍然存在只读问题,请告诉我。

相关问题