IRONSOFTWAREHOME
Repeat Rows & Columns in Excel via C#
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set repeating rows for row(2-4)
workSheet.SetRepeatingRows(1, 3);

// Set repeating columns for column(C-D)
workSheet.SetRepeatingColumns(2, 3);

// Set column break after column(H). Hence, the first page will only contain column(A-G)
workSheet.SetColumnBreak(7);

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

Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

' Set repeating rows for row(2-4)
workSheet.SetRepeatingRows(1, 3)

' Set repeating columns for column(C-D)
workSheet.SetRepeatingColumns(2, 3)

' Set column break after column(H). Hence, the first page will only contain column(A-G)
workSheet.SetColumnBreak(7)

workBook.SaveAs("repeatingRows.xlsx")
NuGet Download
PM > Install-Package IronXL.Excel
Repeat Rows & Columns in Excel via C#

Repeat Rows & Columns in Excel via C#

When Excel spreadsheets span several pages, the data is easier and quicker to read when we print the column or row titles at the right or top of every page (repeating). These are called Repeating Rows and Columns or Header Rows and Columns in Excel. IronXL can utilize this useful aspect of spreadsheets with just a few lines of code.

SetRepeatingRows(startRow, endRow)

This method is used to set repeating rows. For example, calling workSheet.SetRepeatingRows(3, 4) will set repeating on rows 4 and 5.

SetRepeatingColumns(startColumn, endColumn)

This method is used to set repeating columns. For example, calling workSheet.SetRepeatingColumns(0, 2) will set repeating on columns A to C.

These two methods use zero-based indexing as parameters, such that column(0) is "A" and row(1) is 2. It's important to note that if these methods SetRepeatingRows() and SetRepeatingColumns() are used in combination, each page may have different repeating rules based on their position relative to the first page.

The content that spans multiple pages along the right side of the first page will have the repeating column rule applied only. Figure 1 shows this phenomenon:

Figure 1

Figure 1

Multiple pages spanning along the bottom side of the first page will contain repeating rows.

Lastly, pages that are located on the inner side will have both repeating columns and row rules applied to them. Figure 2 shows the last two phenomena:

Figure 2

Figure 2

Learn to Add Rows & Columns in Excel 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