If I read the documentation correctly, calling Cells.getRanges() returns only the named ranges created through the Aspose API.
Couple of questions here:
- I’d like to be able to load the set of pre-existing ranges and then update one. Is that possible?
- Failing that, if I define a range that already exists, what is the result?
- David
Hi,
You can access the named ranges created manually using Ms-Excel using the following method.
workbook.getWorksheets().getNamedRanges()
As a workaround to update your existing range, you should create a new range and delete the old one.
Thanks for that info. However, I am not finding that to work with 7.0.1.1.
My code is:
Workbook book = new Workbook(“sample.xlsx”);
WorksheetCollection sheets = book.getWorksheets();
Range[] ranges = sheets.getNamedRanges();
I get null back, even though I have 5 named ranges in my xlsx file.
Hi,
Please attach your template Sample.xlsx file here, we will check your issue soon.
Thank you.
Please see attached. It’s actually called “SmallData.xlsx”.
Hi,
Thanks for your template file.
Your named ranges in your template file are defined Names (NameCollection), you should use the following sample code for your requirement:
Sample code:
Workbook book = new Workbook(“SmallData.xlsx”);
WorksheetCollection sheets = book.getWorksheets();
NameCollection ranges = sheets.getNames();
System.out.println(ranges.getCount()); //5 -OK
for(int i =0; i<ranges.getCount(); i++)
{
System.out.println(ranges.get(i).getText());
System.out.println(ranges.get(i).getRefersTo());
}
Thank you.