Error while trying to save excel document

To my Xamarin Android application project in Visual studio 2019
I have added the Asget.Cell nuget package
Everything seems to work fine.

The book can be opened
I can access the content of the cells
Make changes to these and when everything is ready I have tried to save the changes the following error occurs:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

What am i doing wrong
Your nuget works perfectly in everything I’ve tried with others
And when everything seems to work wonders and I’m about to save that error

Please I need your help

Workbook wb = new Workbook ("/ storage / emulated / 0 / APP / WorkBook1.xlsx");
Worksheet ws = wb.Worksheets [0];

ws.Cells [“A1”]. Value = “HELLO!”;

wb.Save ("/ storage / emulated / 0 / APP / WorkBook2.xlsx", SaveFormat.Xlsx);

Please help
this is the line that marks me error
wb.Save ("/ storage / emulated / 0 / APP / WorkBook2.xlsx", SaveFormat.Xlsx);

@lokorroko,
Please share your sample file with us for our testing. We will reproduce the problem and provide our feedback after analysis.

1 Like

using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;

using Aspose.Cells;

namespace EditEXCELFile
{
[Activity(Label = “@string/app_name”, Theme = “@style/AppTheme”, MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
string Route = “/storage/emulated/0/EditEXCELFile/”; ///File route

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        ReadAndWriteExcelFile(Route + "EXCELFile1.xlsx"); //Execute method
    }
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    //********************************************************************************************************
    void ReadAndWriteExcelFile(string ExcelFile)
    {
        Workbook wb = new Workbook(ExcelFile); //Workbook
        Worksheet ws = wb.Worksheets[0]; //Worksheet

        ws.Cells["A1"].Value = "HELLO"; //Write value

        //ERROR
        wb.Save(Route + "EXCELFile2.xlsx", SaveFormat.Xlsx); //Save workbook
    }
    //********************************************************************************************************

Files Generated.png (74.4 KB)
Visual Studio Error.png (63.0 KB)

}

}

Can Help Me
Please!!!

@lokorroko,
Sure, we are trying to recreate the issue here. In the meanwhile could you please share your complete running solution with us for our analysis.

How?
When writing an answer, it is only allowed to share images .rar files that I can elaborate to share with you are not allowed

@lokorroko,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNETCORE-42 – Exception while saving Excel file in Xamarin Android application project in Visual studio 2019

Although we have reproduced the issue here but you may also share the sample runnable complete solution by uploading it to some public file sharing server like Google Drive, Dropbox etc. and then share the download link here.

@lokorroko,
We have investigated this issue more and would like to share that you should download the latest DLLs from the download section and use specific dll from the Xamarin.Android folder. It should work fine and exception should not be raised while saving the Excel file.

THANK YOU VERY MUCH PERFECTION WORKED

@lokorroko,
You are welcome.

@lokorroko,

We confirmed that the installation of Aspose.Cells for .NET (v19.10 or earlier) directly from nuget repos. will cause an error. We have released Aspose.Cells for .NET v19.11 version now and this problem has been fixed in it, so you may try it.