简体   繁体   English

如何写入Excel中的特定单元格?

[英]How do I write to specific cells in Excel?

How do I write to specific cells in Excel? 如何写入Excel中的特定单元格?

This works for writing to cells that have the titles "id" and "name" in the first row. 这适用于写入第一行中标题为“ id”和“ name”的单元格。

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. (OleDbConnection)HDR = YES必须为HDR = NO。 The following does work. 以下工作。

string sql = "UPDATE [" + stSheetName + "$B2:B2] SET F1='e'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM