Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Range Operations / Access Areas in a Range
In This Topic
    Access Areas in a Range
    In This Topic

    In a large worksheet with non-contiguous selections, you can access specific areas in a multiple-area range by using the getArea method of the IAreas interface and getAreas method of the IRange interface.

    The methods of the IAreas interface and the IRange interface also represent the area count (number of areas) of the multiple-area range and all the selected ranges in the multiple area range.

    In order to access areas in a range, refer to the following example code.

    Java
    Copy Code
    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());