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
Description
Loading a workbook with an icon set conditional formatting rule stored in
extLstthrows when a threshold usestype="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 inextLst. The reader routes a numeric<xm:f>value to theValuesetter without checking whether the cfvo type isFormula. The regular icon set reader and the databar reader already guard against this; the ext icon set reader does not.Repro