You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error copying range with ConditionalFormat (ColorScale) to new cell.
There is an error in XLConditionalFormat when the ConditionalFormat values are read and the value is null (which appears expected for certain conditionalFormat rules)
What is the expected behavior or new feature?
Copying the cell range should complete without error.
Is this a regression from the previous version?
No
Reproducibility
Execute the following test, it will throw an exception
System.NullReferenceException : Object reference not set to an instance of an object.
at ClosedXML.Excel.XLFormula..ctor(XLFormula defaultFormula)in D:\ClosedXML\ClosedXML\Excel\Misc\XLFormula.cs:line 15
at ClosedXML.Excel.XLConditionalFormat.<CopyFrom>b__97_0(KeyValuePair`2 kp)in D:\ClosedXML\ClosedXML\Excel\ConditionalFormats\XLConditionalFormat.cs:line 263
at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action)in D:\ClosedXML\ClosedXML\Extensions\EnumerableExtensions.cs:line 12
at ClosedXML.Excel.XLConditionalFormat.CopyFrom(IXLConditionalFormat other)in D:\ClosedXML\ClosedXML\Excel\ConditionalFormats\XLConditionalFormat.cs:line 263
at ClosedXML.Excel.XLCell.CopyConditionalFormatsFrom(XLRangeBase fromRange)in D:\ClosedXML\ClosedXML\Excel\Cells\XLCell.cs:line 2258
at ClosedXML.Excel.XLCell.SetRange(Object rangeObject)in D:\ClosedXML\ClosedXML\Excel\Cells\XLCell.cs:line 2197
at ClosedXML.Excel.XLCell.set_Value(Object value)in D:\ClosedXML\ClosedXML\Excel\Cells\XLCell.cs:line 685
at ClosedXML_Tests.CopyingRangesTests.CopyConditionalFormatColorScaleInRange()in D:\ClosedXML\ClosedXML_Tests\Excel\Ranges\CopyingRangesTests.cs:line 149
Workaround
In the XLConditionalFormat.cs Line 262, guarding for a null Value resolves the crash.
ie
The issue still persists on versions 102.2, 103.0 beta and 104.0 preview.
Simply trying to add an existing Worksheet (with 2-Color gradient scale conditional formatting) to a new Workbook object, FinalWorkbook.AddWorksheet(s);
generates an error almost identical to the one above.
System.NullReferenceException: Object reference not set to an instance of an object.
at ClosedXML.Excel.XLFormula..ctor(XLFormula defaultFormula)
at ClosedXML.Excel.XLConditionalFormat.<CopyFrom>b__97_0(KeyValuePair`2 kp)
at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action)
at ClosedXML.Excel.XLConditionalFormat.CopyFrom(IXLConditionalFormat other)
at ClosedXML.Excel.XLCell.CopyConditionalFormatsFrom(XLRangeBase fromRange)
at ClosedXML.Excel.XLCell.CopyFrom(IXLRangeBase rangeObject)
at ClosedXML.Excel.XLRangeBase.CopyTo(XLCell target)
at ClosedXML.Excel.XLRangeBase.CopyTo(IXLRangeBase target)
at ClosedXML.Excel.XLColumn.CopyTo(IXLColumn column)
at ClosedXML.Excel.XLWorksheet.<>c__DisplayClass156_0.<CopyTo>b__0(KeyValuePair`2 kp)
at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action)
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName, Int32 position)
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName)
at ClosedXML.Excel.XLWorkbook.AddWorksheet(IXLWorksheet worksheet)
at MyProject.MainWindow.<>c__DisplayClass20_0.<GenerateDistributables_Click>b__0()
The Conditional Formatting rules don't do anything fancy, all of their ranges are totally valid values. The only thing that seems to make the problem go away is to remove the conditional formatting altogether.
Do you want to request a feature or report a bug?
Did you test against the latest CI build?
Version of ClosedXML
0.95.3 - abe7cc0
What is the current behaviour?
Error copying range with ConditionalFormat (ColorScale) to new cell.
There is an error in XLConditionalFormat when the ConditionalFormat values are read and the value is null (which appears expected for certain conditionalFormat rules)
What is the expected behavior or new feature?
Copying the cell range should complete without error.
Is this a regression from the previous version?
No
Reproducibility
Execute the following test, it will throw an exception
Code to reproduce problem:
Will throw an exception
Workaround
In the XLConditionalFormat.cs Line 262, guarding for a null Value resolves the crash.
ie
The text was updated successfully, but these errors were encountered: