IRONSOFTWAREHOME
Auto Adjust Rows & Columns Size
from ironxl import *

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

# Apply auto resize on row 2
worksheet.AutoSizeRow(1)

# Apply auto resize on column A
worksheet.AutoSizeColumn(0)

# Apply auto resize on column D
worksheet.AutoSizeColumn(3, True)

# Save changes with the applied auto-resize
workbook.SaveAs("autoResize.xlsx")
pip install ironxl
Auto Adjust Rows & Columns Size

Auto Adjust Rows & Columns Size

Resizing rows and columns in a spreadsheet saves space and improves readability. IronXL for Python includes built-in methods to auto-resize rows and columns based on their content. Because this is done programmatically in Python, the resize methods can be applied across all existing rows and columns, fully automating what would otherwise be a manual task in Excel.

Auto Resize Rows

The AutoSizeRow method automatically adjusts the height of the specified row based on the length of its content. An overload of AutoSizeRow accepts a second Boolean parameter - when set to True, the height calculation takes merged cells into account.

Auto Resize Columns

Use the AutoSizeColumn method to resize the width of a column based on its content length. Similar to AutoSizeRow, an overload is available that considers the width of merged cells when True is passed as the second parameter.

Please note that all row and column positions use zero-based indexing.

Learn How to Auto-Size Excel Rows and Columns with 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