Using linq, to add two different columns and write it in the third column

Hi all

Using linq, to add two different columns and write it in the third column.

Ex
Col1
1
2
3

Col2
4
5
6

Total
5
7
9

All the columns belongs to the same sheet- sheet1.

Any idea?

@Ray_Sha1
have a check if following fits to your needs:
WriteBackCountResult.xaml (8.9 KB)
Data.xlsx (8.2 KB)

in general it is recommended:

  • using for each row for updating the sum in the row
  • read in Excel / compute / write out Excel

Or

  • read in Excel
  • clone in datatable / prepare result datable
  • construct result datatable

(From d In dtData.AsEnumerable
Let s = {0,1}.Sum(Function (x) Convert.ToInt32(“0” & d(x).toString.Trim))
Let ra = d.ItemArray.Take(2).Append(s).toArray
Select dtComputed2.Rows.Add(ra)).CopyToDataTable

  • overwrite Excel
2 Likes