Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Outer group removes multiple inner groups

I want to have multiple groups on outline level 1 and over these groups I want to have 1 group which is on outline level 2, like that:

Groups Example

But with my code the outer group always "overwrites" or removes the inner groups:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Groups_not_working

Code

import openpyxl

wb = openpyxl.load_workbook("Planung.xlsx")
ws = wb["Zeitplan"]
ws.sheet_properties.outlinePr.summaryBelow = False

ws.row_dimensions.group(9, 11, outline_level=1)
ws.row_dimensions.group(13, 13, outline_level=1)
ws.row_dimensions.group(16, 17, outline_level=1)
ws.row_dimensions.group(7, 17, outline_level=2)

wb.save('test.xlsx')

Reproduction steps

  • Create file called Planung.xlsx
  • Create sheet called Zeitplan in the created workbook
  • Run code
  • Open test.xlsx

>Solution :

There is a problem with the rank of your outline_levels, which messes up the nesting.

Here is a possible fix :

import openpyxl

wb = openpyxl.load_workbook("Planung.xlsx")
ws = wb["Zeitplan"]

ws.sheet_properties.outlinePr.summaryBelow = False

ws.row_dimensions.group(7, 17, outline_level=1)
ws.row_dimensions.group(9, 11, outline_level=2)
ws.row_dimensions.group(13, 13, outline_level=2)
ws.row_dimensions.group(16, 17, outline_level=2)

wb.save("test.xlsx")

Output :

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading