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:
filepath : None, int or str, 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_file : bool, optional

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

visible : None or bool, optional

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

silent : None or bool, optional

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

app : None, “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_addins : None or bool, optional

whether or not 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:   # doctest: +SKIP
...     wb['arr'] = arr.dump()
...     wb.save()

read array from an Excel file

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