Free Support Forum - aspose.com

Workbook.save method error

Hello There:

We are planing to buy the Aspose.cells licence for a new and important project, sale's related on wich Aspose could be essential. But as we started building our try out project to see if aspose can be the solution we are encountering some problem when we publish the project to our hosting.

This is the code where we are encountering the error message:

workbook workbook = new Workbook();
foreach (DataTable dt in dsDatos.Tables)
{
Worksheet ws = workbook.Worksheets.Add(dt.TableName);
ws.PageSetup.FitToPagesWide = 1;
ws.Cells.ImportDataTable(dt, true, "A1");
}
workbook.Save(This.Response, fichero, ContentDisposition.Inline, new PdfSaveOptions(SaveFormat.Pdf));

Error Message we are getting:
System.NullReferenceException: Object reference not set to an instance of an object. at ˆŸ.‚™.Š(String , Single , FontStyle ) at Š..ˆ(String , Font , Double ) at ’’.„.‡™(Graphics , Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions ) at ’’.„.AutoFitRow(Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions ) at Aspose.Cells.Worksheet.AutoFitRow(Int32 rowIndex) at ’’.€.™ˆ(Worksheet ) at Aspose.Cells.WorksheetCollection.™ˆ() at †“.‹“..ctor(Workbook ) at Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions) at Aspose.Cells.Workbook.Save(HttpResponse response, String fileName, ContentDisposition contentDisposition, SaveOptions saveOptions) at ParteHora.export.cmdExportar_Click(Object sender, EventArgs e)System.NullReferenceException: Object reference not set to an instance of an object. at ˆŸ.‚™.Š(String , Single , FontStyle ) at Š..ˆ(String , Font , Double ) at ’’.„.‡™(Graphics , Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions ) at ’’.„.AutoFitRow(Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions ) at Aspose.Cells.Worksheet.AutoFitRow(Int32 rowIndex) at ’’.€.™ˆ(Worksheet ) at Aspose.Cells.WorksheetCollection.™ˆ() at †“.‹“..ctor(Workbook ) at Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions) at Aspose.Cells.Workbook.Save(HttpResponse response, String fileName, ContentDisposition contentDisposition, SaveOptions saveOptions) at ParteHora.export.cmdExportar_Click(Object sender, EventArgs e)

Any of the save constructors will function on the server, while debuggin in the local machine it works just fine.

P.S. We are totally able to read, modify the aspose workbook from stream or physical file, pretty well, the only problem have emerged when trying to save. We've already checked permission for writing on the server, and save file through a Fileupload asp.net component and it worked good. It's not about writing in the server directories.

Please help us with this asap, as we need to decide if aspose is the right solution to our project.

The web server for the hosting is runing .net 3.5 framework, and it's windows based.

Best regards,

Youssef

Correction:

Any of the save constructors will not work on the server, it will on the local development machine.

Thanks

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Your code looks fine and there seems to be no problem.

Please also download and try the latest version:
Aspose.Cells
for .NET v7.3.2.4

and see if it resolves your issue.


Please provide us your sample project with your sample datatable replicating this issue with the above version.

We will look into it and help you asap.

Please also let us know if you are using Regular .NET Framework or Client Profile .NET Framework, because there are two separate dlls for these frameworks.

The above dll link is meant for Regular .NET Framework only.

ymekin:

Correction:

Any of the save constructors will not work on the server, it will on the local development machine.

Thanks

Hi,

From your statement, it seems, this is the issue related to your .NET framework version. There could be two possible things.

  • You have Regular .NET Framework, but you are using Client Profile Aspose.Cells DLL.
  • You have Client Profile .NET Framework installed on your machine, but you are using Regular Aspose.Cells DLL

Depending on your .NET Framework, please use the correct DLL.

You can find both of these dlls from the MSI installer of the official release: Aspose.Cells for .NET 7.3.2

Please see the below image for your more help.

Hello Shakeell:

Thanks in advance for your fast and fine response.
I just checked and I have regular 3.5 framework as far as I know, and I use the regular aspose 2.0 dll. That’s one of the things I tried this afternoon, to change to the client dll to see if I was using the correct one, but I saw this one doesn’t have the save(this.response constructor for the save method.
Can you please tell me, where to check(I’m using visual studio 2010 professional) if I’m using the client framework, I checked project properties and I don´t see the client framework.
Thanks a lot for your helps.
Regards
  • You have Regular .NET Framework, but you are using Client Profile Aspose.Cells DLL.

P.S

Please, take in consideration, this code works just fine in my local development machine when I’m debugging, but when I publish this to a production server, is when I start receiving this error.

Hi,

Thanks for your feedback.

Could you please remove the following line and see if your code works fine on your other machine.

ws.PageSetup.FitToPagesWide = 1;

Please also close the Response stream if it makes any difference.

C#


workbook workbook = new Workbook();

foreach (DataTable dt in dsDatos.Tables)

{

Worksheet ws = workbook.Worksheets.Add(dt.TableName);

ws.Cells.ImportDataTable(dt, true, “A1”);

}

workbook.Save(HttpContext.Current.Response, fichero, ContentDisposition.Inline, new PdfSaveOptions(SaveFormat.Pdf));


HttpContext.Current.Response.End();