【发布时间】:2013-01-24 04:02:55
【问题描述】:
我知道这个问题很老了,但我找不到任何答案。
如何将值附加到现有的 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 并追加,但没有任何效果。
【问题讨论】: