如何对ClosedXML中的列值求和

问题描述

我有9列,我想对ClosedXML中每一列的值求和。

这些是列:

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;
 }

我需要对Cell(index,1),Cell(index,2)... Cell(index,9)求和。

这是表格:

enter image description here

在ClosedXML文档中找不到任何有用的信息。

有人可以帮助我吗?

谢谢!

解决方法

有两种方法:

  1. 在总计行中插入一个计算整个列的公式
  2. 在内存中计数,然后将值插入总单元格

对于第一种选择,您可以在文档内找到一些东西

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