HorizontalPageBreakCollection.Item

HorizontalPageBreakCollection indexer (1 of 2)

Gets the HorizontalPageBreak element at the specified index.

public HorizontalPageBreak this[int index] { get; }
ParameterDescription
indexThe zero based index of the element.

Return Value

The element at the specified index.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class HorizontalPageBreakCollectionPropertyItemDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            
            // Add horizontal page breaks
            worksheet.HorizontalPageBreaks.Add(5);
            worksheet.HorizontalPageBreaks.Add(10);
            
            // Access page breaks using Item property
            HorizontalPageBreak firstBreak = worksheet.HorizontalPageBreaks[0];
            Console.WriteLine("First page break row: " + firstBreak.Row);
            
            // Modify cells which affects page breaks
            worksheet.Cells.DeleteRows(0, 2);
            
            // Verify the page break was adjusted
            Console.WriteLine("First page break after row deletion: " + worksheet.HorizontalPageBreaks[0].Row);
        }
    }
}

See Also


HorizontalPageBreakCollection indexer (2 of 2)

Gets the HorizontalPageBreak element with the specified cell name.

public HorizontalPageBreak this[string cellName] { get; }
ParameterDescription
cellNameCell name.

Return Value

The element with the specified cell name.

Examples

namespace AsposeCellsExamples
{
    using System;
    using Aspose.Cells;

    public class HorizontalPageBreakCollectionPropertyItemDemo1
    {
        public static void Run()
        {
            // Create a new workbook and get the first worksheet
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            try
            {
                // Add a couple of horizontal page breaks using different overloads
                worksheet.HorizontalPageBreaks.Add(5);          // break after row index 5
                worksheet.HorizontalPageBreaks.Add("D5");      // break at cell D5 (row index 4)

                // ----- Access via integer index (Item[int]) -----
                // The Item property is the indexer, so we use the [] syntax
                HorizontalPageBreak firstBreak = worksheet.HorizontalPageBreaks[0];
                Console.WriteLine("First break row (int index): " + firstBreak.Row);

                // ----- Access via string key (Item[string]) -----
                // Retrieve the page break that was added with the cell name "D5"
                HorizontalPageBreak breakByCell = worksheet.HorizontalPageBreaks["D5"];
                Console.WriteLine("Break added with \"D5\" is at row: " + breakByCell.Row);

                // Save the workbook to verify that the page breaks are persisted
                workbook.Save("HorizontalPageBreaks_ItemDemo.xlsx");
                Console.WriteLine("Workbook saved successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
    }
}

See Also