MiceX
MiceX

Reputation: 27

How to sum column value in ClosedXML

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!

Upvotes: 1

Views: 6230

Answers (1)

Marco
Marco

Reputation: 86

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

Upvotes: 3

Related Questions