Bug 63960 - [PATCH] Pre-evaluated values in formula cells are written with the wrong type
Summary: [PATCH] Pre-evaluated values in formula cells are written with the wrong type
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 4.1.1-FINAL
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2019-11-25 11:13 UTC by Mat Mannion
Modified: 2019-12-31 06:36 UTC (History)
0 users



Attachments
Patch to set cell type to "str" for formula cells with pre-evaluated string contents (336 bytes, application/tar+gzip)
2019-11-25 12:17 UTC, Mat Mannion
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mat Mannion 2019-11-25 11:13:24 UTC
A pre-evaluated value in a Formula cell is written by SheetDataWriter as follows:

    switch(cell.getCachedFormulaResultType()) {
        case NUMERIC:
            writeAttribute("t", "n");
            break;
        case STRING:
            writeAttribute("t", STCellType.S.toString());
            break;
        case BOOLEAN:
            writeAttribute("t", "b");
            break;
        case ERROR:
            writeAttribute("t", "e");
            break;
    }

The problem is that STCellType.S is for shared strings, but then the value is immediately written with <v></v> for an inline string. The correct cell type in this situation is "str", not "s".

This causes Excel to mark the sheet as invalid when opening.
Comment 1 Mat Mannion 2019-11-25 12:17:05 UTC
Created attachment 36901 [details]
Patch to set cell type to "str" for formula cells with pre-evaluated string contents

Patch attached.
Comment 2 Dominik Stadler 2019-12-31 06:36:15 UTC
Applied via r1872130, thanks for the patch!