通过C#在Excel中重复行和列

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 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#

准备开始了吗?
Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布