Example: Name

This example adds a named range first, then removes it.

import com.ibm.symphony.javaapi.Application;
import com.ibm.symphony.javaapi.spreadsheet.Name;
import com.ibm.symphony.javaapi.spreadsheet.Names;
import com.ibm.symphony.javaapi.spreadsheet.Spreadsheet;
import com.ibm.symphony.javaapi.spreadsheet.Spreadsheets;

public class NameExample {

	public void example() {
		try {
			Application application = Application.getInstance();
			Spreadsheets spreadsheets = application.getSpreadsheets();
			Spreadsheet spreadsheet = spreadsheets.openSpreadsheet(
					"D:\\test.ods", true);
			Names names = spreadsheet.getNames();
			System.out.println(names.getCount());
			Name name = names.add("FirstNames", "$A.$A$1:$E$11", true);
			System.out.println(names.getCount());
			name = names.item("FirstNames");
			System.out.println(name.getRefersTo());
			System.out.println(name.getRefersToRange().getName());
			name.remove();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Related information

Name

Names property in Spreadsheet