I’m reading numbers from excel and I want to write again numbers which are even. I’m trying filter them with mod 2 function in if statement but not having success. Instead it writes same numbers again without filtering out the odd numbers. Any help to this?
You are checking with Mod opeartor in your IF statement, but writing whole datatable again into the excel.
Thats the problem, Do you want to write the data into the same excel?
Try this:
evenDT = yourDT.AsEnumerable.Where(function(x) CInt(x("ColumnName").Tostring) Mod 2 =0).CopyToDataTable
And then use Write Range activity and pass that evenDT to write all even numbers into Excel file.
Fine
hope these steps would help you resolve this,
–use a excel applicatiion scope and pass the file path as input
–inside the scope use READ RANGE activity and get the output with a variable of ttype datatable named dt
–now use a assign activiity like thiss
dt = dt.Asenumerable().Where(Function(a) Convert.ToInt32(a.Field(of string)(“yourcolumnname”)) mod 2 =0).CopyToDatatable()
–now use a write range activity and mention the datatable as dt and sheetname as “sheet2” and enable add headers property in the property panel of write range activity
if you are not getting AsEnumerable as a method for datatable then kindly follow these steps
hope this would help you
kindly try this and let know any queries or clarification
Cheers @Darba
I had the exercise exactly correct, but I was wondering why this doesn’t work cause I was getting error from AsEnumerable method. But now it’s working perfectly after I added that assembly reference manually, thanks @Palaniyappan @sarathi125
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.