Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/changes/version_0_33.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Miscellaneous improvements
* implemented the :py:obj:`Range.add_plot()` method that allows to create graphs when using
`open_excel()` (closes :issue:`900`).

* implemented the :py:obj:`Range.add_table()` method.

Fixes
^^^^^

Expand Down
13 changes: 6 additions & 7 deletions larray/inout/xw_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ def load(self, header=True, convert_float=True, nb_axes=None, index_col=None, fi
else:
return Array(list_data)

def add_table(self, array: Array):
self.xw_range.value = array.dump()

def add_plot(self, data_source: str, width: int=427, height: int=230, title: str=None, template: str=None,
min_y: Union[int, float]=None, max_y: Union[int, float]=None,
xticks_spacing: Union[int, float]=None, customize_func: Callable=None,
Expand Down Expand Up @@ -806,19 +809,15 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a

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

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['arr']['A6'].add_plot('A1', title='simple graph')
... wb['arr']['A6'].add_table()
... wb['arr']['G1'].add_plot('A1', title='simple graph')
... wb.save()

read array from an Excel file
Expand Down
10 changes: 10 additions & 0 deletions larray/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ def test_repr(self):
1 3 4 5"""


@needs_xlwings
def test_add_table():
arr = ndtest((3, 3))

with open_excel(filepath='test_add_table.xlsx', visible=False, overwrite_file=True) as wb:
sheet = wb[0]
sheet["B2"].add_table(arr)
wb.save()


@needs_xlwings
def test_add_plot():
demo = load_example_data('demography_eurostat')
Expand Down