Use skip() and Take() method in linq

Hi Guys
I need you help to understand in which scenario we can use skip() and Take() method togather
like below query use to split excel into chunks
ExampleExcel.zip (235.0 KB)
Split_Excel_Files.xaml (18.1 KB)

dt_Input.AsEnumerable.Skip(int_Boundry_Start_Row-1).Take(int_Split_Row_Count).CopyToDataTable

Have a look here:

And have some practicals here:

Can anyone help me on this topic

HI,

How about the following?

Enumerable.Range(0,(dt.Rows.Count \ chunkSize)+1).Select(Function(i) dt.AsEnumerable.Skip(i*chunkSize).Take(ChunkSize).CopyToDataTable).ToArray

Sample20221108-4.zip (132.8 KB)

Regards,

2 Likes

Hi @Yoichi, Thank you for above solution.
I have a similar requirement where a large data table has 3000 records which would be spilt in 3 files with 900 records/file and remaining 300 would go in a separate file.
3000 is just a number, it can be 5000 but records per file is fixed; 900 so remaining will go in a new file.
Any suggestions.

we suggest to open a new topic on your case and get individually help

Preview:
Assign Activity:
TableList | DataType: List(of DataTable) =

dtDataVar.AsEnumerable.Chunk(SegmentSizeAsIntVar).Select(Function (x) x.CopyToDataTable).ToList

UPD1 - added preview on calculation of Fixed, Remaining rest Skip Take calculations:

1 Like

Thank you @ppr, this should work

Hey @ppr, chunk function is showing up. As you suggested, I created a variable of type list of datatable (List).
@Yoichi any idea?

Do you have any problem? We can iterate the list using ForEach, then Save each item into xlsx file using WriteRange activity etc.

Regards,

The problem is chunk function in below query in not showing in my studio.
dtDataVar.AsEnumerable.Chunk(SegmentSizeAsIntVar).Select(Function (x) x.CopyToDataTable).ToList

can we have a query something using range function?

Hi,

Is your project Windows-Legacy? If so, Chunk cannot be used.

Regards,

Yes, it is window-legacy.

Is there any alternate function of chunk in legacy projects ?

Hi,

Doesn’t this post work for you?

Regards,

It does, thank you for the quick response

yes, that is

why we have shared with you the approach of calculating Skip, Take Blocks

However, for any further question just open a new topic and get individually help on your case as already mentioned