Reputation: 524
I know this question is very old but i am not finding any answer to this.
How to append values into existing excel file and to a particular column.
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();
I even tried different method like opening Excel through C# and append, nothing worked.
Upvotes: 1
Views: 2200
Reputation: 18443
Using OLEDB to work with excel files has it's problems and shortcomings. It is better to use a third-party library. I recomment CSharpJExcel for Excel 97-2003 (xls) files or EPPlus for Excel 2007 (xlsx) files. You don't need to even have Microsoft Excel installed.
Upvotes: 0
Reputation: 9942
You can checkout below links
http://www.aspsnippets.com/Articles/Export-Data-to-Excel-Sheet-using-ADO.Net-and-C.aspx http://www.aspsnippets.com/Articles/Read-and-Import-Excel-Sheet-using-ADO.Net-and-C.aspx
Upvotes: 2
Reputation: 32459
If you don't have to use OLEDB
here is a good article how to operate excel files by using early binding.
Upvotes: 2