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.
https://docs.microsoft.com/ja-jp/dotnet/visual-basic/language-reference/functions/type-conversion-functions

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.:slight_smile:

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. image
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