Selection text in changing event

Posted by: m.holland-moritz on 8 December 2022, 8:31 am EST

  • Posted 8 December 2022, 8:31 am EST

    Hello everyone.

    I am using the build in Event SelectionChanging, which returns the current selection, but it only returns it as an object, with row, rowcount, col and colcount.

    I could map that now and create the exact String out of it, but i hope there is a better way you already provide.

    I am using it as follows:

    spread.bind(GC.Spread.Sheets.Events.SelectionChanging, function (sender, args) {
            console.log(args);
    });

    What i want is the selection string which shows like this “A2:C8”

    Is that possible?

    Best Regards

    Maik

  • Posted 9 December 2022, 12:46 am EST

    Hi Maik,

    You could use the evaluateFormula method and the ADDRESS formula to calculate the address of a cell corresponding to its row and column.

    Please refer to the following code snippet for reference:

        spread.bind(GC.Spread.Sheets.Events.SelectionChanging, function (sender, args) {
            if (args.newSelections.length === 1 && args.newSelections[0].rowCount === 1 && args.newSelections[0].colCount === 1) {
                let result = GC.Spread.Sheets.CalcEngine.evaluateFormula(args.sheet,
                    `ADDRESS(${args.newSelections[0].row + 1},${args.newSelections[0].col + 1},4)`, 0, 0);
                addressEl.innerHTML = result;
            } else {
                var result1 = GC.Spread.Sheets.CalcEngine.evaluateFormula(args.sheet,
                    `ADDRESS(${args.newSelections[0].row + 1},${args.newSelections[0].col + 1},4)`, 0, 0);
                var result2 = GC.Spread.Sheets.CalcEngine.evaluateFormula(args.sheet,
                    `ADDRESS(${args.newSelections[0].row + args.newSelections[0].rowCount},${args.newSelections[0].col + args.newSelections[0].colCount},4)`, 0, 0);
                addressEl.innerHTML = `${result1}:${result2}`
            }
        })

    Sample: https://jscodemine.grapecity.com/share/x-pS3GoCwUWdKNqzJYtczQ/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fsrc%2Fapp.js"%2C"%2Fpackage.json"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    API References:

    evaluateFormula method: https://www.grapecity.com/spreadjs/api/modules/GC.Spread.Sheets.CalcEngine#evaluateformula

    ADDRESS function: https://www.grapecity.com/spreadjs/docs/formulareference/FormulaFunctions/lookup-reference-functions/ADDRESS

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels