cost_eco_model_linker.handlers.excel_handlers¶
Classes¶
Manages a persistent Excel application instance and caches open workbooks. |
Functions¶
|
Open an Excel workbook. |
|
Close a workbook and optionally quit the Excel application. |
|
Reset workbook state. (Optimized: No longer re-opens file) |
Module Contents¶
- cost_eco_model_linker.handlers.excel_handlers.open_excel(fp, xlapp=None)¶
Open an Excel workbook.
- Parameters:
fp (str) – Path to the workbook file.
xlapp (Excel.Application, optional) – An existing Excel application instance to use. If None, a new isolated instance is created via DispatchEx. Pass an existing instance when opening multiple workbooks to avoid running several Excel processes simultaneously (which causes RPC_E_DISCONNECTED).
- Returns:
xlapp (Excel.Application)
wb (Workbook)
- cost_eco_model_linker.handlers.excel_handlers.close_excel(xlapp, wb, quit_app=True)¶
Close a workbook and optionally quit the Excel application.
- Parameters:
xlapp (Excel.Application)
wb (Workbook)
quit_app (bool) – If True (default), quit the Excel application after closing the workbook. Pass False when the application hosts other open workbooks that should remain alive.
- cost_eco_model_linker.handlers.excel_handlers.reset_workbook(xlapp, wb, fp)¶
Reset workbook state. (Optimized: No longer re-opens file)
- class cost_eco_model_linker.handlers.excel_handlers.WorkbookSession¶
Manages a persistent Excel application instance and caches open workbooks.
This class ensures that only one Excel process is created per worker and that workbooks are reused across evaluations, significantly reducing the overhead of DispatchEx and Workbooks.Open calls.
- xlapp = None¶
- workbooks¶
- seeded¶
- open_workbook(fp)¶
Open a workbook or return a cached instance.
- is_seeded(fp)¶
Check if a workbook has already been seeded with baseline factors.
- mark_seeded(fp)¶
Mark a workbook as seeded.
- cleanup()¶
Close all workbooks and quit the Excel application.