Creata a datatable from a text file

Hi All,

I have a text file from which I need to get the data into datatable to further process the data.

I have used Read Text file activity, saved the data into string then using Generate datatable activity.
Below are the column names
Project definition Description WBS Elem Description Created on Changed on
Please note I have 2 column names same
Screenshot of Generate Datatable activity parameters

I am not getting desired output. Can someone help me?

What is the format of the data in the text file?

Here is some sample data

So it’s tab delimited. Your Generate Datatable appears to be set correctly. What’s the issue? You won’t see anything in Test Preview unless you paste something into Sample Input. Paste the contents of the text file into Sample Input.

Only first column seems to be separated when I select solumn seperator as Space. See screenshot below

if changed it to Tab, all columns are coming in one cell. attached screenshot

Are you sure it’s actually tabs and not something else? You’ll have to find out for sure what the column separator is.

looks like Tab. Attaching the sample text file.
sample.txt (706 Bytes)

Word says it’s tab. I even read the file into a variable in UiPath and used the ASC function to find out the ASCII code of the delimiter. It comes back as 9 which is, in fact, a tab.

Why the Generate Data Table isn’t working, I have no idea. Won’t work for me either.

I suggest reporting it to UiPath support.

Also, even if you get it to work there’s a problem. You have two columns named Description. This will cause an error when trying to generate the datatable.

Another thought, you could use a Replace to replace the tabs with commas or some other delimiter and see if Generate Datatable works with a non-tab delimiter.

Replacing Tab with comma worked and I am able to generate desired datatable. Thank you so much.
Now I have to lookup this datatable and get value for Description column(second one). Is there any way I can have Target Column as Description (skip 1st Description).

You should rename one of those Description columns in the text file, or in the text file variable. Then you can just reference whichever of the columns you want. I’m surprised it will let you create a datatable with two columns named the same.

Also, it’s worth considering if the , character may appear in any of the values - throwing off the csv format.

Can you elaborate more on how to handle this situation?


Jim, Jr.,52

That third row is a problem. It has 3 columns if you just split on the comma. Proper CSV format would be:

“Jim, Jr.”,“52”

Now all 3 rows have 2 columns.

If you’re really OCD about things like this, like I am :slight_smile: then you could replace all the tabs with “,” and then add a " at the beginning and end of each row. Heck, if you do all that you could just write it back to the file, then use Read CSV.

I have somewhat of a similar issue. I have a tab delimited text file and it seems to work except for the header column.
I checked if every entry had a tab. it does. it combines the first 3 into one column, the next 2 into another column, and then 2 have an individual column, and it then creates 3 additional columns named column1, column2, and column 3.

Any help would be great.

“c5 c10 c12 c15” “c16 c510” Column1 Column2 Column3

For that you should split on VbTab. Read the file in as simply a text file, split on VbCrLf to get your rows, and split each row on VbTab to get the columns for each row.