We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save xlsx file with dotnet core version on linux using Aspose.Cells for .NET in C#

Hi,

I’m trialling the Dotnet Core C# version of Aspose for a project and plan to use it on a Linux machine.
I’ve written some code that opens an XLSX file that was created in Excel, does stuff with the contents, and then saves the file to a different folder. Everything is working fine when run on a Windows machine.

However, when I run the code on Linux I get a NullReferenceException when saving the file.

EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
   at Aspose.Cells.Workbook.Save(String fileName, SaveOptions saveOptions)

The method signature in the error has filename and saveoptions, but I’m calling the save method which takes just a filename wb.Save(fullSavePath);

If I change it to wb.Save(fullSavePath, SaveFormat.Xlsx.); I get the same error.

It saves a file, but it is corrupt.

Details, steps I’ve taken and other info that might help

  • Linux is Debian running in WSL.
  • Aspose.Cells is the current version, 19.7.0
  • I’ve installed TTF fonts in Linux, and set the Font Folder
  • I save charts from the worksheet and these are saving fine on linux
  • Using wb.Save(savePath + “test.xlsx”, SaveFormat.Xlsx); Throws the null exception and creates a corrupt file
  • Using wb.Save(savePath + “test.csv”, SaveFormat.CSV); works and saves the first sheet
  • Using wb.Save(savePath + “test.pdf”, SaveFormat.Pdf); works, and saves a PDF with all the sheets
  • Using wb.Save(savePath + “test.xlsb”, XlsbSaveOptions(SaveFormat.Xlsb)); Throws the null exception and creates a corrupt file
  • I’ve tried a stream, and that fails too.

Any help would be much appreciated.

@chris-7,
You may send us your runnable console application along with the template XLSX file, the program output file and expected output file created by Excel for our reference. We will use this application for testing this issue and provide our feedback after detailed analysis.

demo:

Workbook workbook = new Workbook(path);//path is file path, .xlsx file

workbook.Save(outPath); // outPath Is the export path , Extension is .xlsx

In linux docker, Object reference not set to an instance of an object. Wrong

aspose.cells v:20.10.0

@tianmin,
I have tested this scenario on Ubuntu 16.04 x64, in a docker container.
Here are my steps:

The docker I use is: microsoft/dotnet, install it first:
sudo docker pull microsoft/dotnet

Then I install libgdiplus:

apt-get update
apt-get install -y libgdiplus
cd /usr/lib && ln -s libgdiplus.so gdiplus.dll

And install libc6-dev:
apt-get install -y --no-install-recommends libc6-dev

After all these steps I saved one of my sample XLSX file as XLSB and got no error. Would you please check your scenario again by following these steps and share the feedback? If you still find some issue, please share your sample XLSX file for our reference.

HI!
I tried as you said, but it still doesn’t work.
This is my code:
dockerfile
dockerfile.png (8.9 KB)
Error message
excel报错.png (23.7 KB)
system message
linux.png (5.7 KB)

Ordinary excel .xlsx files can reproduce this problem.
Open the .xlsx file and save the .xlsx will cause an error

@tianmin,
I have tried the complete scenario again by creating a new Debian docker container and then installed .NET Core 5.0. Following sample code is executed which runs fine without any error. Could you please follow the steps below and try the scenario again:

Pull the image as follows:

docker pull debian

Start the Debian image and then execute the following commands in the container:

apt update && apt upgrade
apt-get install sudo
sudo apt install wget

wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

Sample code

Workbook workbook = new Workbook();
workbook.Save("output.xlsx");
workbook.Save("output.xlsb");
Console.WriteLine("Executed successfully");

test.zip (1.8 MB)

This is the test file
Workbook workbook = new Workbook(“test.xlsx”);
workbook.Save(“test1.xlsx”)

.net core 2.2 docker swarm

I will write a demo and try again several times to see what the reason is. My java program is also written in this way.
Still have to thank you

@tianmin,
Ok. Let us know your feedback as per your convenience.

HI!
Upgrade to .net core 3.1, the problem is solved, thank you

@tianmin,
Good to know that your issue is sorted out. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.