Skip to content

InvalidOperationException loading iconSet with formula cfvo from extLst #2431

Description

@swmal

Description

Loading a workbook with an icon set conditional formatting rule stored in extLst throws when a threshold uses type="formula" with a numeric constant value.

Exception

System.InvalidOperationException: Value can only be changed if Type is
Num, Percent or Percentile. Current Type is "Formula"

Cause

Icon sets using extended sets (3Stars, 3Triangles, 5Boxes) or cross-sheet formulas are stored in extLst. The reader routes a numeric <xm:f> value to the Value setter without checking whether the cfvo type is Formula. The regular icon set reader and the databar reader already guard against this; the ext icon set reader does not.

Repro

using var package = new ExcelPackage();
var ws = package.Workbook.Worksheets.Add("Sheet1");
var iconSet = ws.ConditionalFormatting.AddThreeIconSet(
    new ExcelAddress("A1:A10"),
    eExcelconditionalFormatting3IconsSetType.Stars);
iconSet.Icon3.Type = eExcelConditionalFormattingValueObjectType.Formula;
iconSet.Icon3.Formula = "67";

var stream = new MemoryStream();
package.SaveAs(stream);
stream.Position = 0;
using var reloaded = new ExcelPackage(stream); // throws

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions