Hello,
I have two.excel.files in a folder and I need to read those Excel and add the data into different data tables how can I achieve this.
Excel file1 data should be added to dt1
Excel file2 data should be added to dt2
So on
Hi,
If it is just for 2 files or for a specific number of files you already know, you can build a logic to do that, like reading all the files in the folder and generating the datatables.
But if this folder can contain any number of files, then I don’t think it is possible to do that, because you cannot create variables during runtime. I mean, you would to use a “for each files in folder” to loop all the files, but then when reading each file you would need to assign to an existing datatable already there in the code, it is not possible to create new variables during the execution since UiPath uses compiled approach.
assign:
folder_path=“give the folder path”
files=directory.getfiles(folder_path) <file_path data type array of string>
Build datable with required columns <output-dt_Build>
>for each file_path
read range workbook activity
input-currentfile
output -dt_excel
assign:
dt_build=dt_excel.asenumerable.select(function(x)dt_build.rows.add(x("Columnname1").tostring,x("ColumnName2").tostring,).copytodatatable
write range workbook activity
input-dt_build
Cheers!!
In Main use :
- Excel Application Scope (file1.xlsx)
- Read Range (Sheet1)
- Output: dt1
- Excel Application Scope (file2.xlsx)
- Read Range (Sheet1)
- Output: dt2
Now you havedt1
anddt2
containing data from file1.xlsx and file2.xlsx, respectively.
You can perform additional processing or analysis on these DataTables as needed.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.