Why won't this formula calculate unless i double click a cell?

前端 未结 1 957
难免孤独
难免孤独 2020-12-19 22:12

See this .xlsx file. No macros, of course!

When you open the file, you will see the following cells:

[Series     ]
[10         ]
[20         ]
[30            


        
相关标签:
1条回答
  • 2020-12-19 22:32

    You are adding data to an already existing Excel sheet which already contains the =SUM(B3:B7) formula.

    I guess that is an EPPlus issue. Namely, the issue is that you are not calling the Calculate() method after entering the data:

    ... you can let EPPlus calculate the results of the formulas in a workbook.

    This is done by calling the Calculate() method, which is available on Workbook, Worksheet and Range level. When Calculate() is called EPPlus will evaluate the result of the formula and store the result as the Value of the cell - just like Excel do.

    After you type a formula in Excel, Excel calculates the value and stores it in the file together with the value.

    For example you have a sheet like:

    100
    200
    =SUM(A1:A2)
    

    Excel stores this (I removed the non-relevant XML attributes):

    <sheetData>
        <row r="1">
            <c r="A1">
                <v>100</v>
            </c>
        </row>
        <row r="2">
            <c r="A2">
                <v>200</v>
            </c>
        </row>
        <row r="3">
            <c r="A3">
                <f>SUM(A1:A2)</f>
                <v>300</v></c>
        </row>
    </sheetData>
    

    When you insert the data to the XLSX file externally without the value, Excel does not have the cached value stored yet and displays 0. Your XLSX file (the one which you uploaded) contains in sheet1.xml:

    <row r="8">
        <c r="B8">
            <f>SUM(B3:B7)</f>
            <v>0</v>
        </c>
    </row>
    

    There is some explanation in the similar Java library Apache POI:

    Sometimes Excel will notice itself, and trigger a recalculation on load, but unless you know you are using volatile functions it's generally best to trigger a Recalculation.

    and there is a similar problem Excel cell displaying zero instead of a calculated / referenced value from the Java perspective.

    0 讨论(0)
提交回复
热议问题