Regarding Method getNamedRange()

Hi,

In my project we are using getNamedRange() returns NamedRange[] class. since we are upgrading from aspose 2.5.3 jar to aspose v7.0 above. If i use getNamedRange() it is returing Range[].


In worksheets class.

What is the similar method to use?

Thanks & Regards,
Saravanan Mani

Hi Saravanan,

Thanks for your posting and using Aspose.Cells.

There is no NamedRange class, so please use workbook.getWorksheets().getNamedRanges() method. You can also use workbook.getWorksheets().getNames() method for this purpose.

If you find any trouble, then please let us know your sample code snippet, we will look into it and let you know how to upgrade it to latest API.

Please also see this documentation article that enlist all the past and present APIs for your reference.

( How to Migrate to Aspose.Cells 7.0.0 or Higher|Documentation )

Hi Faiz,

NamedRange[] namedRanges = getWorkbook().getWorksheets().getSheet(sheetName).getNamedRanges(); this code need to be changed according to aspose v7.0 and above

Hi Saravanan,

Thanks for your posting and using Aspose.Cells.

You will have to use workbook.getWorksheets().getNames() instead. Please see the following sample code which illustrates the use of getNames() method. I have also attached the source Excel file used in this code and also shown the console output of the code for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.getWorksheets().get(0);


for (int i = 0; i < workbook.getWorksheets().getNames().getCount(); i++)

{

Name name = workbook.getWorksheets().getNames().get(i);


System.out.println(“Name: " + name.getText());

System.out.println(“Refers To: " + name.getRefersTo());


System.out.println(””);


Range[] ranges = name.getRanges();


}


Console Output:
Name: MyNamedRange1
Refers To: =Sheet1!$B$3:$C$8

Name: MyNamedRange2
Refers To: =Sheet1!$C$7:$F$11

Name: MyNamedRange3
Refers To: =Sheet1!$L$3:$N$14