DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironsoftware.com

Repeat Excel Rows & Columns

When Excel spreadsheets span several pages, the data is easier to read when we print the column titles at the top of every page. These are called "Repeating Rows" in Excel.

"Repeating Rows" and "Repeating Columns" are header rows and columns which repeat on every printed page of an Excel WorkSheet

These are also known as also known as "Duplicate Rows and Columns" and "Header Rows and Columns"

C#:

using IronXL;

WorkBook workbook = WorkBook.Load("test.xlsx");
WorkSheet worksheet = workbook.DefaultWorkSheet;

// SetRepeatingRows is how we can set repeating rows for the print title of the worksheet.  
// The Int parameters are the start and end zero-based row numbers.
// To remove  repeating rows you can use worksheet.RemoveRepeatingRows();  
worksheet.SetRepeatingRows(1, 2);


// SetRepeatingColumns is how we can set repeating columns.
// The Int parameters are the start and end zero-based colum numbers (0 is "A");
// To remove repeating columns you can use worksheet.RemoveRepeatingColumns();
worksheet.SetRepeatingColumns(2,3);


workbook.SaveAs("RepeatingRows.xlsx");
Enter fullscreen mode Exit fullscreen mode

VB:

Imports IronXL

Private workbook As WorkBook = WorkBook.Load("test.xlsx")
Private worksheet As WorkSheet = workbook.DefaultWorkSheet

' SetRepeatingRows is how we can set repeating rows for the print title of the worksheet.  
' The Int parameters are the start and end zero-based row numbers.
' To remove  repeating rows you can use worksheet.RemoveRepeatingRows();  
worksheet.SetRepeatingRows(1, 2)


' SetRepeatingColumns is how we can set repeating columns.
' The Int parameters are the start and end zero-based colum numbers (0 is "A");
' To remove repeating columns you can use worksheet.RemoveRepeatingColumns();
worksheet.SetRepeatingColumns(2,3)


workbook.SaveAs("RepeatingRows.xlsx")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)