How to read rows after specific header of an excel

I need to read an excel file and copy the data to another excel, how do i read only certain rows after a header to output datatable?
The excel is separated by headers like so:

header 1
sub-header1 | sub-header2 | sub-header3|
xxx | xxx | xxx |
header 2
sub-header4 | sub-header5 | sub-header6|
xxx | xxx | xxx |

Also, how do i skip certain columns ( say sub-header2) too before putting it into the second excel?
Thanks for the help in advance, i am very new to uipath and automation

Welcome to uipath community
If we know the row position like A5 or A10 from where the header is mentioned and what we want to fetch, then that can be mention in READ RANGE activity under Range property
But still would like to know how the table looks like and how it’s fetched

Cheers @Zac_Soh

1 Like

The rows position isn’t fixed, it depends on the number of entries the previous header has. I’m trying to fetch only the rows and certain columns under a certain header and ignore the rest of the data.
Right now i am writing the entire sheet to a data table so i can filter from there before writing it to a new excel with only the data i need.
Sorry i couldn’t come up with any image as it contains very sensitive and protected data.

Yah if we are able to do this then it’s fine
Were we facing any issue in that

1.How i do only write the rows and under lets say, header 2 into the data table and ignore header 1?

2.Skipping a few columns as well ( only columns A,B,G,D for example, filtering by the header of the columns instead of the letters as it differs from excel to excel )

If we have now obtained the datatable with those data get the index of that row column value
That is pass the datatable variable to FOR EACH ROW activity and inside that activity use a IF condition like this
If true it goes to THEN part where we can use a assign activity like this
int_index = datatable.Rows.IndexOf(row)
Where int_index is a variable of type int32 defined in the variable panel

—next to this assign activity inside the THEN part of IF use a BREAK activity

Then next to this FOR EACH ROW activity use a assign activity like

datatable = datatable.AsEnumerable().Skip(int_index).CopyToDatatable()

This will obtain the records only after the mentioned index

And to get the required columns alone
use a assign activity like this
datatable = datatable.DefaultView.ToTable(False,”Columnname1”,”columnname2”,…,”columnname n”)

Cheers @Zac_Soh

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