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 試算表跨越多頁時,若將欄位或列標題 PRINT 在每頁的右側或頂端(重複 PRINT),資料將更易於閱讀且更為迅速。 在 Excel 中,這些稱為 重複的列與欄標題列與欄。 IronXL 只需幾行程式碼,即可運用試算表的這項實用功能。

SetRepeatingRows(startRow, endRow)

此方法用於設定重複的列。 例如,呼叫 workSheet.SetRepeatingRows(3, 4) 將在第 4 行和第 5 行設定重複。

SetRepeatingColumns(startColumn, endColumn)

此方法用於設定重複欄位。 例如,呼叫 workSheet.SetRepeatingColumns(0, 2) 將設定 A 至 C 欄位為重複列。

這兩種方法使用以零為起點的索引作為參數,因此 column(0) 代表"A",而 row(1) 代表 2。 需特別注意,若同時使用 SetRepeatingRows()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天試用金鑰
無需信用卡或帳戶建立