I get the following error on both TabColor properties:
‘worksheetX.TabColor’ threw an exception of type 'System.NullReferenceException’
The exception is:
System.NullReferenceException: Object reference not set to an instance of an object. at Aspose.Cells.Record.PaletteRecord.GetColor(Int32 index) at Aspose.Cells.Worksheet.get_TabColor()
I doesn’t really matter to me if both properties throw an exception, as long as they are the same. However, I am wondering if this is my fault? Is there something I set-up wrong? To get there, I open an Excel file using workbook.open(stream) and then workbook.Worksheets[i]. The problem doesn’t occur for every worksheet contained within my workbook.
Well, we don't find the issue you have mentioned. Which version of Aspose.Cells you are using. Could you try our latest version (4.5). If you still find the problem, kindly post your template excel file with sample code to reproduce the issue, we will check it soon.
I updated the version to 4.5. I was using version 4.4.1.0. The problem is still there. It seems to occur for hidden sheets. When I have the time, I will try to create a sample code and excel file to reproduce the problem.
for (int i = 0; i < wksheet.Count; i++) { try { Color color = wksheet[i].TabColor; Console.WriteLine("worksheet " + i + " color: " + color.ToString()); } catch (System.Exception e) { Console.WriteLine(“Failed to get worksheeet " + i + " color.”); Console.WriteLine(e); } }
To send your template file you may chosse any option:
1). You may click on the Contact button and then click Send Amjad Sahi an email. Now attach the file with your subject and message and that's it.
2) You can mark this thread as Private setting "Keep this post private" and attach your files here without any problem. Now only Aspose staff and you can see your attachments :)
It works great. I believe the file sent to you has been created directly in Excel. It is then used as a template to create another Excel file using Aspose. We also validate its content using Aspose in our unit tests.