Search code examples
excelpython-3.xpywin32

Grouping of rows in excel using python


I am automating certain excel tasks. Right now, I need to append some missing data into a table which uses Outline levels. I have been using pywin32 all along and I have come to the point where I have appended missing data with outline levels.

I can specify the outline levels using this piece of code:

xlSheet.Rows(row_number).OutlineLevel=3

But the problem is that I can't specify that this row-PLA(Outline level=3) should come under this row-Incoming &Outgoing money(Outline Level=2).

Can you guys help me with a solution (using win32)?

enter image description here


Solution

  • Found the solution rangeObj.EntireRow.Groupdoes what is needed (using win32 library).

    import win32com.client as win32
    xlSheet.Cells(i+2,1).Value=temp_sheet.Cells(j+1,3).Value
    xlSheet.Rows(i + 2).OutlineLevel = 2
    rangeObj.EntireRow.Group