Get text from each column in DataTable

Hi all,

I am trying to get the text from these the headers of a datatable and click the button depending on if the text contains Thu for example.

How do i loop through and get the text for example ‘Thu’, ‘Fri’ from this datatable.

When i run my for each loop i just get ‘Column-1’, ‘Column-2’ etc.

Here is an example of my sequence.

image

1 Like

use the for each with your datatable and in your case to get the output you would use

col(“Column-0”).tostring or whichever col you are using to get the value.

e.g. if my data table was called DT_Col and i was using for each col, i would write in an assign or message box

Col(“Column-0”). to string OR VAR_COL = Col(“Column-0”).tostring

1 Like

Hi aquinn,

Thanks for the responce. Still getting this error though.

1 Like


please follow this screenshot, use a for each row in data table

1 Like

Hi aquinn,

Again thanks for the help but i need to get the text from the columns.

I need to be getting 18/11, 19/11 etc.

So instead of iterating from top to bottom i need to be going from left to right.

See screenshots attached.

image

1 Like

Hey @Alexander_Ward

You are getting datatable as a output from Extract Table Data, So use the same variable and loop it through the regular for loop.
<Your_DataTableVariable>.Columns ( Place this in the condition of the for loop)

You will be getting column headers in each iteration, further you can put your conditions.

Regards.

1 Like

Instead of using col(“column-0”).tostring you can use column(1).tostring for the next column along which would be the date, then (2) for the 3rd column etc

1 Like

Hi @Alexander_Ward check this screenshot

image

It will return the columns

1 Like

the foreach typeargument is to set to DataColumn
when retrieving the columnname is needed we use
col.ColumnName

1 Like

I would have to do a multiple assign with that wouldn’t i?

Because there is no way increment that column-1, 2, 3 etc as im doing a for each row?

Thanks

1 Like

maybe reread above.

do a first start with:

For each Activity | TypeArgument: DataColumn - col in YourDataTableVar.Columns

  • log message: col.ColumnName
1 Like

Hi Peter,

Thanks a lot for that it seems like it’s working correctly. The only thing is i need to be reading the text for the 2nd row only. As you can see in the screenshot i just want the dates.

Is there anyway you can do this but for the 2nd row?

1 Like

For each activity | item in YourDataTableVar.Rows(0).ItemArray - typeArgument: Object

  • log message: item.ToString()
1 Like

Hi Peter,

Thank you so much that seems to be working! Really appreciate it :slight_smile:

Can I just ask one last thing regarding the output is there anyway i can possibly skip the first 2 columns?

1 Like

YourDataTableVar.Rows(0).ItemArray.Skip(2)

1 Like

Seems to be getting an error on protection level. See attached screenshot.

Thanks

1 Like

was a typo use dot instead of comma. check updated statement

1 Like

Thanks a lot Peter.

Really appreciate the help.

Have a good rest of your day
:slight_smile:
Thanks

1 Like

Perfect so the topic can be closed by:
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum