C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Bug with named ranges when inserting a new sheet.

rated by 0 users
This post has 2 Replies | 0 Followers

Not Ranked
Posts 8
jerrade Posted: Mon, Oct 27 2008 6:53 PM
I have an Excel file that has named ranges on sheets 1, 2 & 3. These named ranges are used to populate dropdowns in sheet 0. I am reading in this file, and I want to programmatically insert a new sheet between sheets 0 and 1. I am able to do this via the C1XLBook.Sheets.Insert method. The problem is that this screws up my named ranges. After inserting the new sheet, the named ranges all reference the wrong sheet, as if they were based on the index of the sheet instead of the name. For example, I have a range on the 2nd sheet that is defined as 'My Sheet Name'!$A$2:$A$28. After inserting a new sheet at index 1 and saving the file, the range is now defined as 'Newly Inserted Sheet'!$A$2:$A$28, which of course is wrong. It's as if C1Excel is internally defining the named ranges by the index of the sheet instead of the name of the sheet. Everything is fine if I just insert the new sheets after all the existing sheets, but that isn't really what I want. And as far as I can tell, there's no method for reordering or changing the indices of the existing sheets.
Top 10 Contributor
Posts 1,090
Hello,
 
There is no support for named ranges at this time. Currently, Excel for .NET will read named ranges, which allows you to load
existing XLS files, modify some cells, and save the file back to disk preserving the named ranges. However, any modification
which requires the alteration of the named ranges are not supported. In your case the references to the sheet index changes
when a new sheet is inserted in between as a result we do not get the desired behavior.
 
Regards,
John Adams
 
<jerrade> wrote in message news:210540@10.0.1.98...
I have an Excel file that has named ranges on sheets 1, 2 & 3. These named ranges are used to populate dropdowns in sheet 0. I am reading in this file, and I want to programmatically insert a new sheet between sheets 0 and 1. I am able to do this via the C1XLBook.Sheets.Insert method. The problem is that this screws up my named ranges. After inserting the new sheet, the named ranges all reference the wrong sheet, as if they were based on the index of the sheet instead of the name. For example, I have a range on the 2nd sheet that is defined as 'My Sheet Name'!$A$2:$A$28. After inserting a new sheet at index 1 and saving the file, the range is now defined as 'Newly Inserted Sheet'!$A$2:$A$28, which of course is wrong. It's as if C1Excel is internally defining the named ranges by the index of the sheet instead of the name of the sheet. Everything is fine if I just insert the new sheets after all the existing sheets, but that isn't really what I want. And as far as I can tell, there's no method for reordering or changing the indices of the existing sheets.

http://helpcentral.componentone.com/cs/forums/p/77046/210540.aspx#210540

Not Ranked
Posts 8
jerrade replied on Mon, Nov 3 2008 6:51 PM
I don't understand why the sheet index has anything to do with the definition of the named range. The range is defined by the name of the sheet, not the index of the sheet (e.g. 'Sheet1'!$A$2:$A:28, not 1!$A$2:$A:28).
Page 1 of 1 (3 items) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.