Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 16, 2012 04:15 AM by santosh.jagdale
Member
1 Points
10 Posts
Aug 15, 2012 06:44 PM|LINK
Hey! I need to be able to update multipul specific rows in my excel file. Is there anyway to do this in a C# asp.net?
Here's what I have:
protected void Button2_Click(object sender, EventArgs e) { using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\AIRSIGNDMC\wwwroot\Contract.xlsx;Extended Properties=Excel 12.0 Xml;HDR=NO"; string sql = string.Format("UPDATE [Sheet1$A2:A2] SET F1=123456 VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", TextBox1.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text); using (OleDbCommand cmd = new OleDbCommand(sql, conn)) { try { conn.Open(); cmd.ExecuteNonQuery(); } finally { conn.Close(); } conn.Close();
as you can see, I need to take the values from texbox1,2... and insert them into specific rows in excel.
Thank you!
Star
7625 Points
1454 Posts
Aug 16, 2012 04:15 AM|LINK
if yopu know row number then you can use following
sheet.Cells[row, col] = value;
more excel help http://www.codeproject.com/Articles/22935/A-Very-Easy-to-Use-Excel-XML-Import-Export-Library
l3elivE
Member
1 Points
10 Posts
How to update specific rows in excel
Aug 15, 2012 06:44 PM|LINK
Hey! I need to be able to update multipul specific rows in my excel file. Is there anyway to do this in a C# asp.net?
Here's what I have:
protected void Button2_Click(object sender, EventArgs e) { using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\AIRSIGNDMC\wwwroot\Contract.xlsx;Extended Properties=Excel 12.0 Xml;HDR=NO"; string sql = string.Format("UPDATE [Sheet1$A2:A2] SET F1=123456 VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", TextBox1.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text); using (OleDbCommand cmd = new OleDbCommand(sql, conn)) { try { conn.Open(); cmd.ExecuteNonQuery(); } finally { conn.Close(); } conn.Close();as you can see, I need to take the values from texbox1,2... and insert them into specific rows in excel.
Thank you!
santosh.jagd...
Star
7625 Points
1454 Posts
Re: How to update specific rows in excel
Aug 16, 2012 04:15 AM|LINK
if yopu know row number then you can use following
more excel help http://www.codeproject.com/Articles/22935/A-Very-Easy-to-Use-Excel-XML-Import-Export-Library
MCP