Convert the data type of column of datatable

I have an excel sheet with multiple columns. I am using Read Range Activity and the data table automatically picks a column type as double which is having both number and string values .
I want to convert that Column from Double to String. I don’t want to use any custom activity .
Please help.

1 Like

Hi @Yoichi ,

Any help from your end would be really appreciated

Try using enabling PRESERVE FORMAT property in Read Range activity and then try.

1 Like

@balupad14 got it covered :+1:

1 Like

Hi,

I suppose type of Datacolumn is object if use ReadRange ativity…
Anyway, we cannot change type of DataColumn if data already exists.
The following sample is for create new datatable which has same name columns and expected data type.

Sample20211027-1.zip (8.9 KB)

If your datatable is very large, it might be better to write the above in InvokeCode.

Regards,

5 Likes

Can I create a new data table with all columns as required type and then read the excel to avoid this issue

Hi,

We can create datatable which has any type column. However ReadRange activity overwrite datatable schema when write data into it. So probably it won’t be solution.

Regards,

My data table has more than 1 lakh of data , i am using for each but it is not feasible, I am using below invoke code but it is not working
newDt = dt.Select(Function(o) o.ToString).CopyToDataTable

Please can you check once

Hi,

How about the following?

For Each row As DataRow In dt.AsEnumerable
newDt.Rows.Add(row.ItemArray.Select(Function(o) o.ToString).ToArray)
Next

Sequence.xaml (8.2 KB)

Regards,

2 Likes
1 Like

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