sdkjs-plugins icon indicating copy to clipboard operation
sdkjs-plugins copied to clipboard

How to capture worksheet/cell change events?

Open lapnd opened this issue 4 years ago • 7 comments

Hi, Thank for the great project. As we know, Microsoft Excel and OfficeJs addins allow us to listen event when a worksheet and/or a cell changed. Is there anyway to listen these change events with OnlyOffice via plugin/macro? Thank you!

lapnd avatar Oct 09 '20 10:10 lapnd

@flaminestone Please, take a look

ShockwaveNN avatar Oct 09 '20 10:10 ShockwaveNN

Hello @lapd-viosoft.This feature is in development and has not been documented yet. What you mean with worksheet change event? In spreadsheet editor, every cell change (or double click in any cell) will trigger this event, and I do not know any case for using this.

flaminestone avatar Oct 09 '20 11:10 flaminestone

Hello @flaminestone In Excel, with VBA macro, we can watch the change of each cell and do further processing. For example:

Private Sub Worksheet_Change(ByVal Target As Excel.Range) 
    If Target.Column = 1 Then 
        ThisRow = Target.Row 
        If Target.Value > 100 Then 
            Range("B" & ThisRow).Interior.ColorIndex = 3 
        Else 
            Range("B" & ThisRow).Interior.ColorIndex = xlColorIndexNone 
        End If 
    End If 
End Sub

Or with OfficeJs addins, we can do like this


// Register change event
Excel.run(function (context) {
    var worksheet = context.workbook.worksheets.getItem("Sample");
    worksheet.onChanged.add(handleChange);

    return context.sync()
        .then(function () {
            console.log("Event handler successfully registered for onChanged event in the worksheet.");
        });
}).catch(errorHandlerFunction);


function handleChange(event)
{
    return Excel.run(function(context){
        return context.sync()
            .then(function() {
                console.log("Change type of event: " + event.changeType);
                console.log("Address of event: " + event.address);
                console.log("Source of event: " + event.source);
   
            });
    }).catch(errorHandlerFunction);
}

In spreadsheet editor, every cell change (or double click in any cell) will trigger this event, and I do not know any case for using this.

Can you tell me how to capture this cell change event in plugin/macro or any background thread of editor?

I have scenario like:

  • A plugin as system plugin, run in background and listen the change of every cell.
  • When a cell is changed (ex: user input some value, or paste new value, or select new value from drop down list) , the plugin captures new content of the cell, check the new content against some rules....and give warning to user if the new value is invalid.

Thank you.

lapnd avatar Oct 09 '20 11:10 lapnd

Can you tell me how to capture this cell change event in plugin/macro or any background thread of editor?

It is not available now, this functional is in development.

This is example for using some available events

flaminestone avatar Oct 09 '20 17:10 flaminestone

Hi @flaminestone Thank you very much for your information!

lapnd avatar Oct 10 '20 05:10 lapnd

Is it available for now?

gamead avatar Jul 19 '22 09:07 gamead

Hi @gamead ! These methods are still in development. Improvement request in our internal repository #58189

l8556 avatar Jul 19 '22 13:07 l8556