Read “dynamic range” from excel file with a “dynamic name” for the first sheet

I want to read a range from “workbook123.xls” where the “123” changes from report to report.

I have tried so many things and looked around, where I am now is assign activity to the following

Directory.GetFiles(“C:Reports\output”,"workbook") to a system string variable*

I am getting a string conversion error when trying to pass this assigned variable into excel application scope or excel process. In the screen below as noted I assign my actual file, then was hoping to push it into either Process Scope or Application scope and then read the range of a variable I assign using the sheet index

Any suggestions or ideas on how I can make this work? Am I even on the right path. Once I am able to read the entire worksheet of these workbooks I’ll work on reading the specific table within the file, but that’s for later. Thanks so much.

Hi,

How about the following sample?

Sample
Sample20240927-2.zip (15.9 KB)

Regards,

Hi @jwetherin

you can try this, if its one file contain in the folder you can use the below expression if not use loop

Directory.GetFiles("C:Reports\output\","workbook*.xls")(0)

Regards,
Gowtham K

It’s not just workbook.xls.

It is workbook123.xls some times, then workbook 234.xls, etc. etc. I can’t just do a direct path to the file, because the file name is not static.

Gonna pull this and look shortly here. Will report back for sure. Thanks so much Yoichi

Tried to view your use case. I may need to load a package or something in my version

Hi,

As a workaround, can you try to remove project.json then open Main.xaml?

Regards,

Ha, yea that worked. I’ll check this out in a bit.

The only thing is Ill want to read not “sheet1” but rather (0). Since the sheet name always changes name as well (and there is always only 1 sheet). So I am hoping your use case here works, but I create a variable for sheet(0) and then read that.

The image shows the "Read Range" configuration window in an Excel context, with options to include headers and only visible rows, saving the data to a variable named "dt". (Captioned by AI)

Hi,

How about using ForEachExcelSheet and Break activity as the following?

Regards,

Directory.GetFiles returns an array of string, not a string. ANd you have to have a Use Excel File inside Excel Process Scope, then Read Range inside that. Also I don’t think GetSheets returns the correct datatype for the Range property. I use the Get Sheets activity and then use that array to pass the sheet.

Trouble I am finding there is I can’t find the file “workbook123” with a string search. I need to be able to read workbook123, workbook234, workbook*** or whatever the extension is from day to day.

I can easily put workbook123 into the use excel file>Excel file, but that pulls just that one workbook. I need it to be dynamic in pulling an excel file with a key word in it. The files are brand new every day and there is only one file with that “string”, so I won’t need to loop through every file. I can directly utilize the excel file from day to day, i just need to be able to ID the part of the file name so I can use that for specific use cases.

I tried creating a variable of a string for workbook*.xlsx but it comes up with the string error. I tried to do an object and that too failed. Maybe there is some other combination of using a variable for my dynamic file that will actually work.

You need to use Directory.GetFiles with a filter, or For Each File in Folder with a filter, to get the file(s) you want with wildcards.