Q: GetWorksheetNames returns both Worksheets and Named Ranges, how to ignore Named Ranges?

115 views
Skip to first unread message

Aksel Stepsel

unread,
Jan 19, 2012, 6:38:08 AM1/19/12
to linqt...@googlegroups.com
First - thank you for the great project!

When an Excel file contains some Named Ranges in addition to Worksheets, it seems that GetWorksheetNames() returns both sheets and named ranges together. 
I'd like to ignore Named Ranges, also GetColumnNames doesn't work with Named Ranges (it appends $). 
Any suggestions?


For example the following code gives an error:
'[Named Range]$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

foreach (var sheetName in excel.GetWorksheetNames() )
{
foreach (var columnName in  excel.GetColumnNames(sheetName) )
{
listBox1.Items.Add(sheetName + "---" + columnName);
}
}

Paul Yoder

unread,
Jan 19, 2012, 9:05:00 AM1/19/12
to linqt...@googlegroups.com, andre...@gmail.com
Aksel,

Can you send me an example spreadsheet which is experiencing this issue.

I'll take a look at it and let you know what I find out.

Paul

Pascal

unread,
Feb 8, 2012, 10:52:33 AM2/8/12
to Linq To Excel
Hi Paul,

I'm experiencing the same issue as Aksel.
It only happens with .xlsx Format.

I can send you an exemple if you will...

Thank you for your help !

Regards

Pascal

On 19 Jan., 15:05, Paul Yoder <paulyo...@gmail.com> wrote:
> Aksel,
>
> Can you send me an example spreadsheet which is experiencing this issue.
>
> I'll take a look at it and let you know what I find out.
>
> Paul
>

Pascal

unread,
Feb 9, 2012, 4:39:02 AM2/9/12
to Linq To Excel
I was able to better identify the issue....
The error happens only if the named range has the workbook defined as
scope.
If the scope is limited to a given worksheet it won't produce any
exception...

Regards

Pascal

Paul Yoder

unread,
Feb 9, 2012, 11:11:53 AM2/9/12
to linqt...@googlegroups.com
Thanks Pascal for the example spreadsheet.

I can reproduce the issue as well.

I'm trying to update my unit tests to take this into consideration, but I can't figure out how to save the named ranges so that GetWorksheetNames() pick up the named ranges.

How did you save the named ranges in the spreadsheet?

Thanks,
Paul

Paul Yoder

unread,
Feb 15, 2012, 10:08:27 AM2/15/12
to linqt...@googlegroups.com
With the latest published version (1.6.1), GetWorksheetNames() doesn't return named ranges anymore.

Thanks for your help,

Paul

andre...@gmail.com

unread,
Feb 22, 2012, 6:49:34 AM2/22/12
to linqt...@googlegroups.com
Indeed! Thank you!
Reply all
Reply to author
Forward
0 new messages