EPPlus SUMIFS return value #VALUE

T.Zacks 3,986 Reputation points
2021-02-26T18:21:04.523+00:00

I am generating excel file with EPPlus. at the end i am try to get sum of values of a column but getting #VALUE!

i used SUM formula first but got the same error. Here is a sample code.

for (int x = 2; x <= totalIteration; x++)
{
    startperiodletter = ColumnIndexToColumnLetter(x) + 2;
    endperiodletter = ColumnIndexToColumnLetter(x) + totalrows;
    tmpCell = ColumnIndexToColumnLetter(x) + (totalrows+1);

    ws.Cells[tmpCell].Formula = "=SUMIFS(B2:B99,B2:B99,>0)";
    ws.Cells[tmpCell].Calculate();
    val = (ws.Cells[tmpCell].Value == null ? "" : ws.Cells[tmpCell].Value.ToString());
}

ws.Cells[tmpCell].Formula = "=SUMIFS(B2:B99,B2:B99,>""""0"""")"; This way i use SUMIF formula with EPPLus and when i try to read value then getting value like #VALUE! i am reading value this way val = (ws.Cells[tmpCell].Value == null ? "" : ws.Cells[tmpCell].Value.ToString());

this line is not working as expected. my few cells are empty and i want to get sum of those cell value which is not empty.

please rectify me where i made the mistake in above code.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,279 questions
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,576 Reputation points
    2021-03-01T07:24:12.3+00:00

    I did a simple test. In the rules of this package, the formula does not need to add the preceding "=".

    After deleting it and adding double quotes to >0 as suggested by Viorel-1, it works fine.

    currentWorksheet.Cells["C4"].Formula = "SUMIFS(B2:B99,B2:B99,\">0\")";


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful