Update the Excel sheet using c#

Some time I got the requiremnt where I need to update the excel sheet corresponding to testcases through the code whether the test case is failed or passed while automation is running and send the updated testcases excel with current status of testcases through the email at the end of automation code.
i hope that this would be very usefull for you.

Below is the code for that purpose :
//write to excel sheet
public void writeToExcelsheet(int rowNumber, string status)
DbProviderFactory factory = DbProviderFactories.GetFactory(“System.Data.OleDb”);
using (DbConnection connection = factory.CreateConnection())
connection.ConnectionString = Program.excelSheetDeclaration;
using (DbCommand command = connection.CreateCommand())
command.CommandText =
“Update [sheet1$] Set Status =\”” + status + “\” WHERE TestCaseID =”+rowNumber;
catch (Exception ex)
} //end of writeToExcelsheet method.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s