[]
        
(Showing Draft Content)

Get Range and Range Area

Range or a range area refers to an array of cells that have been defined in a spreadsheet. While working with worksheets in a workbook, users can define multiple ranges and then further access those range areas separately to perform certain tasks like formatting of cells, merging of cells, insertion or deletion of cells within a range and other useful operations.

Refer to the following example code to see how you can define a range.

worksheet.getRange("H6:M7").setValue(1);
worksheet.getRange("J9:J10").merge();

// UsedRange is "H6:M10"
String usedrange = worksheet.getUsedRange().toString();
        
// Customize the used range 
usedRange.getInterior().setColor(Color.GetLightBlue());

Refer to the following example code to see how you can access the range area with a range.

IRange range = worksheet.getRange("A5:B7, C3, H5:N6");
        
// Access the first area - area1 is A5:B7.
IRange area1 = worksheet.getRange("A5:B7, C3, H5:N6").getAreas().getArea(0);
        
// Set interior color for the first area
area1.getInterior().setColor(Color.GetPink());
        
// Access the second area - area2 is C3.
IRange area2 = worksheet.getRange("A5:B7, C3, H5:N6").getAreas().getArea(1);
        
// Set interior color for the second area
area2.getInterior().setColor(Color.GetLightGreen());
        
// Access the third area - area3 is H5:N6.
IRange area3 = worksheet.getRange("A5:B7, C3, H5:N6").getAreas().getArea(2);
        
// Set interior color for the third area
area3.getInterior().setColor(Color.GetLightBlue());

See Also

Insert and Delete Rows and Columns

Work with Used Range