Add numeric data in a column of excel

excel
activities

#1

I used For Each Row to access each row and row() function to get the column element.But row() returns an object and it can only be converted to string.But i need it be an integer to find out their sum.What will i do??


#2

You need to convert it. I recommend reading up on either CInt or preferably the TryParse static method available for various .NET data types


#3

Here is the way. Just change typeArgument from object to string and later you can use
Convert.ToInt32(item) to conver to int.
.


#4

Here’s an example to get your sum:
Assign
sum = sum + Cint(row(0).tostring)

And, you can put that in your For Each Row to calculate the sum throughout the loop.


#5

Thank u for the sugg @ANSI @ddpadil @ClaytonM


#6

@ClaytonM this conversion is invalid says uipath.


#7

@ddpadil i want to use for each row because by using for each every element is accessed.Hence give me a sugg using that. For each cant be used.


#8

hope you resolved conversion part.
I’m not clear with you problem statement.
you wants to use foreach or not?
if yes then above post mentioned inside foreach only


#9

@ddpadil I want to use for each row and not for each as clearly stated in the problem statement


#10

Got it.
Here is the way .Use get row item to get row values and create output variable which is of type generic then you can use Cint to convert to integer and perform the sum operation


#11

You get the conversion error when the string has a character that isn’t a number. So check that out maybe with a message box to make sure you are grabbing the correct item in the row. If the string is blank as in “” then it will get that error, or if it has any other letter in it.

If occasionally that row contains nothing then you might need an if() statement, such as:
Assign sum = if(row(“column”).tostring<>"",sum+cint(row(“column”).tostring),)

Just giving you some ideas.


#12

thank you guys it has worked at last!!!


#13

Hi

I have a data table in that Aging column i have assigned double as it will contain those values.

No i am not able to add values to that Row it gives error saying generic variable not define.
Now after this i have condition that if
row(“Aging”) is greater than 0.35 i need to copy only that row to current data table.

Please help @ClaytonM @ddpadil


#14

Hi @1vivek12

I’m just answering this quick, but you can probably filter the table that meets your criteria then use the new datatable in Append Range activity or datarow array in Add Data Row activity

// method 1
Append Range: => datatable parameter: dt2.AsEnumerable.Where(Function(r) CDbl(r("Aging").ToString.Trim) > .35 ).CopyToDataTable

// method 2
For each row In dt2.AsEnumerable.Where(Function(r) CDbl(r("Aging").ToString.Trim) > .35 ).ToArray
    Add data row: => datarow parameter: row, datatable parameter: dt1

Regards.


#15

Sorry, I answered your second part but skipped the first one. I am not sure what you mean on that error without seeing a screenshot of the error or activity. Thanks.


#16

I meant Aging Column in build data activity i have assigned to double but now with add data row activity i am not able to populate the table with required value


#17

Hi,

I will; explain
I use build data activity and created a column aging with variable type double
then from excel sheet i populate excel value to this table but add row activity in for each loop dint work.

then i conver aging to string then it worked.

Now i have to filter according to this condition aging > 0.35 copy those rows.

Please help.


#18

Currently in data Table Aging is a string as add data row was not working with double

getting this error when i used one of ur method


#19

Sorry, you need to add an If in my method:

dt2.AsEnumerable.Where(Function(r) If( IsNumeric(r("Aging").ToString.Trim), CDbl(r("Aging").ToString.Trim) > .35, False) ).CopyToDataTable

So it only checks if value is > .35 if it is a number, otherwise you will get that error.


#20

what variable type should be the column Aging string or dowble?