Datatable conversion

Hallo, I have a datatable, which has only 1 column with data. first I need to convert this datatable into datacolumn type (to remove headers with columnname.trim method), then back to datatable, but with all rows fused together to a single entry as string type.

what do you mean by convert this datatable into datacolumn type (to remove headers with columnname.trim method) ? can you give an example?

Hi @B.D

You could simply use Remove Data Column activity and add to datatable

Hi Jack,

let’s say you have a datatable consisting of 4 columns and ~15 rows.
All this data has to go to a escel sheet, with each of these 4 colunns going into 4 column in the sheet (all next to each other) but all the rows merged into just 1 cell/row ?

I tried writing each column seperately in each column of the excel sheet. It would be the fastest way, but I couldn’t get it to work, . Now I am thinking about writing each row seperately like this:
Now when I run it it says something like “row” is part of “mydatatable” and can’t be trnasfered to “mydatatble_row”

lets say i hve the following table called dt

image

  1. first i create a new empty datatable (newdt) with the same coluumn headers
    image

  2. add a new row to newdt (newRow variable is of type “DataRow”
    image

  3. i then loop over all the columns of newDt, and for each column, i merge all the rows of the same column in dt into an array then join the array with “,” so it becomes a string.
    I do this by assiging:

    String.Join(","c,dt.AsEnumerable.Select(function(row) row.Field(Of String)(column.ColumnName)).ToArray)

    to

    newRow(column.ColumnName)

    This means newRow(“Column1”) = “a,c,e,g”, amd newRow(“Column2”) = “b,d,f,h”

  1. now use “Add datarow” activity to add datarow to your newDt

  2. finally, write the newDt to excel

  3. result
    image

1 Like

Hi Jack thanks, I will try it out. How would it be a,b,c,d are written without comma under each other like:

a
c
e
g

if you dont want a comma, just replace

String.Join(","c,dt.AsEnumerable.Select(function(row) row.Field(Of String)(column.ColumnName)).ToArray)

with

String.Join(Environment.Newline,dt.AsEnumerable.Select(function(row) row.Field(Of String)(column.ColumnName)).ToArray)

result looks like this

image

2 Likes

Thank you very much Jack, it works. I tried to solve this last part for over a week now. I was getting frustrated.

Does write range overwrite the cell content with the new one ?
Because the process writes diffrent results in the same cell,. Is only the data from the last result in the cell ? And if so how can I add instead of overwriting it each time ? It should only overwrite/or empty at the beginning (the old data)…

Edit: I solved it, was kinda dumb to ask. Thanks again Jack :slight_smile:

1 Like

no problem, good luck!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.