How to get the column names from a DataTable UiPath

While automating business processes we use datatables very often because they can be used as input to bot or output to business user.

Sometimes while automating a business process that uses excel as input.

That uses dynamic column names or we are not sure every time that particular column name will be present or not.

Then we need to know the column names of that input excel.

Basing on that we can design the workflow dynamically by using the present column names from input excel.

Let’s see how we can implement this practically in UiPath:

Step1: Drag and Drop a Read Range Activity which is under workbook activities or we can also use Excel Application Scope and then use a Read Range Activity of excel activities as shown below:

column names from a datatable

The required properties are shown below:

column names from a datatable


  • Range- Provide the range from where to where it has to read. In this case, we are reading the whole range.
  • SheetName-Provide the sheet name which the bot is going to read.
  • WorkbookPath- Provide the input excel file path.
  • AddHeaders- It has to be ticked because we need the column names.
  • Password- If the excel is password protected then provide that here.
  • DataTable- It is the output datatable of input excel.

Step2: Drag and Drop an Assign Activity and create an array of string variable to store the column names by using LINQ expression as shown below:

column names from a datatable


We are getting every column name in that DataTable and storing it in an array of strings.

Step3: Now let’s check the output of column names in the array. Drag and drop a for each to the designer panel as shown below:

column names from a datatable


Provide the array of string variables as input to for each activity as shown above.

Below are the column names from datatable as we used the writeline activity inside the for each:

column names from a datatable

This is how we can get the column names from a datatable using the LINQ expression in UiPath.

Happy Learning!

Like this post then let your friends know about this-:

Leave a Reply

Your email address will not be published. Required fields are marked *