Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect value retrieving cell value when COUNTIFS is used #60

Open
jonneale opened this issue Jan 5, 2017 · 3 comments
Open

Incorrect value retrieving cell value when COUNTIFS is used #60

jonneale opened this issue Jan 5, 2017 · 3 comments

Comments

@jonneale
Copy link
Contributor

jonneale commented Jan 5, 2017

Hi Martin

We have a cell containing a formula which returns a weird result whenread-cell is called on it. I suspect this is a known POI issue, although I couldn't find any mention of it. We can work around it by using the underlying getNumericCellValue which I appreciate is probably not a great catch-all solution particularly for non-numeric formulae, but wonder whether you happen to know what's going on and whether you could point towards a fix.

We have seen this issue specifically in cases when the COUNTIFS function is being called with multiple predicates.

Given the sheet below:
workbook.xlsx

Which for reference, looks like this:

screen shot 2017-01-05 at 16 34 29

I would expect the below code snippet to return the numerical value in cell B2, which is 0:

(ns docjure-test.core
  (:require [dk.ative.docjure.spreadsheet :as docjure]))

(defn read-file [path]
  (let [sheet (->> path 
                   (docjure/load-workbook)
                   (docjure/sheet-seq)
                   first)
        cell  (docjure/select-cell "B2" sheet)]
    (docjure/read-cell cell)))

Instead, when I evaluate this code. I get 2.0

If we replace the call to read-cell with the raw getNumericCellValue, as below:

(defn read-file [path]
  (let [sheet (->> path 
                   (docjure/load-workbook)
                   (docjure/sheet-seq)
                   first)
        cell  (docjure/select-cell "B2" sheet)]
    (. cell getNumericCellValue)))

The value 0.0 is returned as expected.

If there's no simple way to fix this issue, is there any way to throw an exception in this case? It would be better for us to retrieve no value instead of the wrong value.

Thanks

@jonneale
Copy link
Contributor Author

jonneale commented Jan 5, 2017

Now I look a bit harder, it could well be an issue resulting from this bug, which does indeed point to a problem with POI's implementation of COUNTIFS, which is presumably why the formula evaluator used by read-cell is returning the wrong answer. It's weird that getNumericCellValue returns the correct value, though.

@mjul
Copy link
Owner

mjul commented Jan 17, 2017

I agree that it sounds like a POI problem. Maybe the values of the formula are persisted with the sheet so getNumericCellValue works as long as the sheet has not been changed?

@manuelherzog
Copy link
Contributor

it indeed is persisted. The Spreadsheets contains the latest formula results, so you don't need to calculate the formula if you just want to display it to the user. I noticed it while implementing the SXSSF Interface for stream-reading the Spreadsheets, because my Excelfiles i have to import would need more RAM then even a good server has.

I think the bug can be closed as it is resolved in POI some time now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants