Skip to main content Skip to footer

Print Titles in C1Excel

Microsoft Excel provides a Print Titles feature to print the row and column headings or labels on every page if a worksheet spans more than one page while printing. In simple words, Print Titles are the rows and columns repeated at the top and left of each page respectively, when a sheet is printed. When any excel file is created using C1Excel, this feature is not implemented by default. However, we can set Print Titles using C1Excel's SetRangeToRepeat() method which accepts arguments to specify the range of rows and columns to use as Print Titles for the worksheet. Following code blocks show the implementation of SetRangeToRepeat() method.


private void btnRepeatTop_Click(object sender, EventArgs e)  
 {  
    book.Load("..\\\..\\\TestRepeat.xls");  
    XLSheet sheet = book.Sheets[0];  
    sheet.Rows[6].PageBreak = true;  
    //specifies the range to be repeated on each print page after exporting it to Excel  
    sheet.SetRangeToRepeat(0, 0, -1, -1);  
    string xlsFile = tempdir + @"RepeatTop.xls";  
    book.Save(xlsFile);  
    System.Diagnostics.Process.Start(xlsFile);  
  }  

private void btnRepeatLeft_Click(object sender, EventArgs e)  
 {  
    book.Load("..\\\..\\\TestRepeat.xls");  
    XLSheet sheet = book.Sheets[1];  
    sheet.Columns[1].PageBreak = true;  
    sheet.SetRangeToRepeat(-1, -1, 0, 0);  
    string xlsFile = tempdir + @"RepeatLeft.xls";  
    book.Save(xlsFile);  
    System.Diagnostics.Process.Start(xlsFile);  
}  

private void btnRepeatTopAndLeft_Click(object sender, EventArgs e)  
{  
   book.Load("..\\\..\\\TestRepeat.xls");  
   XLSheet sheet = book.Sheets[2];  
   sheet.Rows[6].PageBreak = true;  
   sheet.Columns[1].PageBreak = true;  
   sheet.SetRangeToRepeat(0, 0, 0, 0);  
   string xlsFile = tempdir + @"RepeatTopAndLeft.xls";  
   book.Save(xlsFile);  
   System.Diagnostics.Process.Start(xlsFile);  
} 

PrintTitle Refer to the attached samples for complete implementation. DownloadSample_CS DownloadSample_VB

MESCIUS inc.

comments powered by Disqus