Click here to Skip to main content
15,038,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying to do something like this in my code to add values of excel cells

xlWorkSheet1.Cells[i, 5] = row[13].ToString() + row1[13].ToString();

But it is just writing the values side by side in one cell

Can anyone suggest me how can I add the values of excel cells using c#


1 solution


You are concatenating two values. if row[13] and row1[13] is numeric value you need to cast before sum each other.

So simple dear.

Best luck :)
Member 10408451 10-Dec-13 9:11am
I tried like this by using casting

xlWorkSheet1.Cells[i, 5] = Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13]);
It is working fine, but giving integer values. But I have floating point values
I am trying like this
xlWorkSheet1.Cells[i, 5] = (float)(row[13]) + (float)(row1[13]);
which is not working
AmitGajjar 12-Dec-13 23:44pm
use Convert.ToDouble

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900