Exception when accessing WorkSheet.TabColor property

Hi,

I am comparing properties in an Excel document.

When I do

CheckEqual(worksheet1.TabColor, worksheet2.TabColor);
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.

Thanks,
Marie

Hi Marie,

Thanks for considering Aspose.

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.

Thank you.

Hi Amjad,

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.

Thank you,
Marie

Hi Marie,

Thanks, we will be waiting for your sample code with template excel file to check your issue.

Thanks for your workaround.

Hi Amjad,

I successfully created a problematic Excel file. The following code raises an exception every time.

global::Aspose.Cells.Workbook workbook = new global::Aspose.Cells.Workbook();
workbook.Open(“D:\excelFile.xls”);

global::Aspose.Cells.Worksheets wksheet = workbook.Worksheets;

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);
}
}
How can I send you the file in a private way?

Thanks,
Marie

Hi,

Thanks for your code.

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 :)

Thank you.

Hi Marie,

Thanks for sending the template file.

We will figure out your issue soon.

Thank you.

Hi Marie,

Please try this fix.

By the way ,which tool do you use to create this file?

Hi Warren and Amjad,

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.

Thanks a lot for the great support!

Regards,
Marie