【问题标题】:The Microsoft Access database engine could not find the object 'Sheet1$Microsoft Access 数据库引擎找不到对象“Sheet1$”
【发布时间】:2014-02-13 14:17:54
【问题描述】:

我正在将保存在服务器文件夹中的模板 excel 文件复制到具有不同名称的同一文件夹中。插入值..我可以复制文件,但是当我尝试插入值时它显示工作表!$ 找不到。我给出了正确的工作表名称。在名为 sheet1 的电子表格中只添加了一张工作表。仍然显示错误。我的代码在下面给出。不知道这个错误。我用谷歌搜索但要求我检查文件夹和工作表名称..它只是正确的..请帮助我

        string xxx = "~/temp/" + "Tempfile" + dunsno + DateTime.Today.ToString("dd.MM.yyyy") + ".xlsx";
         DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath("~/temp/"));
                            var fileList = directoryInfo.GetFiles();
                            string newFileName = Server.MapPath("~/temp/" + "Tempfile" + dunsno + DateTime.Today.ToString("dd.MM.yyyy") + ".xlsx");
                            foreach (FileInfo fleInfo in fileList     

                       {
                                fleInfo.CopyTo(newFileName, true);
                       }
         string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=xxx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");
         OleDbConnection MyConnection;
                            OleDbCommand MyCommand = new OleDbCommand();
                            MyConnection = new OleDbConnection(@connStr);

                            MyConnection.Open();
                            MyCommand.Connection = MyConnection;
                            string sql = "Insert into [Sheet1$] (id,name) values('3','c')";
                            MyCommand.CommandText = sql;
                            MyCommand.ExecuteNonQuery();
                            MyConnection.Close();

【问题讨论】:

  • 你在混合使用 Excel 和 Access 吗?
  • 不,我只使用 excel-2010 插入值

标签: c# asp.net ms-access-2007


【解决方案1】:

替换:

string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=xxx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");

string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES""", newFileName);

【讨论】:

  • 非常感谢。这有助于解决我的问题。代码运行良好近 3 年,bu 突然 .xlsx 开始失败(但 .xls 中的相同数据正常工作)。
【解决方案2】:

如果您仍然收到如下错误“Microsoft Access 数据库引擎找不到对象...”,然后是您尝试从中读取数据的工作表名称,请尝试 [sheetname$]。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多