IRONSOFTWAREHOME
Group & Ungroup Excel Rows/Columns in Python
from ironxl import *

# Load existing spreadsheet
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet

# Apply grouping to row 1-5
worksheet.GroupRows(0, 4)

# Ungroup row 3-5
worksheet.UngroupRows(2, 4)

# Apply grouping to column A-F
worksheet.GroupColumns(0, 5)

# Ungroup column C-D will cut the grouping at B
worksheet.UngroupColumn("C", "D")

# Save changes with grouped and ungrouped rows and columns
workbook.SaveAs("groupAndUngroup.xlsx")
pip install ironxl
Group & Ungroup Excel Rows/Columns in Python

Group & Ungroup Excel Rows/Columns in Python

Apply grouping and ungrouping of rows and columns in Excel using intuitive IronXL for Python APIs, without requiring Office Interop.

Group and Ungroup Rows

The GroupRows method groups rows by specifying their index positions. Multiple groupings can be applied using repeated calls to this method.

To ungroup rows, use the UngroupRows method. This method acts like a cutting tool - when applied to the middle of an existing row group, it splits that group into two. For example, ungrouping rows 2-4 within a group spanning 0-9 results in groups 0-1 and 5-9.

Group and Ungroup Columns

Columns can be grouped in the same way as rows. Use the GroupColumns method to group columns by their index positions or by specifying column names as strings. Multiple column groups can be created as needed.

To ungroup columns, use the UngroupColumns method, which also functions as a cutting tool. Applying it in the middle of a column group splits it in two. For instance, ungrouping columns C-D within a group A-F results in groups A-B and E-F.

All index positions use zero-based indexing. Grouping can only be applied as far as the cells contain values.

Learn to Group and Ungroup Excel Rows and Columns with IronXL for Python

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required