We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Read Constant Named Range in Aspose.cells for java

Hi,


I have tried a lot to read the constant named range defined in xlsx workbook from Asopse.cells 8.1.0 version, but it is always returning null.

For example:
In myworkbook.xlsx has the following named range defined with workbook scope and value of the named range is "tiger"
let say name of the named range is “testRange” which will hold the value tiger.

In java
worksheets = workbook.getWorksheets();

Range range = worksheets.getRangeByName(“testRange”);

output: range is null always?

also tried using other methods of worksheets getNamedRanges(), getNames(), but no use,always return null.

Please suggest if ASPOSE support this feature.


thanks
Esha

Hi,


Could you provide us your template file here, we will check it soon.

By the way, you may also try to use Name Collection. you may try to use Name/NameCollection APIs if it works for your needs:
e.g
Sample code:

//Get the named range
Name name = workbook.getWorksheets().getNames().get(“testRange”);
//get your desired range’s criteria in string
System.out.println(name.getRefersTo());

Thank you.

Thanks Amjad for your reply.


I have already tried the Name and NameCollection, it did not work. Not sure if you know that in excel, we can create a named range without referring to it any cell in the workbook, instead it just holds a constant value.

I will attach the workbook that I am using with constant named range to my original post.

thanks


Attache the workbook that has only constant named range which does not refer to any cell.

Hi Joe,

Thanks for your posting and using Aspose.Cells.

Please download and use the latest version: Aspose.Cells
for Java v8.2.1.4
it works fine. We tested this issue with the following code and it returned all the named range.

I have also shown you the console output of this code and also attached the source Excel file used in this code for your reference.

Java


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


Workbook workbook = new Workbook(filePath);


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

{

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


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

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


System.out.println(”-----------------------”);


}

Console Output:
Name: Sheet1!Another
RefersTo: =“t1,t2,t3”
-----------------------
Name: Check
RefersTo: =“Myvalue”
-----------------------
Name: Sheet2!Keee1
RefersTo: =Sheet1!$E$14
-----------------------
Name: testRange
RefersTo: =""“tiger”""
-----------------------
Name: Sheet3!UIO
RefersTo: =Sheet1!$E$14
-----------------------
Name: UIOP1
RefersTo: =Sheet1!$E$14
-----------------------
Name: vbn
RefersTo: =Sheet1!$E$14
-----------------------

Thanks ,

It means that previous versions are not supporting this feature?




Hi Joe,

Thanks for your posting and using Aspose.Cells.

I have tested this code found in the above post with the version 8.1.0.0 and it worked fine and gave the same result as shown in the above post.