IRONSOFTWAREHOME
Auto-Resize Excel Rows and Columns in C#
using IronXL;

// Load existing spreadsheet
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet 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);

workBook.SaveAs("autoResize.xlsx");
Imports IronXL

' Load existing spreadsheet
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As 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)

workBook.SaveAs("autoResize.xlsx")
NuGet Download
PM > Install-Package IronXL.Excel
Auto-Resize Excel Rows and Columns in C#

Auto-Resize Excel Rows and Columns in C#

Resizing rows and columns in a spreadsheet can save a lot of space and make it more readable. The IronXL C# library has the functionality to auto resize rows and columns. Since it is done in C#, the resize methods can be called upon all the existing rows and columns, thereby automating the manual tasks in spreadsheets.

Auto Resize Rows

The AutoSizeRow method automatically resizes the height of the specified row based on its value length. Another overload of \``AutoSizeRow takes the second parameter as a Boolean value. If true, the height of merged cells will be considered.

Auto Resize Columns

Use the \AutoSizeColumn method to resize the width of a column based on its value length. Similar to ``AutoSizeRow, it is also possible to make the resizing of the column consider the width of a merged cell.

Please note that all the row and column positions mentioned above follow zero-based indexing.

Learn How to Auto-Size Excel Rows & Columns with C#
View on GitHub

Ready to Get Started?

Nuget Downloads 2,237,574Version: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