Creating DataTable at runtime to extract excel data

I want to extract the data from each sheet in a different data table. However, it is unknown that how many workbook sheets are available in a workbook… it can be 2,10… or more…
I can get the name of worksheets using WorkbookName.GetSheets or the count. But I am not sure how should I dynamically add/create the number of datatables in UiPath.

Is there any leads?


You can use a generic collection type. Use List<DataTable>
And then keep adding data to the List.
Create a variable DataTable and then initialise to a new DataTable object in the loop.
Extract the sheet data to a data table and then add to a List.
You can use index to access the data table corresponding to each sheet.

dataTableofSheet1 = List(0)

Karthik Byggari


Hi @Ayush_Purohit_IN

Is the columns are unique or dynamic

U need to iterate based on directory.get files(“folder path”)
Use for each item in filename

Use read range of sheets and use merge datatable
Write range activity

Can you share an example xaml?


1 Like

The name of the columns doesn’t really matter here. It can be unique or dynamic.
I guess, you’ve misinterpreted the question?
There is only one excel file, in which there are multiple sheets. I want to extract these sheets in different datatable, not merge them.


I can share the sample xaml by eod.
Currently no access to studio.

No worries
here you go
hope its resolved (16.9 KB)

Cheers @Ayush_Purohit_IN


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