please share with us some sample rows and give us some more details on what you want to achieve.
When using the first found column value which isNumeric then you also risk an invalid value exception for the default case.
FirstOrDefault).FirstOrDefault() ← last FirstOrDefault will return not a string, which is expected for the Double.Parse. This could be the reason for the object / string missmatch.
Also keep this in mind:
So a $123 Value will never be passed to the conversion function
But this query was giving me only integer like when we have “$302.45”, It will give “303”. So trying to put convert into double and currency,sultureinfous.
Your currency sign in the sheet is defined as not value but format style. If we get value from the sheet with default settings, the result is just numeric.
So can you try the following steps?
First, Read data as DataTable using ReadRange activity with PreserveFormat option.
can be different later in the datatable after read range
When we are taking too much constraints e.g. $ character is mandatory, or isDigit fails beacuse of dollar char is present we do risk that less cases we will get the amount as we could get.
For an initial start in order to have a balance of differenct aspects a LINQ could look like this:
(From d In dtData.AsEnumerable
Where d(0).ToString.Contains(“Total Amount Owed:”)
Let jra = String.Join("|", d.ItemArray )
Let mtc = Regex.Match(jra, "(?<=\$)?[\d,.]+" )
Where mtc.Success
Where Double.TryParse(mtc.Value, NumberStyles.Any, New CultureInfo("en-US"), Nothing)
Select x = Double.Parse(mtc.Value, NumberStyles.Any, New CultureInfo("en-US"))).DefaultIfEmpty(-1).First()
filtering only the total Amount rows
optional $ and simple pattern for the amount accepting also , and .
Filtering on regex match success (we had a match)
Filtering Value was parseable
Parsing the value
And if it was failing / not retrieving any value then we do return -1 (or any other default value, Or Null)
I did use with same solution but it is working, when I am using Excel application scope activity and use read activity where we have property “Preserve Format”.
But in my scenario, I have to use Read activity from workbook without excel application scope. where we don’t have property “Preserve Format”.
as mentioned above we would not recommend this LINQ, due it is conflicting with some essential basics.
As also given some alternates and also introducing into the case of excel/resulting datatable values after read range we pointed out, the differences on it.
It looks like the marker for the totals can be varying. Maybe you will in a first-round recheck the documents and redefine the complete requirements.