IRONSOFTWAREHOME
通过C#在Excel中重复行和列
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
通过C#在Excel中重复行和列

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

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

SetRepeatingRows(startRow, endRow)

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

SetRepeatingColumns(startColumn, endColumn)

此方法用于设置重复列。 例如,调用workSheet.SetRepeatingColumns(0, 2)将在A到C列设置重复。

这两种方法将零基索引作为参数使用,如SetRepeatingColumns(),则每个页面可能基于它们相对于第一页的位置拥有不同的重复规则。

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

图 1

图1

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

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

图 2

图2

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

准备开始了吗?

Nuget Downloads 2,237,574版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户