简体   繁体   English

使用oledb更新Excel文件的特定单元格

[英]Update specific cell of excel file using oledb

I want to update the specific cell of the excel file using oledb. 我想使用oledb更新excel文件的特定单元格。 Say I7 cell, for some reason always I1 is getting updated. 说I7单元,由于某种原因总是I1正在更新。 Can anyone tell me what's wrong with this code? 谁能告诉我这段代码有什么问题吗?

OleDbConnection oledbConn = new OleDbConnection(connString);
oledbConn.Open();

// I want to set the value of I7 cell to 22, for some reason value is I1 is getting updated :(
OleDbCommand cmd = new OleDbCommand("UPDATE [" + sheetName + "$I7:I7] SET F1=22", oledbConn);
int result = cmd.ExecuteNonQuery();
Console.WriteLine(result);
oledbConn.Close();

This may purely be an issue with the cell address scheme you're using. 这可能纯粹是您正在使用的单元地址方案的问题。 Try $I$7:$I$7 intsead. 尝试$I$7:$I$7 intsead。 Also, what is that F1 thing in the query? 另外,查询中的F1是什么?

I ran the same program on excel 2007, it worked smoothly. 我在excel 2007上运行了相同的程序,运行顺利。 For excel 2013 it does not work. 对于excel 2013,它不起作用。 Seems like a bug in excel 2013. 似乎是Excel 2013中的错误。

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

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