Bug 65730 - DataFormatter should format cell values on cells that have formulas but no formula evaluator provided
Summary: DataFormatter should format cell values on cells that have formulas but no fo...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 5.0.x-dev
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-08 12:52 UTC by PJ Fanning
Modified: 2021-12-29 00:23 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PJ Fanning 2021-12-08 12:52:27 UTC
POI does not implement all functions and there are bugs reported regularly. We have little hope of getting close to total coverage.

This is the method and javadoc that I plan to change:

    /**
     * <p>
     * Returns the formatted value of a cell as a {@code String} regardless
     * of the cell type. If the Excel format pattern cannot be parsed then the
     * cell value will be formatted using a default format.
     * </p>
     * <p>When passed a null or blank cell, this method will return an empty
     * String (""). Formulas in formula type cells will not be evaluated.
     * </p>
     *
     * @param cell The cell
     * @return the formatted cell value as a String
     */
    public String formatCellValue(Cell cell) {
        return formatCellValue(cell, null);
    }
Comment 1 PJ Fanning 2021-12-08 12:54:19 UTC
The excel file will usually have a cached value stored on the cell. We can still fail if this cached value is missing.
Comment 2 PJ Fanning 2021-12-08 13:01:30 UTC
The current code returns the formula if the formula evaluator is not set - so I don't want to break backward compatibility.

Maybe better to add a boolean param which says whether to prefer the cached values.
Comment 3 Nick Burch 2021-12-08 13:23:15 UTC
See bug #45404 for the original contribution, which is where the formula logic first came from

I'd lean towards a boolean when you create the DataFormatter, similar to how we do for CSV stuff and locales, probably with a getter and setter for later changes. That's probably easier to use than overriding the format method

If there's no cached value, I guess we return something like #N/A (error type 0x2a)?
Comment 4 PJ Fanning 2021-12-08 13:49:00 UTC
I've added DataFormatter setUseCachedValuesForFormulaCells - if there is no cached value, it returns the cell formula (which is the legacy behaviour). - r1895699
Comment 5 PJ Fanning 2021-12-08 13:58:35 UTC
I will follow up with extra test coverage over the coming days.
Comment 6 PJ Fanning 2021-12-09 12:52:33 UTC
This issue was raised based on comments in https://stackoverflow.com/questions/70260410/generic-way-to-parse-excel-files