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

SKEW formula in Excel results in exception instead of :FUNCTION_NOT_IMPLEMENTED #92

Open
takapai opened this issue Jul 30, 2020 · 2 comments

Comments

@takapai
Copy link

takapai commented Jul 30, 2020

I have a simple Excel worksheet that has a formula cell with the function SKEW. Screenshot below:
image

Trying to read in this Excel file will result in an exception using the following code, which is mostly straight from the README.

(defn load-xls
  "Load Excel spreadsheet and return a list of lists"
  [fname]
  (->> (xls/load-workbook fname)
       (xls/sheet-seq)
       (first)
       xls/row-seq
       (remove nil?)
       (map xls/cell-seq)
       (map #(map xls/read-cell %))))

The result is:

((1.0)Error printing return value (NotImplementedFunctionException) at org.apache.poi.ss.formula.functions.NotImplementedFunction/evaluate (NotImplementedFunction.java:40).
SKEW

I believe this should result in the cell to have the keyword value :FUNCTION_NOT_IMPLEMENTED.

@takapai takapai changed the title SKEW formula in Excel results in crash instead of :FUNCTION_NOT_IMPLEMENTED SKEW formula in Excel results in exception instead of :FUNCTION_NOT_IMPLEMENTED Jul 30, 2020
@mjul
Copy link
Owner

mjul commented Jul 31, 2020

Hello Takapai

Thank you for the bug report.

I believe it is a problem with the underlying Apache POI library. It does not fully support all Excel formulas.
You can read more about it here: https://poi.apache.org/components/spreadsheet/eval-devguide.html

SKEW is not mentioned in the list of supported functions in Appendix A at the bottom of that page.

There are two possible approaches:

  1. Fix the problem in the POI library. This would be best for everyone including people using POI without Docjure.
  2. Work around the issue in Docjure. Perhaps it would be possible to use the cached value for the formula result from the spreadsheet when we encounter this error.

I encourage you to explore these options if you have the time and motivation.

All the best,
Martin

@kimim
Copy link

kimim commented Oct 22, 2020

option 2, could define this method with a try...catch, but need an additional function read-cell-cached:

(defmethod read-cell CellType/FORMULA   [^Cell cell]
  (let [evaluator (.. cell getSheet getWorkbook
                      getCreationHelper createFormulaEvaluator)]
    (try
      (let [cv (.evaluate evaluator cell)]
        (if (and (= CellType/NUMERIC (.getCellType cv))
                 (DateUtil/isCellDateFormatted cell))
          (.getDateCellValue cell)
          (read-cell-value cv false)))
      (catch Exception e
        (read-cell-cached cell)))))

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

No branches or pull requests

3 participants