Remove odd numbers from the excel

Hi all,
I have an excel file as follows:
7
3
6
4
10
5
2
8
1
9
9
how to remove all the odd numbers?
How can I do this? Someone please help to achieve this.
Thanks

@Lam_Ha

I think below logic will work.

  1. Read range
  2. Loop @ data table of 1
  3. Mod data row with 2, and it is even value if it is not 0. So if calculation result is 0, then add the value to the data table, else add blank value to data table.
  4. End loop
  5. Write 2nd data table to Excel which youā€™ve get data.

Thatā€™s yet.
J,

@Lam_Ha

First read entire data using Read Range Activity and will give output as dataTable and say ā€˜DTā€™.

Try this:

                **evenDT = DT.AsEnumerable().Where(Function (r)Cint(r("ColumnName").ToString) Mod 2 = 0).CopyToDataTable**

Then use Write Range Activity to write into Excel file and pass evenDT to it.

2 Likes

@Jumbo
I tried it, but there was an error. I donā€™t know how?
Below is an error:image

@Lam_Ha
ah, might be you didnā€™t cast the value string to int32. please refer below vb expression and try it.

Rgds,
J,

@Jumbo
Sorry, I uploaded the wrong error. Can you give me a solution for the following error?Sorry, I uploaded the wrong error. Can you give me a solution for the following error?
image

@Lam_Ha

Have you tried my query or not ?

If there is no ColumnName in the Excel file then replace r(ā€œColumnNameā€).Tostring with r.item(0).Tostring in the above expression.

2 Likes

@Lam_Ha
Here is sample
sample_ham 2.xaml (8.1 KB)

1 Like

thanks @lakshman
Iā€™m trying it

1 Like

@Jumbo
I did the same. but the problem is that i canā€™t add divisible cases to 2 to the data table. can you help me that part
thanks

@Lam_Ha

Read range in DT

DT = DT.select(convert.int32(ā€œcolumnnameā€) %2 <>0).copytodatatable

And write range

Regards,
Aditya

1 Like

@Lam_Ha Check attached zip file ExcelRemoveOdd.zip (17.0 KB)

1 Like

Hi @rahatadi
can you give me an example?
thanks

@Lam_Ha

Thanks for the attension.:relaxed:

You can use select method for filtering and as it is string you have to convert it into int32.

Converting int32 is the catch for this.

Will provide you an example soon as i dont have my pc with me right now.

Thanks
Aditya

1 Like

Hi @rahatadi
I did this.


but i donā€™t know how to add new datatable. can you give me advice?
Thanks

@Lam_Ha

Greatā€¦it is another beat way to do it.

Just add build datatable activity (define your output column here)-dtout

And inside if then part
Add datarow
Dtout and in data array {in32mod} as input.

Hope this will solve our problem. If not let me know the issues.

Regards
Aditya

1 Like

@rahatadi
Thank you for your assistance :slightly_smiling_face:

1 Like

@indra
Thanks :blush:

1 Like