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:

How to sum column value in ClosedXML

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

Can anyone help me, please?

Thanks in advance!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x