[Python] Using xlwings, is there a way to collapse all the groups on a sheet?

Discussão em 'Python' iniciado por Stack, Janeiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using xlwings with python to copy one excel sheet to another. As part of the copying, however, I'd like to collapse all the grouped columns.

    This is different than hiding the relevant columns and rows; I want them to be non-hidden, but just have the outlines collapsed to level 0!

    And to be clear, I also don't want to create new outlines; I just want all the existing ones to be collapsed.

    Is there a simple command to do that? Cannot find it via google. (if the answer is to group specific ranges - the answer also would need to list how to find the ranges that are available for grouping!).

    Edited to add: The solution must work on MacOS. The answer proposed by @grismar below fails on a Mac:

    (Pdb) sheet.api.Outline
    *** AttributeError: Unknown property, element or command: 'Outline'

    Continue reading...

Compartilhe esta Página