ONLYOFFICE / sdkjs-plugins

The add-ons for ONLYOFFICE Document Server and ONLYOFFICE Desktop Editors.
https://www.onlyoffice.com
Apache License 2.0
136 stars 134 forks source link

How to capture worksheet/cell change events? #130

Open lapnd opened 4 years ago

lapnd commented 4 years ago

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!

ShockwaveNN commented 4 years ago

@flaminestone Please, take a look

flaminestone commented 4 years ago

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.

lapnd commented 4 years ago

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:

Thank you.

flaminestone commented 4 years ago

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

lapnd commented 4 years ago

Hi @flaminestone Thank you very much for your information!

gamead commented 2 years ago

Is it available for now?

l8556 commented 2 years ago

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