Bug 63960

Summary: [PATCH] Pre-evaluated values in formula cells are written with the wrong type
Product: POI Reporter: Mat Mannion <m.mannion>
Component: SS CommonAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 4.1.1-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Patch to set cell type to "str" for formula cells with pre-evaluated string contents

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!