通过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

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

准备开始了吗?
Nuget 下载 1,765,830 | 版本: 2025.12 刚刚发布