Unplanned
Last Updated: 30 Apr 2024 13:44 by ADMIN
Marcelo
Created on: 22 Feb 2024 19:28
Category: SpreadProcessing
Type: Bug Report
1
SpreadProcessing: NullReferenceException is thrown when copying the UsedCellRange of a worksheet with conditional formatting
If the conditional formatting is missing, the copy operation is executed with no errors.
2 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 30 Apr 2024 13:44

Hello, Paul,

Thank you for bringing this to our attention. The ticket has already been related to this public item.

I would encourage you to cast your vote for the item to increase its priority. The more votes an item gathers, the higher its priority becomes. You can click the Follow button to get notified for any status changes.

Please excuse us for the inconvenience caused. We will do our best to introduce a proper fix accordingly.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Paul
Posted on: 29 Apr 2024 12:24
I hit this and didn't find this ticket when searching so i had filed a new ticket. Here is the information from my ticket:

It appears that if a cell has a conditional formatting rule of the type "Format only cells that contain" there is a null reference exception that occurs when you try to copy that cell. I've attached an excel sheet that uses "Cell value equal to 0" but you can change it to any of the other rules such as greater than, between, etc and the result is the same.

I am using .net 7. I originally hit it with 
Telerik.UI.for.Wpf.70.Xaml.2023.3.1114. I updated to Telerik.UI.for.Wpf.70.Xaml.2024.1.423 to see if it was fixed but it still appears to happen.

Simple code for repro:
using var fileStream = File.Open( spreadsheetFilePath, FileMode.Open );

var formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
using var workbook = formatProvider.Import( fileStream ); 
using var sheet1 = workbook.Worksheets.FirstOrDefault( ws => ws.Name.Equals("Sheet1", StringComparison.OrdinalIgnoreCase));
if( sheet1 != null)
{
    var test = sheet1.UsedCellRange;
    var testSelection = sheet1.Cells.GetCellSelection( test );
    testSelection.Copy();
}



Exception details:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Telerik.Windows.Documents.Spreadsheet
  StackTrace:
   at Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormattings.ConditionalFormattingDxfRule.TranslateArgument(ICellValue argument, Worksheet worksheet, CellIndex targetIndex)

The debugger shows that the argument parameter is null. Below is the call stack from the debugger since the exception call stack doesn't give the full stack.

  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormattings.ConditionalFormattingDxfRule.TranslateArgument(Telerik.Windows.Documents.Spreadsheet.Model.ICellValue argument, Telerik.Windows.Documents.Spreadsheet.Model.Worksheet worksheet, Telerik.Windows.Documents.Spreadsheet.Model.CellIndex targetIndex)
> Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormattings.EqualToRule.CopyOverride(Telerik.Windows.Documents.Spreadsheet.Model.Worksheet targetWorksheet, Telerik.Windows.Documents.Spreadsheet.Model.CellIndex targetIndex)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormattings.ConditionalFormattingDxfRule.Copy(Telerik.Windows.Documents.Spreadsheet.Model.Worksheet targetWorksheet, Telerik.Windows.Documents.Spreadsheet.Model.CellIndex targetIndex)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormattings.ConditionalFormatting.Copy(Telerik.Windows.Documents.Spreadsheet.Model.Worksheet worksheet, Telerik.Windows.Documents.Spreadsheet.Model.CellIndex targetIndex)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.WorksheetFragment.CopyPasteConditionalFormattings(Telerik.Windows.Documents.Spreadsheet.Model.CopyPasteContext context, System.Collections.Generic.HashSet<Telerik.Windows.Documents.Spreadsheet.PropertySystem.IPropertyDefinition> nonDefaultProperties, Telerik.Windows.Documents.Spreadsheet.Core.DataStructures.LongRange fromLongRange, Telerik.Windows.Documents.Spreadsheet.Core.DataStructures.LongRange toLongRange)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.WorksheetFragment.CopyPasteCellProperties(Telerik.Windows.Documents.Spreadsheet.Model.CopyPasteContext context, Telerik.Windows.Documents.Spreadsheet.Core.DataStructures.LongRange fromLongRange, Telerik.Windows.Documents.Spreadsheet.Core.DataStructures.LongRange toLongRange)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.WorksheetFragment.CopyPasteCellProperties(Telerik.Windows.Documents.Spreadsheet.Model.CopyPasteContext context)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.WorksheetFragment.CopyPaste(Telerik.Windows.Documents.Spreadsheet.Model.CopyPasteContext context, out System.Collections.Generic.List<Telerik.Windows.Documents.Spreadsheet.Model.CellRange> affectedCellRanges, out System.Collections.Generic.IEnumerable<Telerik.Windows.Documents.Spreadsheet.Model.Shapes.FloatingShapeBase> newShapes)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.WorksheetFragment.WorksheetFragment(Telerik.Windows.Documents.Spreadsheet.Model.CellRange cellRange, System.Collections.Generic.IEnumerable<Telerik.Windows.Documents.Spreadsheet.Model.Shapes.FloatingShapeBase> shapes, Telerik.Windows.Documents.Spreadsheet.Model.Worksheet fromWorksheet, bool shouldPasteAsText, bool isCellCopyPaste, Telerik.Windows.Documents.Spreadsheet.Model.PasteOptions pasteOptions)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.CopyInternal(Telerik.Windows.Documents.Spreadsheet.Model.PasteOptions pasteOptions)
  Telerik.Windows.Documents.Spreadsheet.dll!Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.Copy()
Attached Files: