ListObject.ConvertToRange throws NullReferenceException on a table with an empty style

The attached file contains few tables with empty styling. In the following code, ConvertToRange throws NullReferenceException:


public void Fails()
{
var workbook = new Workbook(GetFullPath(“sample.xlsx”));
workbook.Worksheets.SelectMany(ws => ws.ListObjects).ToList()
.ForEach(l => l.ConvertToRange());
}

If I assign some style to a table before calling ConvertToRange, it works:

public void Works()
{
var workbook = new Workbook(GetFullPath(“sample.xlsx”));
workbook.Worksheets.SelectMany(ws => ws.ListObjects).ToList()
.ForEach(l =>
{
l.TableStyleType = TableStyleType.TableStyleMedium21;
l.ConvertToRange();
});
}

It looks like a simple bug.
Thanks.

Hi,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue after executing the following sample code with the latest version: Aspose.Cells for .NET 8.4.1. We found that if the table style is set then exception is not thrown but if the table style is not set, then null reference exception is thrown.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43570 - ListObject.ConvertToRange throws NullReferenceException on a table with an empty style

C#

var workbook = new Workbook(“sample.xlsx”);


for (int i = 0; i < workbook.Worksheets.Count; i++)

{

Worksheet worksheet = workbook.Worksheets[i];


for (int j = 0; j < worksheet.ListObjects.Count; j++)

{

ListObject l = worksheet.ListObjects[j];

// l.TableStyleType = TableStyleType.TableStyleMedium21;

l.ConvertToRange();

}//for

}//for
Exception:
A first chance exception of type 'System.NullReferenceException' occurred in Aspose.Cells.dll
symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
at ’’.’.”˜(Style , Style , Style )
at Aspose.Cells.Tables.ListObject.ApplyStyleToRange()
at Aspose.Cells.Tables.ListObject.ConvertToRange()

Additional information: Object reference not set to an instance of an object.

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.4.1.1 and let us know your feedback.

Thanks, v8.4.1.1 solves my issue.

Hi Dmitry,


Thank you for the confirmation. Please feel free to contact us back in case you need our further assistance with Aspose APIs.

The issues you have found earlier (filed as CELLSNET-43570) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.