Two worksheet with the same name ranges

Hi:

I was using the following command without any problem to update the ranges in the spreadsheet:

range.Worksheet.Cells.ImportDataTable(table, false, range.FirstRow, range.FirstColumn, false, false);

But the workbook was updated and now I have a few worksheet with the same name ranges. How can update the ranges for specific worksheet?

Thanks

Hi,


Well, you might have two kinds of named ranges:
1) Global
2) Local (to the worksheet)

For example you might have two named ranges named “Test”. one is global and other is local. For your information, when you use: workbook.Worksheets.GetNamedRanges(); method, it returns both types of named ranges, but the local named range’s name would be accompanied by Sheet’s name.
e.g. See the sample code below:

Workbook workbook = new Workbook(“e:\test\Book1.xls”);
//Get All Named RangeCollection in the workbook
Range[] range = workbook.Worksheets.GetNamedRanges();

MessageBox.Show(range[0].Name); //Test
MessageBox.Show(range[1].Name);//Sheet2!Test

So you got to get named ranges into separate Range objects and then you may import data to the ranges accordingly.

Thank you.

Thanks, The sheet name resolved my problem.

Hi,


Good to know that your issue is resolved.

Thank you.