Reading and Setting Values in a Worksheet with Widgets

You can pass values from the worksheet to the widget and vice versa, but only for widgets with HTML content type.

Passing values from the worksheet to the widget

Values are passed to the widget in a pre-defined JavaScript variable array called params. Of course, you first need to define a data source in the widget properties. For example, if your source is the range A1:B2, the cell value from A1 would be accessible in the widget code with the expression params[0], while B1 would be params[1], and so on.

The following example is a JavaScript function that reads this variable and assigns the values to an object in the HTML part of the code, making it visible. This function __exec is executed by default every time source values change, so the widget refreshes the data.


Passing values from the widget to the worksheet

To return a value to the worksheet (or more specifically, to the target defined in the widget properties), the pre-defined JavaScript function __set() is used. As its single parameter, __set expects the value to return.

The following example code returns the current value of a text input field to the worksheet once the user clicks the button:


Of course, the target of the widget must be specified to pass the result back to the spreadsheet.