libxlsxwriter
|
Excel allows you to group rows or columns so that they can be hidden or displayed with a single mouse click. This feature is referred to as Outlines and Grouping.
Outlines can reduce complex data down to a few salient sub-totals or summaries. For example the following is a worksheet with three outlines.
Rows 2 to 11 are grouped at level 1 and rows 2 to 5 and 7 to 10 are grouped at level 2. The lines at the left hand side are called "outline level" bars and the level is shown by the small numeral above the outline.
Clicking the minus sign on each of the level 2 outlines will collapse and hide the data as shown below.
The minus sign changes to a plus sign to indicate that the data in the outline is hidden. This shows the usefulness of outlines: with 2 mouse clicks we have reduced the amount of visual data down to 2 sub-totals and a master total.
Finally, clicking on the minus sign on the level 1 outline will collapse the remaining rows as follows:
Grouping in libxlsxwriter
is achieved by setting the outline level via the worksheet_set_row_opt()
and worksheet_set_column_opt()
worksheet functions:
Adjacent row or columns with the same outline level are grouped together into a single outline.
The options
parameter is a lxw_row_col_options struct. It has the following members:
-
'level' -
'collapsed'`Options can be set as follows, for example to set up an outline for rows:
Or an outline for columns:
The following example sets an outline level of 1 for rows 1 to 4 (zero-indexed) and columns B to G. The parameters height
, width
and cell_format
are assigned default values:
Rows and columns can be collapsed by setting the hidden
member for the hidden rows/columns and setting the collapsed
member for the row/column that has the collapsed ‘’+'` symbol:
Excel allows up to 7 outline levels. Therefore the level
parameter should be in the range 0 <= level <= 7
.
Some additional outline properties can be set via the worksheet_outline_settings()
worksheet function.