1

I have 9 columns and I want to sum value of each column in ClosedXML.

These are the columns :

foreach (Attivita attivita in listaSomthing)
{
     worksheet.Cell(index, 1).Value = attivita.Somthing;
     worksheet.Cell(index, 2).Value = attivita.Somthing;
     worksheet.Cell(index, 3).Value = attivita.Somthing;
     worksheet.Cell(index, 4).Value = attivita.Somthing;
     worksheet.Cell(index, 5).Value = attivita.Somthing;
     worksheet.Cell(index, 6).Value = attivita.Somthing;
     worksheet.Cell(index, 7).Value = attivita.Somthing;
     worksheet.Cell(index, 8).Value = attivita.Somthing;
     worksheet.Cell(index, 9).Value = attivita.Somthing;
 }

I need to sum total of Cell(index, 1), Cell(index, 2)...Cell(index, 9).

And this is the table:

enter image description here

I didn't find any useful info in the ClosedXML documentation.

Can anyone help me, please?

Thanks in advance!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MiceX
  • 27
  • 1
  • 9

1 Answers1

3

There are two ways:

  1. insert a formula in the total row that count the entire column
  2. count in memory and insert the value on the total cell

For the first option you can find something inside the documentation

https://github.com/ClosedXML/ClosedXML/wiki/Using-Formulas

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Marco
  • 86
  • 4