Skip to content

Commit

Permalink
added default vmerge (without args)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Sep 16, 2022
1 parent 882c976 commit fc573e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Binary file modified docs/images/vmerge.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions docs/reports.rst
Expand Up @@ -312,14 +312,18 @@ Merge cells vertically for adjacent cells with the same value --- can be used to

.. figure:: images/vmerge.png

The screenshot makes use of :ref:`Frames <Frames>`.
Note that the screenshot uses 4 :ref:`Frames <Frames>` and the text is centered/vertically aligned in the template.


Syntax::
Syntax (arguments are optional)::

{{ df | vmerge(col_index1, col_index2, ...) }}

Example: Hierarchical mode: Merge cells vertically in the first column (indices are zero-based) and merge cells in the next column to stay within the merged cells of the previous column ::
Example (default): Hierarchical mode across all columns --- this is helpful if the number of columns is dynamic. In hierarchical mode, cells are merged vertically in the first column (indices are zero-based) and cells in the next columns are merged only within the merged cells of the previous column::

{{ df | vmerge }}

Example: Hierarchical mode across the specified columns only::

{{ df | vmerge(0, 1) }}

Expand Down
8 changes: 7 additions & 1 deletion xlwings/pro/reports/filters.py
Expand Up @@ -231,10 +231,16 @@ def vmerge(df, filter_args, top_left_cell, header):
To merge columns independently, the filter can be used like this:
vmerge(0) | vmerge(1)
vmerge without args merges hierarchically over all columns
"""
if df.empty:
return []
cols = [arg.as_const() for arg in filter_args]
if not filter_args:
# Default merges hierarchically over all columns
cols = list(range(len(df.columns)))
else:
cols = [arg.as_const() for arg in filter_args]

merged_cells_count_all = []
for ix, col in enumerate(cols):
Expand Down

0 comments on commit fc573e8

Please sign in to comment.