Interface IHPageBreaks
The collection of horizontal page breaks within the print area. Each horizontal page break is represented by an IHPageBreak object.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.NET.dll
Syntax
public interface IHPageBreaks : IEnumerable
Properties
Application
Used without an object qualifier, this property returns an IApplication object that represents the Excel IApplication.
Declaration
IApplication Application { get; }
Property Value
Type |
---|
IApplication |
Examples
The following code illustrates how to access the IApplication property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Property returns an Application object that represents the Excel application
IApplication hPageBreakApplication = sheet.HPageBreaks.Application;
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
}
Count
Returns the number of objects in the collection. Read-only.
Declaration
int Count { get; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates the use of Count property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Number of objects in the collection
int hPageBreakCount = sheet.HPageBreaks.Count;
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
}
Item[IRange]
Returns a single IHPageBreak object from a collection. Read-only.
Declaration
IHPageBreak this[IRange location] { get; }
Parameters
Type | Name | Description |
---|---|---|
IRange | location |
Property Value
Type |
---|
IHPageBreak |
Remarks
To know more about page setting refer this link.
Examples
The following code illustrates how to get a IHPageBreak object from location.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add PageBreaks
sheet.Range["A1:S65"].Text = "PagePrint";
sheet.HPageBreaks.Add(sheet.Range["A3"]);
sheet.HPageBreaks.Add(sheet.Range["G10"]);
sheet.HPageBreaks.Add(sheet.Range["F24"]);
sheet.HPageBreaks.Add(sheet.Range["C37"]);
//Get the Horizontal page break location as index
IRange pageBreakLocation = sheet.HPageBreaks[0].Location;
IRange hPageBreakLocation = sheet.HPageBreaks[pageBreakLocation].Location;
IRange hPageBreakLocation2 = sheet.HPageBreaks[sheet.Range["G10"]].Location;
IParentApplication pageBreakApplication = sheet.HPageBreaks[sheet.Range["F24"]].Application;
object pageBreakParent = sheet.HPageBreaks[sheet.Range["C37"]].Parent;
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
}
Item[Int32]
Returns a single IHPageBreak object from a collection. Read-only.
Declaration
IHPageBreak this[int Index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | Index |
Property Value
Type |
---|
IHPageBreak |
Remarks
To know more about page setting refer this link.
Examples
The following code illustrates how to get an IHPageBreak object from a collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add PageBreaks
sheet.Range["A1:S65"].Text = "PagePrint";
sheet.HPageBreaks.Add(sheet.Range["A3"]);
sheet.HPageBreaks.Add(sheet.Range["G10"]);
sheet.HPageBreaks.Add(sheet.Range["F24"]);
sheet.HPageBreaks.Add(sheet.Range["C37"]);
//Get the Horizontal page break location using index
IRange hPageBreakLocation1 = sheet.HPageBreaks[0].Location;
IRange hPageBreakLocation2 = sheet.HPageBreaks[1].Location;
IRange hPageBreakLocation3 = sheet.HPageBreaks[2].Location;
IRange hPageBreakLocation4 = sheet.HPageBreaks[3].Location;
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
}
Parent
Returns the parent object for the specified object.
Declaration
object Parent { get; }
Property Value
Type |
---|
System.Object |
Examples
The following code illustrates the use of Parent property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create a worksheet.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Parent object for the specified object
object hPageBreakParent = sheet.HPageBreaks.Parent;
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
}
Methods
Add(IRange)
Adds a horizontal page break. Returns an IHPageBreak object.
Declaration
IHPageBreak Add(IRange location)
Parameters
Type | Name | Description |
---|---|---|
IRange | location | IRange of the page break. |
Returns
Type | Description |
---|---|
IHPageBreak | IHPageBreak which was added. |
Remarks
To know more about page setting refer this link.
Examples
The following code illustrates how to add a horizontal page break.
//Create a worksheet.
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:T100"].Text = "PagePrint";
//Set Horizontal Page Breaks.
sheet.HPageBreaks.Add(sheet.Range["A5"]);
sheet.HPageBreaks.Add(sheet.Range["C18"]);
sheet.HPageBreaks.Add(sheet.Range["H32"]);
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
Clear()
Clears horizontal page breaks from HPageBreaks collection.
Declaration
void Clear()
Remarks
To know more about page setting refer this link.
Examples
The following code illustrates how to clear a horizontal page break.
//Create a worksheet.
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//clear Horizontal Page Breaks
sheet.HPageBreaks.Clear();
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
GetPageBreak(Int32)
Returns page break at the specified row.
Declaration
IHPageBreak GetPageBreak(int iRow)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | iRow | One-based row index. |
Returns
Type | Description |
---|---|
IHPageBreak | Page break with corresponding row or null if not found. |
Remarks
To know more about page setting refer this link.
Examples
The following code illustrates how to get page break with corresponding row.
//Create a worksheet.
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Get Page break with corresponding row
IHPageBreak hPageBrk = sheet.HPageBreaks.GetPageBreak(5);
if(hPageBrk != null)
{
//Your code here
}
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();
Remove(IRange)
Removes a pagebreak from the specified IRange.
Declaration
IHPageBreak Remove(IRange location)
Parameters
Type | Name | Description |
---|---|---|
IRange | location | IRange to remove the page break. |
Returns
Type | Description |
---|---|
IHPageBreak | Horizontal page break in location after removing. |
Remarks
To know more about page setting refer this link.
Examples
The following code illustrates how to Remove a horizontal page break.
//Create a worksheet.
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet sheet = workbook.Worksheets[0];
//Remove Horizontal Page Breaks.
sheet.HPageBreaks.Remove(sheet.Range["A5"]);
sheet.HPageBreaks.Remove(sheet.Range["A18"]);
sheet.HPageBreaks.Remove(sheet.Range["A32"]);
workbook.SaveAs("PageSetup.xlsx");
workbook.Close();