I wrote this method (almost similar in other post)
public void update(string fileName, string sheetName)
{
string connString = connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(fileName) + ";Extended Properties='Excel 12.0;HDR=NO'";
try
{
OleDbConnection oledbConn = new OleDbConnection(connString);
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand("UPDATE ["+sheetName+"$B5:B5] SET F1=17", oledbConn);
cmd.ExecuteNonQuery();
oledbConn.Close();
}
catch(Exception ex)
{
Debug.Write("Error: " + ex.Message);
}
}
and calling that method:
update("test.xls", "test");
So far, it works fine because when I open the test.xls file, B5
gets updated to 17
. However, if there is a cell: B1
is dependent on B5
: B1=B5*5
, then B1
will not get updated automatically. I have to manually open the Excel file and save it with warning in order to get B1
updated. How can I do it programmatically?