How to concatenate an excel column in to a string?

Hi All,
I need to concatenate the column values in to a string and need to write into an cell.
For example below is the excel column value.
Currentrow(“Location”).tostring
Location
H
L
M
O
J

the final output should be “H,L,M,O,J”

@ppr
@Yoichi
@Nithinkrishna
@Gokul001
@vishal.kp
@supermanPunch
@ushu

Hi @Vrishchik ,

Could you try the below Expression :

String.Join(",",DT.AsEnumerable.Select(Function(x)x("Location").ToString))

Here, DT is your Datatable variable

4 Likes

Hi @Vrishchik - Try below steps

  • Read the excel data to data table
  • Take Assign activity and apply below exp
Variable of type String Output = String.Join(","c,DT.AsEnumerable().Select(function(x) x(0).ToString))
  • Change the column index value according to your input, col1 - x(0), col2 - x(1)…
  • Use write cell activity to write the comma separated values in the Output variable
1 Like

This worked perfectly for me but I need to write inside the cell value C2.
But it is writing the same value into multiple cell value.
I am passing the value inside the for each row loop

@Vrishchik ,

You do not need to use For Each Row activity if the goal is to achieve writing the value to a particular cell.

You can remove the For Each Row Activity if you were using that for this sole purpose only.

Else just place the Write Cell Activity outside the For Each Row Activity with the Expression provided in the previous post.

It is dynamic like it has to write c2, c3,c4 etc

@Vrishchik ,
Can you please confirm how is your input .
Is it like this
image

Or this :
image

Regards,

1 Like

@Vrishchik ,

Does it need to write the Same data in multiple cells ? Or do you have different data to be written for each cell ?

If Different data, then we would need to understand your total requirement.

From the initial requirement, you did mention only the Concatenation part and writing the value to an Excel Cell.

I do have different data, Just I took an example

Hi @Vrishchik ,

Greetings

It would be helpful if you can perhaps share your input Excel file?

Regards,

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