"Refers to" property of named range being changed... How can I make it stop!

I’ve got an Excel template with named ranges. I have code to export data to Excel and then import it back to the database after the user has entered whatever data they need to. I use named ranges for accessing specific cells for both the import and export procedures.

Upon viewing the resulting Excel file that was exported, the range names are gone. Upon further inspection, I’ve noticed that the “refers to” property of the range names changes from something like this:

=‘WORKSHEET-NAME-1’!$B$27

To something like this:

=‘C:\Documents and Settings\user\Local Settings\Temporary Internet Files\OLK7[EXCEL-FILE.xls]WORKSHEET-NAME-2’!$C$27

I have no idea what is happening, but the change only takes place for ranges where I change the value of the cell. If I leave it alone, then the range remains as it is.

Here’s some example code that I’m using for this:

currentRange = template.Worksheets.GetRangeByName(“RANGE_NAME”);
template.Worksheets[sheetIndex].Cells[currentRange.FirstRow, currentRange.FirstColumn].PutValue(myDecimalVariable);

Can anybody help me understand why this is happening and how to make it stop? I need the ranges to be left intact for the update to take place later. FYI, I’m using version 3.6.1.8 of Aspose Cells.

Hi,

Thanks for considering Aspose.

Well, I think it seams to me a bug in the older version of Aspose.Cells.

Please try the attached version.

If you still find some problem, kindly post your sample code and template file here.

Regards

Amjad Sahi

Aspose Nanjing Team

I resolved this issue, although I think there might be a bug in Aspose–at least the (admittedly old) version I’m using. Depending on certain circumstances, my code needs to remove worksheets. What I was originally doing was the following:

IF we need Worksheet A
Export data to Worksheet A (using ranges)
ELSE
Remove Worksheet A



IF we need Worksheet D

Export data to Worksheet D (using ranges)

ELSE

Remove Worksheet D

Now, I do the following:

IF we need Worksheet A

Export data to Worksheet A (using ranges)



IF we need Worksheet D

Export data to Worksheet D (using ranges)


IF we DO NOT need Worksheet A
Remove Worksheet A



IF we DO NOT need Worksheet D

Remove Worksheet D

Basically, deleting worksheets at the very end works, otherwise it doesn’t. This doesn’t seem right, so I’d say it’s a bug, but it might have already been fixed in subsequent versions.