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
Hi @Valeriia,
Use output data table activity to convert datatable to string.
Reference
https://activities.uipath.com/docs/datatable-output-data-table
After that using write text file* activity you can write into text file.
Reference
https://activities.uipath.com/docs/file-write-text-file
Regards,
Arivu
thank you for help, looks like work)
How to skip headers from the output datatable ?
If you download datatable from excel you uncheck headers.
UI Path adds its own headers if âadd headersâ is left unchecked though. Column0, Column1 etc
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.
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(Environment.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
I wish i have help and remember to mark a solution if you had one.
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.
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
Thanks for your response.
I have never used âAdd Data rowâ and i am confused with the fields to b filled.
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.
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
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
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
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
Hi @Faraz_Subhani,
And also use a comma as separator not + in ArrayRow
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
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
Thanks @Rishabh_Lakhera and @Ananthu for your help and also for being patient.
The solution works.
Hi @Valeriia
Since this is an old post I think should give you a correct answer,
- Using assign activity create a new data table using (new System.Data.DataTable)
- Using a for each and add columns to your new table using a scrapped table. At this point Add Data Column activity Type Argument should be string type
- Using another for each add data rows to your new table using a scrapped table.