UIPath selecting first excel document in a file

Hello my dear robot masters :smiley:
I’m working on a project where i need to select different excel documents in a file.
For example i have a file that contains 60 excel document.
The robot has to choose all the files in order one by one every time in a loop.
Which activity should i use to tell the robot to choose.
I was thinking to tell the robot to choose the first excel and after reading the data it can delete the excel.
So in the next action of loop the first file will be changed and it’s going to choose the next one.

Please let me know if my question is not clear.

Looking for any kind of answer.

Cheers.

1 Like

Hi @mtalhabalci
–hope these steps could help you resolve this
–use a assign activity and mention like this
out_filepath = Directory.GetFiles(“yourfilepath”,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).ToList(0)
this will give the latest file
where out_filepath is a variable oftype string
–then we can use this variable as file path while using excel application scope
–once done use delete file activity and pass the same file path variable as input so that it will delete the same

OR

to get them in order
mention a assign activity like this
out_filepath = Directory.GetFiles(“yourfilepath”,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime)

where out_filepath is a variable of type array of strings
–now pass this array in for each activity and change the type argument as string
–inside the loop use excel application scope and mention the file path as variable item as it holds the file path in order of the creation time

hope this would help you
Cheers @mtalhabalci

1 Like

dear palaniyappan im thankful for your kindly answer.

It worked for my issue but the order was not a real order.

Somehow it is choosing the files randomly but the order was not really so important for me.

Let me ask my next question.

In my excel files, there are different sheets. how can i choose the sheet i want?

for example i’m going to get the data of a sheet with name of “mysheet2”?

Or should i get with a path as well?

Bth i’m always going to choose the first sheet but names are different.

Looking forward.

Kindly regards. Cheers

You can add an dynamic argument instead of a static sheet name with read range activity, obviously, you could add try catch and manipulate in different ways this, but just to illustrate

Hello again,

I think here is a missunderstanding.

I’m telling that i dont know names of the sheets since there are more than 200 of them.

I just know i have to choose the first sheet every time.

Do i have to look at their names each time and change in the read range activity, or is there a better way to say it?

For example;
for my first excel file i’have 10 sheets and i need to choose first of them without knowing the sheet’s name.
Thank you…

You can use outputDataTable.GetSheets to get the sheet

1 Like

hello again,
ive read the required data from excel.
but i robot cant delete the file since it’s opened.
how can i close these excel documents dynamically in order to delete them after every loop?
see you

hello people,
i couldnt get any response from anyone…
im not sure if my question is understood clearly…
please let me know if it is not clear so i can express better…

You want to delete whole XLSX file after reading data from it?