Excel Read Range - last twenty rows only?

Hello Community,

Is it possible to set the range in the Excel read range to the last 20 rows only? The input data sheet rows are dynamic and they will change number often,
Thank you

Try this:

Step 1:
Read the excel file - reading all rows. Let the output datatable be called “dt”

Step 2:
Insert assign activity,
Assign Left:
dt
Assign Right:
dt.AsEnumerable().Skip(dt.Rows.Count-20).CopyToDataTable()

Note: You may want to always check the row count is greater than 20.

Cheers

Steve

1 Like

Hi @Orchestrator_Practice

Give a try with the following query

yourDTVar.AsEnumerable().Skip(Math.Max(0, yourDTVar.Rows.Count - 20)).CopyToDataTable()

Regards!

1 Like

Hi,

FYI, If the project is not Windows-Legacy, we can use TakeLast method.

dt = dt.AsEnumerable.TakeLast(20).CopyToDataTable()

Or if there is possibility number of rows is less than 20, it may be better to use datarow array as the following.(Because CopyToDataTable throws exception if there is no row)

arrDr = dt.AsEnumerable.TakeLast(20).ToArray

Regards,

1 Like

Thank you for your post and providing two alternatives

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