String to Double Datatable LinQ

Hello, I would like to convert rows from String to Double using LinQ query. However I got this error message:

image

Some of my cells are empty… I would like to include a condition: If the cell is empty, then does nothing, otherwise converts. Do you have any solutions for me? Thanks

“CSVDataTable.AsEnumerable.Select(
Function(r)CSVDataTable.Clone.LoadDataRow({r(0),r(1),r(2),r(3),r(4),r(5),r(6),r(7),r(8),r(9),r(10),r(11),r(12),r(13),r(14),r(15),r(16),r(17),r(18),CDbl(r(19)),CDbl(r(20)),CDbl(r(21)),CDbl(r(22)),CDbl(r(23))},False)
).CopyToDataTable”

@DimitriLYR

You can change cdbl(r(22)) like this

If(IsNumeric(r(22).ToString),Cdbl(r(22)),0)

Repeat same for all columns

Cheers

1 Like

Thanks for your answer, the function passes, but my values ​​in my file are still stored as text.

@DimitriLYR

Whicha ctivity are you trying?

Trying excel read range or workbook read range…?

I beleive column type is already double…

And is the excel column type changed to number as well? If not you can use format range activity

Cheers

Hi @DimitriLYR

Kindly try the below expression-

CorrectedInputDT = (From r In InputDT.AsEnumerable()
Let ab = r.ItemArray.take(18).Concat(r.ItemArray.skip(18).Take(5).ToList().ConvertAll(Function(a) CDbl(“0”+a.ToString.))).ToArray
Select CorrectedInputDT.Rows.Add(ab)
).CopyToDataTable

Regards

Hi @DimitriLYR

Kindly try the below expression-

CorrectedInputDT = (From r In InputDT.AsEnumerable()
Let ab = r.ItemArray.take(18).Concat(r.ItemArray.skip(18).Take(5).ToList().ConvertAll(Function(a) CDbl("0"+a.ToString.))).ToArray
Select CorrectedInputDT.Rows.Add(ab)
).CopyToDataTable

Regards

1 Like

I’m using the “Read Workbook” workbook read range. My column is in String

1 Like

Hi @DimitriLYR ,

Maybe an Alternate would be to use Format Cells Activity :

However, You would require to enable Modern Design and use the Excel Scope Activities to achieve this.

1 Like

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