I want to sum column amount, tax in excel.
But number in file as text.
Please guide me about it.
I want to sum column amount, tax in excel.
But number in file as text.
Please guide me about it.
Hi @fairymemay
U can the linq query to obtain the sum
First read the excel file and store in dt1
For getting sum of amount
dt1.AsEnumerable().Sum(Function (row) Cint(row(“amount”)).ToString
Similarly u can do this for other columns too
lets use CDbl instead to keep the fractions
dt1.AsEnumerable().Sum(Function (row) CDbl(row(“amount”).toString.Trim)).ToString
It errors.
check for empty values in the datatable as empty values cannot be converted with CDbl
ideally there should no empty values (maybe overhead of to many blank rows)
so it is suggested to get control on the not needed rows
A work around could be:
dt1.AsEnumerable().Sum(Function (row) CDbl(“0” & row(“amount”).toString.Trim)).ToString
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.