Aspose.Cells 18.2.0.0 can't remove pivot tables from xls files

I’m trying to remove a pivot table from an xls document in Cells 18.2.0.0 .net, but it constantly fails. It works fine for xlsx, but for xls files it throws a System.NullReferenceException whether I use PivotTables.Remove, PIvotTables.Clear, or PivotTables.RemoveAt.

@joeymilyli,

Please try our latest version/fix: Aspose.Cells for .NET v18.3.6:

I have tested using a simple template XLS file (that contains a PivotTable in it) with the following sample code, it works fine. The output file is fine tuned and PivotTable is removed in it:
e.g
Sample code:

 Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook("e:\\test2\\Pivot1.xls");
            Worksheet sheet = workbook.Worksheets[0];
            PivotTableCollection pivotTables = sheet.PivotTables;
            PivotTable pivotTable = pivotTables[0];
           
             //All three methods work fine
             //sheet.PivotTables.Clear();
             //sheet.PivotTables.RemoveAt(0);
            pivotTables.Remove(pivotTable);


            workbook.Save("e:\\test2\\out1.xls");

If you still find the issue with v18.3.6, kindly provide your template XLS file (containing the PivotTable), we will check it soon.

Hey Amjad,

I upgraded and it didn’t solve the issue. I have the excel I’m testing on attached in the zipDataSourceRemoved-2.zip (8.4 KB)
. Note that it has a non-accessible remote data source for the pivot table. While testing the new version, I found that the pivot table is not having the data source field set, as well as I see an error for SaveData,

  •   SaveData	'(new System.Linq.SystemCore_EnumerableDebugView<Aspose.Cells.Pivot.PivotTable>(sheet.PivotTables).Items[0]).SaveData' threw an exception of type 'System.NullReferenceException'	bool {System.NullReferenceException}
    

Thanks!

@joeymilyli,

Thanks for the template file.

Well, the underlying PivotTable in your template file has external connection references. That’s why you could not get its data source and cannot remove it. Anyways, I observed the issue as you mentioned by using the sample code (in my previous post) with your template file. I found an exception “Object reference not set to an instance of an object” and could not remove PivotTables from XLS file format. I have logged a ticket with an id “CELLSNET-46034” for your issue.

We will look into it and try to figure it out soon.

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

Ahhhhh alright. I wasn’t sure if external data connections would show up in there or not as the connection string.

Sounds good, thanks! Appreciate your help.

@joeymilyli,

This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-46034”). We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

Once the fix is available for public use, we will share the Download link here.

Keep in touch.

@joeymilyli,

Please try our latest Aspose.Cells for .NET v18.3.9.

Your issue should be fixed in it.

Let us know your feedback.

Hey Amjad,

It looks like that’s the .NET 2.0 version, I need the .NET 4.0 version.

Thanks!

@joeymilyli,

I am afraid, you got to wait for a few days or use this fix for the time being until our next official release of the product: Aspose.Cells for .NET v18.4 (on Nuget repos.) to be published (which is scheduled to be released around 20 April, 2018). The .NET 4.0 fix is not available at the moment.

Sounds good, thanks for the heads up!

The issues you have found earlier (filed as CELLSNET-46034) have been fixed in Aspose.Cells for .NET 18.4. Please also check the document/article for your reference: Install Aspose Cells through NuGet|Documentation

Hey Amjad,

We installed the new version today and it looks like everything’s working. Thanks a bunch!

@joeymilyli

Thanks for your feedback and using Aspose APIs.

It is good to know that your issue is resolved with the latest fix. Let us know if you encounter any other issue, we will be glad to look into it and help you further.