Reading and Setting Values in a Worksheet with Widgets

image_pdfimage_print

You can pass values to the widget and return values from the widget to the worksheet. Both methods are only possible if the Widget has the content type “HTML”.

Reading values

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:

Setting values

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.

image_pdfimage_print
Was this post helpful?
NoYes (+6 rating, 6 votes)
Loading...