How to convert datatable to string value


#1

Hi! I scrapped datatabe and need to paste it in txt format, how can i convert datetable to string? I tried to string method, but it is not work


#2

Hi @Valeriia,

Use output data table activity to convert datatable to string.
Reference

After that using write text file* activity you can write into text file.
Reference

Regards,
Arivu


#3

thank you for help, looks like work)


#4

How to skip headers from the output datatable ?


#5

If you download datatable from excel you uncheck headers.


#6

UI Path adds its own headers if “add headers” is left unchecked though. Column0, Column1 etc


#7

Hi KEntwistle,
Thanks for the prompt response.
Yeah i know that works .
but my requirement is when we use output data table it displays the data with headers in csv format, but i don’t want to display headers.


#8

I dont know if you still need a solution. However, i have learned that the more versatile way to log or write all to a string is using string.join and LINQ.

Basic case and works always:

       string.join(Enviroment.NewLine, yourDataTable.Rows.Cast(of DataRow).Select(function(row) string.join(",",row.ItemArray))

Just copy and paste and change yourDataTable to your variable.

In case you want to understand and goo deeply you can do a lot of changes some of them:

If you add take()/skip() before .Select you can take or skip a number of items of the table for example skip(1) would skip the header in case you have read it as a normal row.

If you want to get some special data (just one item of the row/ or do some changes before going to a string) you just have to change the content of the select for example:

.Select(function(row) row(0).tostring) will show only the first column data
.Select(function(row) string.join(",",row.ItemArray.Take(3)) will show only the first 3 rows

And much more :slight_smile:

I wish i have help and remember to mark a solution if you had one.


#9

Hi @KEntwistle @arivu96

I have few string values eg. “xyz”, “abc” which are being extracted in the workflow from different files(.pdf,.docx) in a for each loop. Ultimately i need to store these values in a .csv file , when i am trying to use write csv activity, as an input it’s asking for data table but my values which are to be stored are string.
Ho can I convert these string values and give input in 'Write CSV ’ activity as a data table, I don’t think i can use Output table.
Please assist.


#10

Hi @Faraz_Subhani,
While you are getting those data from PDF and docs files using for each loop try to add a “add data row” activity that will add the data to a data table. Before that build a data table as per your requirement.

Finally write that data table to a csv file using “write csv” activity.

Hope it would resolve your issue.

Thanks and regards,
Ananthu


#11

Thanks for your response.
I have never used ‘Add Data row’ and i am confused with the fields to b filled.
image

Secondly, in my flow,1 document is being processed at a time and simultaneously the string data is being extracted(that needs to be stored in CSV file) and so on in the next iteration another document is being processed and string data is being extracted from the second document and each string data coming from every document needs to be stored in a separated row.
Help me out, I am really confused as to what to fill in those fields of Add data row.


#12

Hi @Faraz_Subhani,
In the ArrayRow field, enter the string variable. For example:

If you have two strings, then give those variables inside the array.
{str1,str2}

str1 and str2 being the strings that you have extracted from the documents.

In the DataTable field, mention the name of the data table that you have created.

Use build DataTable activity to create a data table before doing these.

I could send a sample workflow by tomorrow morning if you want.

Regards,
Ananthu


#14

Hey @Faraz_Subhani
Are ReportDate and UWI variables? Or is it one string the way its written?

Also use Output Data Table activity above message box to first convert the data table object “dt” to a string,meaning, in the input property give the “dt” variable and in the output property give a string variable. Then just print that string variable in the message box.

Regards,
Rishabh


#15

Hi @Faraz_Subhani,
Use Output DataTable activity to convert the data table into a string before displaying it in a message box.

Anyway I will send the xaml file tomorrow morning.

Thanks and regards,
Ananthu


#17

Are they supposed to be in two columns? or have you concatinated them on purpose?
If they’re supposed to be in seperate columns then they should look like {UWI,ReportDate}

Using Output Data Table you can easily print it in the message box :slight_smile:


#18

Hi @Faraz_Subhani,
And also use a comma as separator not + in ArrayRow


#20

I think probably i will have to put ‘Add data row’ in for each loop because now, i am trying to override on the same row, hence the problem


#21

For that purpose use a while loop for the nmber of items or the rows you want to insert,
inside the while loop put the add data row activity, lets say you want to add 5 rows/values, use suitable cndition in while for the same…

so after this loop you’ll have 5 rows in the data table…then outside the while loop just use write csv and give dt as the input you’ll gate the 5 values in 5 rows in csv


#22

Thanks @Rishabh_Lakhera and @Ananthu for your help and also for being patient.
The solution works.