Spread.Services Documentation
Work with Used Range
Spread.Services Documentation > Developer's Guide > Customize User Interaction > Manage Worksheet > Range Operations > Work with Used Range

Used Range is a bounding rectangle of used cells that returns the IRange object of used range on the specified worksheet.

Spread.Services provides users with an option to work with the already used range of cells in a worksheet in the following two ways:

Work with worksheet's used range

To work with worksheet's used range, you need to first get the used range by using the UsedRange property of the IWorksheet interface. After you accomplish this, you can customize the used range using the properties of the IRange interface.

Refer to the following example code in order to get used range and customize it.

C#
Copy Code
worksheet.Range["H6:M7"].Value = 1;
worksheet.Range["J9:J10"].Merge();

//Used Range is "H6:M10" 
var usedrange = worksheet.UsedRange;
            
//Customize the used range
usedrange.HorizontalAlignment = HorizontalAlignment.Center;

Work with feature related used range

To work with feature related used range, you need to first get the feature related used range by using the GetUsedRange method of the IWorksheet interface. After you accomplish this, you can customize the feature related used range using the properties of the IRange interface.

Refer to the following example code to get feature related used range and customize it.

C#
Copy Code
IComment commentA1 = worksheet.Range["A1"].AddComment("Range A1's comment.");
IComment commentA2 = worksheet.Range["A2"].AddComment("Range A2's comment.");

//Comment used range is "A1:D5", contains comment shape plot area
IRange commentUsedRange = worksheet.GetUsedRange(UsedRangeType.Comment);
            
//Customize feature related used range
commentUsedRange.Interior.Color = Color.LightYellow;

After you get the used range of cells using any of the above methods, you can customize it as per your preferences. For instance- you can set the row height and column width; tweak the row hidden and column hidden settings; perform certain useful operations like group and merge; add value, formula and comment to the used range in your worksheet.

See Also