Free Support Forum - aspose.com

How to add named ranges to sheet and workbook without specifying range details?

Can I create a named range and add to sheet without using Range()? The demo I found has to specify the range to be referred, like below:

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

range = worksheet.getCells().createRange(“B4”, “G14”);
range.setName(“TestRange”);
format
workbook.save(“C:\output.xls”);


Is there a way for us to do sth like:
Name name = new name() //don’t what is the constructor signature
name.setRefersTo(…)
worksheet.addName(name)…

Is that possible? Please let me know, thank you.


Hi,

I think, may be you can try, see the following sample code with Aspose.Cells for Java API:
Sample code:

Workbook workbook = new Workbook();
Worksheet sheetRef = workbook.getWorksheets().get(0);
NameCollection names = workbook.getWorksheets().getNames();
String strName = "test";
Name name = names.get(names.add(strName));
name.setRefersTo("=Sheet1!$A$1:$B$3");
//Make it invisible.
name.setVisible(false);

workbook.save("3outnamerange.xlsx");



Thank you.

thank you, it works.

Hi,

Thanks for your posting and using Aspose.Cells.

We are pleased to know your issue is resolved. If you encounter any other problem, please feel free to post on our forums, we will be glad to help you further.