我将保存在服务器文件夹中的模板excel文件复制到具有不同名称的同一文件夹中。插入值..我能够复制文件,但是当我尝试插入值显示表!$找不到。我给了正确的工作表名称..只有一张表被添加在名为sheet1.still的电子表格中,它显示错误。我的代码如下。请关于此错误的想法。我GOOGLE了,但要求我检查文件夹和工作表名称..它是正确的only..please帮我
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();
+0
你是混合Excel和Access? –
+0
不,我只使用excel-2010插入值 –