使用 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

第一頁底部兩側的多頁將包含重複的行。
最後,位於內側的頁面將同時套用重複列和行規則。 圖 2 顯示了最後兩種現象:
圖 2






