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
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
Give a try with the following query
yourDTVar.AsEnumerable().Skip(Math.Max(0, yourDTVar.Rows.Count - 20)).CopyToDataTable()
Regards!
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,
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.