Articles in this section
Category / Section

How to get the row index of page breaks in Excel worksheet using C#, VB.NET?

3 mins read

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. You can get the row index of page breaks using HPageBreaks with the IWorksheet interface.

This article explains how to get the row index of page breaks in Excel worksheet using C# and VB.NET.

Include the following namespace in the Program.cs file.

C#

using Syncfusion.XlsIO;

VB.NET

Imports Syncfusion.XlsIO

Use the following code snippet for getting the row index of page breaks in Excel worksheet.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
    FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
    IWorkbook workbook = application.Workbooks.Open(inputStream);
    IWorksheet sheet = workbook.Worksheets[0];

    //Access all horizontal page breaks
    for (int i = 0; i < sheet.HPageBreaks.Count; i++)
    {
        int rowIndex = sheet.HPageBreaks[i].Location.Row;
        Console.WriteLine($"Page break {i + 1} is at row: {rowIndex}");
    }

    //Dispose streams
    inputStream.Dispose();
} 

VB.NET

Using excelEngine As New ExcelEngine()
    Dim application As IApplication = excelEngine.Excel
    application.DefaultVersion = ExcelVersion.Xlsx
    Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx")
    Dim sheet As IWorksheet = workbook.Worksheets(0)

    'Access all horizontal page breaks
    For i As Integer = 0 To sheet.HPageBreaks.Count - 1
        Dim rowIndex As Integer = sheet.HPageBreaks(i).Location.Row
        Console.WriteLine($"Page break {i + 1} is at row: {rowIndex}")
    Next
End Using  

You can get the complete sample for getting the row index of page breaks in Excel worksheet from here.

I hope you enjoyed learning about how to get the row index of page breaks in Excel worksheet using C# and VB.NET in XlsIO.

You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.

If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.

If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!

Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and, protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied