Aspose.Cells Delete Worksheet - Value cannot be null exception

Hi Aspose Team,

When deleting a worksheet (RemoveAt method on WorksheetCollection object) I am getting the following error:

Value Cannot be null.
Parameter name: value

This issue for same spreadsheets did not occur in version 20.8.0 but does occur in the latest stable version 23.9.0. I am guessing the latest version is missing some key updates. Can you check this or provide some guidance.

@tufas,

Could you please share your sample code and template Excel file to reproduce the issue on our end? We will check your issue soon.

@amjad.sahi Codewise its a simple loop we are doing on list of worksheet names to be deleted that then get removed from the worksheet collection object:

foreach(var sheetName in sheetsToBeDeleted)
{
_workbook.Worksheets.RemoveAt(sheetName);
}

_workbook.Worksheet -> Aspose.Cells.Workbook.WorksheetCollection

Attached is the santitized spreadsheet. Debug Error.zip (182.8 KB)

@tufas
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-54240

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@tufas,

By the way, are you removing all the worksheets in your provided file? Please note, you cannot remove all the worksheets as a workbook must contain at least a visible worksheet in it. This behavior is same with MS Excel. I tried the following two code segments. The first code works fine but the second one gives an error (rightly so):
1).

Workbook workbook = new Workbook("g:\\test2\\Debug Error.xlsx");

string[] worksheetNames = {"Sheet1", "Sheet2"};

    foreach (var name in worksheetNames)

    {

        workbook.Worksheets.RemoveAt(name);

    }

workbook.Save("g:\\test2\\out11.xlsx");

2).

Workbook workbook = new Workbook("g:\\test2\\Debug Error.xlsx");

string[] worksheetNames = {"Sheet1", "Sheet2", "Sheet3"};

    foreach (var name in worksheetNames)

    {

        workbook.Worksheets.RemoveAt(name);

    }

workbook.Save("g:\\test2\\out12.xlsx"); 

Do you use some other code snippet and which sheets you are trying to remove that produces the error? What is complete error trace? What is your environment and project/app type (WinForm, Console, Web application, etc.) and .NET framework version you are using?

Yes understand about the deleting all worksheets. i seem to have sanitized the model too far :slight_smile: If you include one more sheet and only delete the 3 i had included can you reproduce the issue? Also what version of aspose are you using(This issue for same spreadsheet did not occur in version 20.8.0 but does occur in the latest stable version 23.9.0)?

This is a console application using .Net 4.8.

Message:

Value cannot be null.

Parameter name: value

StackTrace:

at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)

at System.BitConverter.ToInt32(Byte[] value, Int32 startIndex)

at
. ​ [1](Byte[] [1], Int32

, Int32 )
at . ​ [1](Byte[] [1], Int32

, Int32 )
at ​.[1]( [1])

at Aspose.Cells.Workbook.[1]( [1])

at Aspose.Cells.NameCollection.[1](Hashtable [1])

at Aspose.Cells.WorksheetCollection.RemoveAt(Int32 index)

at Baml.Rsch.IQ.Core.SpreadSheet.AsposeSpreadSheet.DeleteWorksheets(IEnumerable`1 needDeletedSheetNameList) in C:\Working\Git\IQClient\iqdesktop_iqribbon_365\IQ.Core.SpreadSheet\Impl\AsposeWorksheet.cs:line 40

@tufas,

Thanks for the providing further details.

As we have already logged a ticket (“CELLSNET-54240”) for it, so we will be looking into your issue and try to figure it out soon.

Once we have an update on it, we will let you know.

@tufas

Workbook workbook = new Workbook(dir +"Debug Error.xlsx");
workbook.Worksheets.Add();
string[] worksheetNames = { "Sheet1", "Sheet2", "Sheet3" };

foreach (var name in worksheetNames)
{
     workbook.Worksheets.RemoveAt(name);
 }

workbook.Save(dir +"Dest.xlsx");

We cannot find any issue with above codes on 23.9.
Could you create a simple console project to reproduce this issue? We will check it soon.

Ok realized there was one more dependency in the code. We are removing external links before the worksheet delete. Try this:

Workbook workbook = new Workbook(dir +“Debug Error.xlsx”);
workbook.Worksheets.Add();
string[] worksheetNames = { “Sheet1”, “Sheet2”, “Sheet3” };

workbook.Worksheets.ExternalLinks.Clear();(or the obsolete workbook.RemoveExternalLinks())

foreach (var name in worksheetNames)
{
workbook.Worksheets.RemoveAt(name);
}

workbook.Save(dir +“Dest.xlsx”);

@tufas,

Thanks for providing further details.

Using your suggested line of code, I am able to reproduce the issue now.

We have reopened your ticket (“CELLSNET-54240”). We will evaluate your issue soon.

1 Like

Hello - Just checking in to see how you are getting on with this issue?

@tufas,

I am afraid, your issue is not resolved yet. Hopefully, it will be resolved within the next week or so.

Once we have figured it out or have any other updates, we will let you know.

Thanks. Also would be great to understand what other differences we have between the 2 versions.

@tufas,
Sure, we will provide required information together with the new fix/version. For the released official version, you may check the release notes to trace the changes between different versions.

@johnson.shi i was referring at the granular level, backwards compatibility for example this issue we have seen.

@tufas,

We would like to inform you that the issue (logged as “CELLSNET-54240”) has been resolved. The fix will be included in the next release (Aspose.Cells v23.10) which is expected to be released in this week or so. You will be notified when a new version is published.

We will get back to you to provide more details on it.

Thank you for the update. It will be great if you could share the details on this. Would like to know about any other areas where backward compatibility issues may arise.

@tufas,

Sure, we will keep you posted on it.

1 Like

@tufas,

It is just a bug of removing external links from shared formulas and defined names. We fixed the bug now, the fix should have no backward compatibility issue.

The issues you have found earlier (filed as CELLSNET-54240) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi