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'";
I found the problem. The (OleDbConnection) HDR=YES must be HDR=NO. The following does work.
string sql = "UPDATE [" + stSheetName + "$B2:B2] SET F1='e'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.