This module provides a base class that can be used to perform EMA on Excel models. It relies on win32com
BaseExcelModel(name, wd=None, model_file=None, default_sheet=None, pointers=None)¶
Base class for connecting the EMA workbench to models in Excel. To automate this connection as much as possible. This implementation relies on naming cells in Excel. These names can then be used here as names for the uncertainties and the outcomes. See e.g. this site for details on naming cells and sets of cells.
The provided implementation here does work with
- name (str) – name of the modelInterface. The name should contain only alpha-numerical characters.
- wd (str) – working_directory for the model.
- model_file (str) – the name of the model file
- default_sheet (str, optional) – The name of the default workbook sheet. Cells and ranges are assumed to be on this sheet unless they are explicitly identified as being on other sheets. If no default_sheet is set, all references must explicitly name the sheet they refer to.
- pointers (dict, optional) – A dictionary to allow pointing named inputs or outputs to excel workbook locations. This can allow keeping the workbench model neat with legible names, while not demanding that workbook cells be named. Each (key, value) pair in pointers maps a key that gives the (concise) name of an input or output for the model to an identfier for that input or output in the Excel workbook, in ‘sheetName!A1’ or ‘sheetName!NamedCell’ notation (the sheet name is optional if the cell or range exists in the default sheet).
cleaning up prior to finishing performing experiments. This will close the workbook and close Excel
Name of the sheet on which one want to set values
get a named worksheet, or the default worksheet if set
Parameters: sheetname (str, optional) –
get the names of all the workbook’s worksheets
extract a value from a cell of the excel workbook
Parameters: name (str) – A cell reference in the usual Excel manner. This can be a named cell or in ‘A1’ type column-row notation. To specify a worksheet, use ‘sheetName!A1’ or ‘sheetName!NamedCell’ notation. If no sheet name is given, the default sheet (if one is set) is assumed. If no default sheet is set, an exception will be raised. Returns: Return type: Number or str
Method called to initialize the model.
- policy (dict) – policy to be run.
- kwargs (dict) – keyword arguments to be used by model_init. This gives users to the ability to pass any additional arguments.
Method for running an instantiated model structures. This implementation assumes that the names of the uncertainties correspond to the name of the cells in Excel. See e.g. this site for details or use Google and search on ‘named range’. One of the requirements on the names is that they cannot contains spaces.
For the extraction of results, the same approach is used. That is, this implementation assumes that the name of a
Outcomeinstance corresponds to the name of a cell, or set of cells.
Parameters: experiment (Experiment instance) – Returns: Return type: dict
inject a value into a cell of the excel workbook
- name (str) – A cell reference in the usual Excel manner. This can be a named cell or in ‘A1’ type column-row notation. To specify a worksheet, use ‘sheetName!A1’ or ‘sheetName!NamedCell’ notation. If no sheet name is given, the default sheet (if one is set) is assumed. If no default sheet is set, an exception will be raised.
- value (Number or str) – The value that will be injected.
Reference to the workbook. This attribute is None until model_init has been invoked.
Reference to the Excel application. This attribute is None until model_init has been invoked.
ExcelModel(name, wd=None, model_file=None, default_sheet=None, pointers=None)¶