SpreadJS 14
Features / Cells / Cell Range
In This Topic
    Cell Range
    In This Topic

    SpreadJS provides an easy way to access a range of cells in the sheet area. You can conveniently get the range information in the sheet using the getRange method.

    It allows users to conveniently choose which way to obtain range information in the sheet area according to their requirements, either through row and column index, or via range address. This is covered in the following two sections.

    Get Range by Row and Column Index

    You can get a series of cells in a range of sheet area using the getRange(row, col, rowCount, colCount, sheetArea) method. This method uses parameter such as row index, column index, row count of range, and column count. In this manner, you get a range of cells by row index and column index in the specified sheet area.

    The following image displays an example of getting cell range by row and column index.

    Get Range by row and column info

    The following code snippet depicts how to use getRange method to specify range B2:F6 with row and column index.

    Javascript
    Copy Code
    <script>
        $(document).ready(function () {
            // Initializing Spread
            var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
            // Get the activesheet
            var sheet = spread.getActiveSheet();
    
            // Get range by row and column info
            var range = sheet.getRange(1, 1, 5, 5, GC.Spread.Sheets.SheetArea.viewport);
            range.text("Text");
        });
    </script>
    

    Get Range by Range Address

    You can also get a range of cells in the sheet area using the getRange(address, sheetArea) method. This method gets a range of cells in the specified sheet area using range address string.

    The following image displays an example of getting cell range by range address.

    Get Range by range address

    The following code snippet depicts how to use getRange method to specify range A1:E5 with range address string.

    Javascript
    Copy Code
    <script>
        $(document).ready(function () {
            // Initializing Spread
            var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
            // Get the activesheet
            var sheet = spread.getActiveSheet();
    
            // Get range by range address
            var range = sheet.getRange('A1:E5', GC.Spread.Sheets.SheetArea.viewport);
            range.text("Text");
        });
    </script>