Создание Именованных Диапазонов с Глобальной Областью и Областью Листа

Ниже приведены примеры кода, показывающие, как создавать именованные диапазоны с областью книги и листа, используя класс Range.

Добавление Именованного Диапазона с Областью Книги

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddNamedRangeWithWorkbookScope.class);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get Worksheets collection
WorksheetCollection worksheets = workbook.getWorksheets();
// Accessing the first worksheet in the Excel file
Worksheet sheet = worksheets.get(0);
// Get worksheet Cells collection
Cells cells = sheet.getCells();
// Creating a workbook scope named range
Range namedRange = cells.createRange("A1", "C10");
namedRange.setName("workbookScope");
// Saving the modified Excel file in default format
workbook.save(dataDir + "output.xls");

Добавление Именованного Диапазона с Областью Листа

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddNamedRangeWithWorkbookScope.class);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get Worksheets collection
WorksheetCollection worksheets = workbook.getWorksheets();
// Accessing the first worksheet in the Excel file
Worksheet sheet = worksheets.get(0);
// Get worksheet Cells collection
Cells cells = sheet.getCells();
// Creating a workbook scope named range
Range namedRange = cells.createRange("A1", "C10");
namedRange.setName("Sheet1!local");
// Saving the modified Excel file in default format
workbook.save(dataDir + "output.xls");