diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs index afe0a10..1b2f0be 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs @@ -14,8 +14,12 @@ var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var dataBar = new DataBar {ShowValue = !cf.ShowBarOnly}; - var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml() , Val = cf.Values[1].Value }; - var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml(), Val = cf.Values[2].Value }; + var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml()}; + if (cf.Values.Count >= 1) conditionalFormatValueObject1.Val = cf.Values[1].Value; + + var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml()}; + if (cf.Values.Count >= 2) conditionalFormatValueObject2.Val = cf.Values[2].Value; + var color = new Color { Rgb = cf.Colors[1].Color.ToHex() }; dataBar.Append(conditionalFormatValueObject1);