Object reference not set to an instance of an object. Excel97


#1

When working with an Excel97 file, the same one that I e-mailed, I encountered this error:

Object reference not set to an instance of an object

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
c5.a(c4 A_0, y A_1, Worksheets A_2)
Aspose.Excel.Worksheets.a(String A_0, SaveType A_1, FileFormatType A_2, HttpResponse A_3)

[Exception: Access denied because you do not have enough permissions, or another user has the file open and locked.]
Aspose.Excel.Worksheets.a(String A_0, SaveType A_1, FileFormatType A_2, HttpResponse A_3)
Aspose.Excel.Excel.Save(String resultSpreadsheet, FileFormatType fileFormatType)


In this case, the file was not open or locked.


Here is the code:

//Init DB
DBInit();

//Export to Excel

string designerFile = “C:\InetPub\wwwroot\CTC.WebApp\ExtractUpdate\XLSheets\MassExtract.xls”;
excel.Open(designerFile);

this.dataTable1.Reset();
this.sqlCmd.CommandText =
@“SELECT *
FROM auto_upload_temp_t”;

this.sqlDa.Fill(this.dataTable1);

Worksheet sheet = excel.Worksheets[0];
sheet.Cells.ImportDataTable(this.dataTable1, false, 2, 1);

FileFormatType XlFileFormat = new FileFormatType();
XlFileFormat = FileFormatType.Excel97;

excel.Save(“Bob.xls”, XlFileFormat);

This is a just a modification of the code included in the sample.

Any thoughts on what the problem is?
Have you tried running the demo with the designer file saved in an Excel97 format?

Regards,
Michael Minadeo
IBM Global Services
Nissan Account


#2

Dear Michael,

Thanks for your consideration.

It doesn’t matter the Excel97 format.

When you use Save method to save the result file to disk and without assigning a directory,
the file will be saved to your default directory. In my machine, it’s “c:\winnt\system32”.
I guest your app is a web app, right? If so, web app has limited permission to access local directory. Maybe your default directory does not permit your web app to access it.

The solution can be one of the following:
* Save file to a directory your web app can write to
* Open the write permission of your default directory
* Write a winform app
* Use another override Save method


#3

Laurence,

Thanks again for your help.

I created and granted file access to a directory and it worked.

Now, I have a working demo, which I will present to management tomorrow.

Thanks again,
Michael Minadeo
IBM Global Services
Nissan Account


#4

Dear Michael,

Thank you too. We hope Aspose products can facilitate your work.