Dividing my datatable into 20 rows

Hi UiPath,

I need help with my problem.

I am using a web application that can accept only maximum of 20 rows per transaction.

however my data table contains dynamic number of Rows count.

so I need to loop until all the row data was added in the cart.

is there simple solution with my situation?

Please let me know

thanks!

Assign NoOfSegments=total no of rows/20
loop through each of the segment in Enumerable.Range(0,NoOfSegments).ToList

Assign row(list of datarow)=inputDatatable.AsEnumerable.Skip(segment*20).Take(20).toList

//This will take 1st 20 in the first loop, next 20 in the 2nd loop and so on

Hi,

Hope the following sample helps you

arrDt = Enumerable.Range(0,dt.Rows.Count\num -CInt(dt.Rows.Count mod num>0)).Select(Function(i) dt.AsEnumerable.Skip(i*num).Take(num).CopyToDataTable).ToArray

note: arrDt is DataTable[] type

Sequence.xaml (11.5 KB)

Regards,

@Yoichi thanks for your response your code is very helpful to me.

however I forgot to mention that my data table doesn’t contain a header.

thus your code is not catching the last row in the data table.

can you help me with it?

thanks!

Hi,

The above expression will divide all the rows to chunk of 20 rows or remaining regardless of whether header exists or not.
Can you elaborate your issue in detail and/or share your sample data?

Regards,

Hi @Yoichi,

Yeah my sample data is this :slight_smile:
Test.xlsx (8.9 KB)

there is a total of 27 rows item in this data table

thanks!

Hi,

It seems works well… Can you check the following sample?

Sample20220816-2.zip (9.2 KB)

Regards,

Hi @Yoichi , I think I got it now I accidentally tick the add header property in the read range activity :slight_smile:

It worked now thank you very much!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.