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
I think below logic will work.
- Read range
- Loop @ data table of 1
- 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.
- End loop
- Write 2nd data table to Excel which youāve get data.
Thatās yet.
J,
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.
@Jumbo
I tried it, but there was an error. I donāt know how?
Below is an error:
@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?
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.
@Lam_Ha
Here is sample
sample_ham 2.xaml (8.1 KB)
thanks @lakshman
Iām trying it
@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
Read range in DT
DT = DT.select(convert.int32(ācolumnnameā) %2 <>0).copytodatatable
And write range
Regards,
Aditya
@Lam_Ha Check attached zip file ExcelRemoveOdd.zip (17.0 KB)
Hi @rahatadi
can you give me an example?
thanks
Thanks for the attension.
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
Hi @rahatadi
I did this.
but i donāt know how to add new datatable. can you give me advice?
Thanks
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
@rahatadi
Thank you for your assistance
@indra
Thanks