Excel Automation for column

I m having a excel file having a column name with specific data values into it. i want to get the whole data value into string variable.

For example

Column Name - SrNo.
Data Value - 1
Data value - 2

I want to fetch only numbers as results at once

Use the following LINQ:

dt_input.AsEnumerable.Select(Function(x) x("SrNo.")).ToArray

And then you can join the array into a string with String.Join (String.Join Method (System) | Microsoft Learn)

image

what must the variable type? i do not want to use for each to extract this data

Hi @tejas.kotharkar

=> Read Range Workbook
Output-> dt

=> Use below syntax in Assign activity

srNoValues = String.Join(", ", 
                    (From row In dt.AsEnumerable()
                     Select row.Field(Of Double)("SrNo")).ToArray())

srNoValues is of DataType System.String

Regards

Hi @tejas.kotharkar ,

There isn’t anything wrong with using For Each, however the solution provided by @ignasi.peiris doesn’t require a For Each and you just have to assign it to a string variable.

Kind Regards,
Ashwin A.K

Linq does not use ForEach:

That results in an Array of Int (As they are numbers) but can be converted into an array of strings, to then join them in a string:

Activity: Assign
Left = arr_stringValues
Right = dt_input.AsEnumerable.Select(Function(x) x("SrNo.").ToString).ToArray

2nd Activity: Assign
Left = str_JoinedValues
Right = String.Join(“,”,arr_StringValues)

In addition, you can do everything in a single assign like so:

Activity = Assign
Left = str_JoinedValues
Right = String.Join(",",dt_input.AsEnumerable.Select(Function(x) x("SrNo.").ToString).ToArray)

Hope this helps!

Exactly, But Its giving error value of object cannot be converted to string after keeping the variable to string

Hi @tejas.kotharkar

=> Read Range Workbook
Output-> dt

=> Use below syntax in Assign activity

srNoValues = String.Join(", ", 
                    (From row In dt.AsEnumerable()
                     Select row.Field(Of Double)("SrNo")).ToArray())

srNoValues is of DataType System.String

Check the below image:

Regards

I’d say you should double-check your variables, as I just tested it, and looks to be working…

image

image

image

TestJoin.xaml (7.7 KB)

Capture
i want only numbers as a extraction

i do not want to join them

Hi @tejas.kotharkar

Can you specify what is your expected string output.

Regards

Capture1

then just use

That will return an Array of Strings

Hi @tejas.kotharkar

Do you want to change the format of a column. Intially it would be in number you want to change it to string. Is that right specify.

Regards

i want to extract column values from a column.
i tried using linq and i was unable to do it as it giving error in varaiable assigning

yes tried but unable to get the solution

Hi @tejas.kotharkar

srNoValues = (From row In dt.AsEnumerable() Select row.Field(Of Double)("SrNo")).ToArray()

srNoValues variable is of DataType Array(System.Double)


Output
image
Sequence.xaml (9.3 KB)

Regards

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