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

Free Support Forum - aspose.com

Object reference not set to an instance of an object when copying worksheet

When I try to copy the "report" sheet from the attached template to a new workbook, I receive the following error.

System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Cells.ಐ.ন(ಐ ঩)
at Aspose.Cells.Cell.ు(Cell ঩)
at Aspose.Cells.Cells.ন(Cells ঩)
at Aspose.Cells.Worksheet.ন(Worksheet ୿, Boolean ஁)
at Aspose.Cells.Worksheet.Copy(Worksheet sourceSheet)
at WindowsApplication2.Form1.Form1_Load(Object sender, EventArgs e) in C:\Documents and Settings\jrozier\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\Form1.vb:line 18


Dim x As New Aspose.Cells.Workbook
Dim y As New Aspose.Cells.Workbook



This happens in, but not

Actually, the first file posted fails in both versions, but the file I’m posting now only fails in


Thanks for the template file,

After an initial test, we found the problem. We will figure it out soon.

Thank you.

Is there something about the template that I might be able to change to get it to work in the meantime?


Well, currently there is a problem with Copy method, so you should not use it for the time being till it is resolved. I think you may try: open your template workbook (having your required sheets), save it as to create a new one.

Thank you.

Unfortunately, I can't use that work-around. I need multiple copies of the sheet being copied and I need VBA in the resulting report that I'm pulling from another template. Worksheet.Copy works with some of my templates. I've attached one. Is there something specific about the templates that caused the failure that I can modify? I'm supposed to deploy to production this Friday and need something soon.


Hi Josh,

Thanks for your patience. Sorry for our delay.

Please try this fix.

In this fix,we use Cell.GetStyle and SetStyle method replace the property of Cell.Style. The two methods will save more memory usage than cell.Style property. The feature caused that we could not response quickly.

If you want to set style of the cell, please change your codes as :

//Getting the style of the cell.

Style style = cell.GetStyle();

//Setting the property of the style.


//Setting the style of the cell



This fixes the issue stated above, but the Cells.Rows property is missing and the Row type is missing. Also, Worksheets.GetNamedRanges fails with an Index out of range error.

Josh Rozier

Hi Josh,

Thanks for considering Aspose.

We did change some internal structure of the Aspose.Cells component related formattings. We have to sacrifice this for some optimization and performance measures and did eliminate / modify some APIs which we have now in more enhanced shape. You may utilize some newer APIs of Cells class instead e.g.., ApplyRowStyle() etc. We will soon publish an article for the users to list the deprecated apis and the newer ones for the replacement.

For Worksheets.GetNamedRanges() method, we don't find the problem as I tested, Could you give us some sample code with template file to re-produce the issue. We will check it soon.

Thank you.


The article about the APIs would be great.

I'm attaching the file that fails when calling the GetNamedRanges() method.

Here's the code:

Dim x As New Aspose.Cells.Workbook


Dim arRg() As Range
arRg = x.Worksheets.GetNamedRanges


Hi Josh,

Thanks for the template file.

After an initial test, we did find an issue retrieving named ranges in your template file. We will further check to figure it out soon.

Thanks for being patient!