larray.open_excel

larray.open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, app=None, load_addins=None)[source]

Open an Excel workbook

Parameters
filepathNone, int, str or Path, optional

path to the Excel file. The file must exist if overwrite_file is False. Use None for a new blank workbook, -1 for the currently active workbook. Defaults to None.

overwrite_filebool, optional

whether to overwrite an existing file, if any. Defaults to False.

visibleNone or bool, optional

whether Excel should be visible. Defaults to False for files, True for new/active workbooks and to None (“unchanged”) for existing unsaved workbooks.

silentNone or bool, optional

whether to show dialog boxes for updating links or when some links cannot be updated. Defaults to False if visible, True otherwise.

appNone, “new”, “active”, “global” or xlwings.App, optional

use “new” for opening a new Excel instance, “active” for the last active instance (including ones opened by the user) and “global” to (re)use the same instance for all workbooks of a program. None is equivalent to “active” if filepath is -1, “new” if visible is True and “global” otherwise. Defaults to None.

The “global” instance is a specific Excel instance for all input from/output to Excel from within a single Python program (and should not interact with instances manually opened by the user or another program).

load_addinsNone or bool, optional

whether to load Excel addins. Defaults to True if visible and app == “new”, False otherwise.

Returns
Excel workbook.

Examples

>>> arr = ndtest((3, 3))
>>> arr
a\b  b0  b1  b2
 a0   0   1   2
 a1   3   4   5
 a2   6   7   8

create a new Excel file and save an array

>>> # to create a new Excel file, argument overwrite_file must be set to True
>>> with open_excel('excel_file.xlsx', overwrite_file=True) as wb:   
...     wb['arr'] = arr.dump()
...     wb.save()

read array from an Excel file

>>> with open_excel('excel_file.xlsx') as wb:    
...     arr2 = wb['arr'].load()
>>> arr2    
a\b  b0  b1  b2
 a0   0   1   2
 a1   3   4   5
 a2   6   7   8