gemseo.disciplines.wrappers.xls_discipline module#
Excel based discipline.
- class XLSDiscipline(xls_file_path, name='', macro_name='execute', copy_xls_at_setstate=False, recreate_book_at_run=False)[source]#
Bases:
Discipline
Wraps an Excel workbook into a discipline.
Warning
As this wrapper relies on the xlwings library to handle macros and interprocess communication, it is only working under Windows and macOS.
Initialize xls file path and macro.
Inputs must be specified in the "Inputs" sheet, in the following format (A and B are the first two columns).
A
B
a
1
b
2
Where a is the name of the first input, and 1 is its default value b is the name of the second one, and 2 its default value.
There must be no empty lines between the inputs.
The number of rows is arbitrary, but they must be contiguous and start at line 1.
The same applies for the "Outputs" sheet (A and B are the first two columns).
A
B
c
3
Where c is the only output. They may be multiple.
If the file is a XLSM, a macro named "execute" must exist and will be called by the _run method before retrieving the outputs. The macro has no arguments, it takes its inputs in the Inputs sheet, and write the outputs to the "Outputs" sheet.
Alternatively, the user may provide a macro name to the constructor, or
None
if no macro shall be executed.- Parameters:
xls_file_path (Path | str) -- The path to the Excel file. If the file is a XLSM, a macro named "execute" must exist and will be called by the
_run()
method before retrieving the outputs.name (str) --
The name of the discipline. If empty, use the name of the class.
By default it is set to "".
macro_name (str | None) --
The name of the macro to be executed for a XLSM file. If
None
is provided, do not run a macro.By default it is set to "execute".
copy_xls_at_setstate (bool) --
If
True
, create a copy of the original Excel file for each of the pickled parallel processes. This option is required to be set toTrue
for parallelization in Windows platforms.By default it is set to False.
recreate_book_at_run (bool) --
Whether to rebuild the xls objects at each
_run
call.By default it is set to False.
- Raises:
ImportError -- If
xlwings
cannot be imported.