我正在将保存在服务器文件夹中的模板 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();
Replace:
string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=xxx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");
with
string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES""", newFileName);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)