UniverSpreadsheetListener
Univer Listener. A listener gets automatically the value of one cell every time its value has changed.
public class UniverSpreadsheetListener : IUniverSpreadsheetListener
Remarks
This class maintains a set of listeners for cell changes in Univer spreadsheets. It allows adding, removing, and invoking listeners through JavaScript interop.
Properties
| Property | Type | Description |
|---|---|---|
| Listeners | Dictionary<UniverSpreadsheetListenerData, Action<object>> | All active Listeners |
Constructor
public UniverSpreadsheetListener(IUniverJsInterop univerJS)
| Parameter | Type | Description |
|---|---|---|
| univerJS | IUniverJsInterop | Univer’s Interop to access Univer |
Methods
InitializeListenersAsync
void InitializeListenersAsync()
Initializes the listener dictionary and sets up the JSInterop reference.
AddListenerAsync
void AddListenerAsync(UniverSpreadsheetListenerData data, Action<object> _event)
Adds a new listener to the dictionary and binds it via JSInterop.
| Parameter | Type | Description |
|---|---|---|
| data | UniverSpreadsheetListenerData | Data to locate the listener in the workbook |
| _event | Action<object> | Callback that triggers when the cell value changes |
RemoveListenerAsync
void RemoveListenerAsync(UniverSpreadsheetListenerData data)
Removes a listener both from JSInterop and the local dictionary.
| Parameter | Type | Description |
|---|---|---|
| data | UniverSpreadsheetListenerData | Listener to remove |
GetListeners
UniverSpreadsheetListenerData[] GetListeners()
Returns all currently active listeners.
Returns
UniverSpreadsheetListenerData[] — Array of keys representing active listeners
OnDataChanged
void OnDataChanged(UniverSpreadsheetListenerData data, object value)
JSInvokable method that triggers the appropriate callback when a cell value is updated via JS.
| Parameter | Type | Description |
|---|---|---|
| data | UniverSpreadsheetListenerData | The listener’s identifier |
| value | object | The new value from the cell |