Saturday, March 28, 2015

How do I write to specific cells in Excel? ... C#, OleDb

How do I write to specific cells in Excel?



This works for writing to cells that have the titles "id" and "name" in the first row.



string stSheetName = "Sheet1";

string sql = "Insert into [" + stSheetName + "$] (id,name) values('5','e')";

myCommand.CommandText = sql;

myCommand.ExecuteNonQuery();



This does not work:



string sql = "Insert into [" + stSheetName + "$A2:B2] SET A2 = '5', B2 = 'e'";



bhs67


No comments:

Post a Comment