我知道这个问题已经很老了,但我没有找到任何答案。
如何将值附加到现有的 excel 文件和特定列中。
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=filelocation;Extended Properties=Excel 8.0;");
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = "Insert into ["+ sheetname +"$] (Result) values ("+ result +")";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
我什至尝试了不同的方法,例如通过 C# 打开 Excel 并追加,但没有任何效果。