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

当 Excel 表格跨越多页时,在每页的右侧或顶部(重复)打印列标题或行标题,可以更轻松快捷地阅读数据。 在 Excel 中,这些被称为"重复行和列"或"标题行和列"。 IronXL 只需几行代码即可利用电子表格的这一实用功能。

SetRepeatingRows(startRow, endRow)

此方法用于设置重复行。 例如,调用 workSheet.SetRepeatingRows(3, 4) 将在第 4 行和第 5 行设置重复。

SetRepeatingColumns(startColumn, endColumn)

此方法用于设置重复列。 例如,调用 workSheet.SetRepeatingColumns(0, 2) 将设置 A 列到 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.

仅对第一页右侧跨越多页的内容应用重复列规则。 图1展示了这种现象:

图 1

图 1

第一页底部两侧的多页将包含重复的行。

最后,位于内侧的页面将同时应用重复列和行规则。 图 2 显示了最后两种现象:

图 2

图 2 图片 1 表

学习如何使用 C# 在 Excel 中添加行和列

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php
Line: 12
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 489
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Examples.php
Line: 44
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php
Line: 19
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 489
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Examples.php
Line: 44
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

准备开始了吗?
Nuget 下载 1,890,100 | 版本: 2026.3 刚刚发布

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php
Line: 17
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/views/products/examples/index.php
Line: 270
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Examples.php
Line: 44
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index: IronXl.Excel

Filename: helpers/counter_helper.php

Line Number: 85

Backtrace:

File: /var/www/ironpdf.com/application/helpers/counter_helper.php
Line: 85
Function: _error_handler

File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php
Line: 24
Function: getTotalDonwloadNumber

File: /var/www/ironpdf.com/application/views/products/examples/index.php
Line: 270
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Examples.php
Line: 44
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package IronXl.Excel
运行示例 观看您的数据变成电子表格。