string str1 ="123";
string str2 ="456";
string str3 ="789";
string mypath= Environment.CurrentDirectory + @"\123.xlsx";
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ mypath + ";Extended Properties='Excel 12.0;HDR=no;'";
using (OleDbConnection OleConn = new OleDbConnection(strConn))
OleConn.Open();
try
{
using (OleDbCommand oleCommand = new OleDbCommand("update [Sheet1$B1:B1] set f1='" + str1 + "'", OleConn))
{
oleCommand.ExecuteNonQuery();
}
using (OleDbCommand oleCommand = new OleDbCommand("update [Sheet1$C2:C2] set f1='" + str3 + "'", OleConn))
{
oleCommand.ExecuteNonQuery();
}
using (OleDbCommand oleCommand = new OleDbCommand("update [Sheet1$D3:D3] set f1='" + str2 + "'", OleConn))
{
oleCommand.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}