Buttons
Add buttons to your worksheets to call user code functions.
The function could export spreadsheet contents, send values from the sheet to a third-party library, communicate with an external system like a database, or even update the contents of the spreadsheet itself.
How to use buttons in Resolver One
It's easiest to demonstrate this feature with example code:
Add the following code to any usercode section:
b = Button("Greet") sheet = workbook["Sheet1"] sheet.B2 = bRecalculate.
A button labelled "Greet" appears in cell B2:
Add an event handler to make the button perform an action when clicked (new code is marked with '|'):
| def onClick(): | print "hello" b = Button("Greet") | b.Click += onClick sheet = workbook["Sheet1"] sheet.B2 = bRecalculate then click the button.
Clicking calls the function ''onClick()'', which prints a greeting in the output pane:
Click the button a couple of times more.
Subsequent clicks do not trigger recalculations; they simply call ''onClick()'':
More about button handler functions
Button handler functions like OnClick() can contain more than simple print statements. Typical uses include...
- Exporting results from a spreadsheet into another system, such as a database.
- A file export.
- Producing charts.
- Passing results into third-party libraries.
- Updating the contents of other cells by setting their Formula property:
def onClick(): workbook["Sheet1"].Cells.D3.Formula = 23 workbook["Sheet1"].Cells.D4.Formula = "=D4 * 2"
Comments
If you have comments, questions or suggestions about any of the Resolver One documentation, please post them to the Documentation Suggestions Forum.
