How to convert IEnumerable object type to Data table or String?

datatable
excel
uiautomation
studio

#1

Hi,

I am trying to copy a column data from an excel sheet to the clipboard and paste the same data onto a work space. I have used the “Read column” function to read the respective column from excel and I saved the content to a reference variable with type “IEnumerable Object”(as it is only accepting this type).
I am unable to find a way using which I can convert this IEnumerable Object type to Data table or String so that I can paste the same in the desired work space??

Thanks in advance.


#2

Having the same problem. #Bump


#3

Hi,
If you just want to convert your datatable to a string, one way is to use the Output Datatable activity, which outputs it to a comma-delimitted string. Then, you can set that text somewhere or use Set to Clipboard.

Thanks.


#4

Simple way:
(outputDT has just one column of type String)


#5

To String

stringColumn = string.Join(",", IEnumCol.ToArray() )


#6

.ToArray() is not needed, it accepts an IEnumerable directly as well.

Interestingly it works irregardless of actual types in the collection and concatenates it’s .ToString() outputs. Didn’t know that :slight_smile: