Implementing Non-Sequential Ranges

Normally, named ranges are rectangular with cells continuous and adjacent to each other. But sometimes, you may need to use a non-sequential cell range in which cells are not adjacent. Aspose.Cells supports creating a named range with non-adjacent cells. For this, the API provides the Name.RefersTo property.

Java code to implement non-sequential ranges

The code sample below shows how to create a named non-sequential range with Aspose.Cells for Java.

// 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(ImplementingNonSequentialRanges.class);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a Name for non sequenced range
int index = workbook.getWorksheets().getNames().add("NonSequencedRange");
Name name = workbook.getWorksheets().getNames().get(index);
// Creating a non sequence range of cells
name.setRefersTo("=Sheet1!$A$1:$B$3,Sheet1!$D$5:$E$6");
// Save the workbook
workbook.save(dataDir + "dest.xls");