I am doing Lev 1-9 excel part and have some curiosities regarding below. This is about adding the value in column 1 and column 2 and write the result in a column 3.
why cell1 and cell2 are to be converted to String and parsed to be added?
where in the picture, row(2) is written: it just created a variable named row(2) but isn’t that just a name and we need to write somewhere some thing like “Write Cell” to row(2)?
The variables valueA & valueB may be declared as String datatype. In the image row refers the DataRow datatype, as we are reading an item stored in the row (DataRow) using it’s index value [i.e row(0) and row(1)] and trying to store it into a String datatype variable, conversion/type casting is mandatory here. So .ToString is used for type casting.
Let me know what’s there after Integer.Parse(Value in the last Assign activity. So I can help you with my answer for your 2nd query.
Answer for Query 2 - Since we have to add the 2 String DataType variables, they are using Integer.Parse for Type Casting. We can also use like this Convert.ToInt(valueA) + Convert.ToInt(valueB)
Hi @cthamizh,
I tried to create a variable with int32 type and put the extracted value from the datarow but couldn’t. So, maybe that means a datarow emits only string datatype?
no worries
lets go one by one
–usually when we read a data from excel it will read in a datatype of type STRING and inorder to add two values obtained we need to convert them to a INTEGER
so for that we need to parse them to integer.
and for this
no buddy its not just a name or a variable here row is a variable that we obtain from for each row loop and it means each row that is getting iterated for each loop by the for each row loop activity
so here row(2) means column 3 and the current row which is under iteration, where 2 is the column index of third column and usually column index starts from 0 for the first column
So row(2) = integer.parse(valueA) + integer.parse(valueB)
means the sum of these two values will be assigned to the third column of the current row and its cell which is under iteration inside the for each row loop activity
Fine your workflow looks perfect this will
–read the excel and get the output with a datatable variable
–and use add datacolumn to add column atlast named “C”
–then use for each row loop to iterate through each row and assign the sum value to the third column of each row for each iteration
–but make sure that this property of ADD HEADERS is enabled in the write range activity so that it will write back to the excel with the column headers