How to Copy entire Column(multiple columns) from Datatable

Hi Guys,

I have got an expression for copying entire column(single column). Please help me to copy entire column (multiple columns) from a datatable and paste the same in SAP.

expression - string.Join(Environment.NewLine,DataTable.AsEnumerable().[Select](Function(s) s.Field(of Double) (“Column1”)).toarray())

Please update the changes in the above expression as per my requirement.

Thanks in advance.

Hi there,

I think I understand you are wanting to store the entire column into string to be used to paste into SAP.

String.Join(System.Environment.NewLine,DataTable.AsEnumerable().Select(Function(s) s("Column1”).ToString).ToArray())

Then, you can use Set Clipboard or use the string directly into SAP.

To do multiple columns, you can assign the expression again but change the column name or use column index.

Here is what I used to test the expression: JoinColumn.xaml (5.5 KB)

Hope this helps. Regards!

Thanks Clayton,

I too have used the same expression by changing the column names.

Thanks anyways for your support…

Dear ClaytonM,
I’m stuck… I need to copy the whole range (not just one column but several continuous columns, the range vary dynamically) to SAP. It’s working with one column (obviously) but how do I define the range to be inputted in each “line”?
Thanks in advance

Hi @natalynv
Are you able to run each column through a loop? Sorry, I’m not sure how you are needing to paste the columns into SAP.

Do use a loop, you can do this with a For each activity using TypeArgument as DataColumn:

ForEach col in dt1.Columns
    columnString = String.Join(System.Environment.NewLine,DataTable.AsEnumerable().Select(Function(s) s(col.ColumnName).ToString).ToArray())

So you can use the col variable as a DataColumn in the expression that was presented above.

However, like I said, I’m not entirely sure how you are needing to paste the data in SAP.

Hopefully, it helps though.


When I do it manually, I can use the paste (Ctrl+V) and it pastes the whole range (that is always 3 rows and x columns where x varies).
I was trying to find the solution to paste it with this NewLine separations but at once…
really no option?
the data to input is stored in a csv file, as an example:

and I need to paste it in exactly the same format/order:

Trying your proposed solution I have this error:

Thanks in advance

You could perform keystroke automation on the Excel file, to select all the data, copy it to the clipboard, then paste it.

Ctrl+a I think let’s you select the data. If not, then you would need to use Read Range, get the range of the data using the row and column count, and convert the numbers to range.
It can be like this:

Select Range, A1
Send Hotkey on excel, Ctrl a
Send Hotkey on excel, Ctrl c
Send Hotkey on SAP, Ctrl v

be careful though cause using clipboard can be interrupted if you manually type ctrl+c while it is running.

I will have to get back to you on that compiler error because the code looks correct, unless you have something else wrong (such as the TypeArgument on the ForEach is not DataColumn)


It’s not from Excel: I copy the specific range according to the date and other input variables (defining the project and the company) from one google spreadsheet. I’m creating the csv file just to Set to clipboard the same range but if I try to Send a hockey later it pasted a Column1, Column2,… in the first cell; value1,value2,… in the cell below etc…

How can I copy an entire column values into clipboard? Then I will paste them into SAP.
I understand the expression you mentioned above helps but to where should I write this expression?
The example has been used for MessageBox