Worksheet Views

Page Break Preview

All worksheets can be viewed in two modes:

  • Normal view.
  • Page break preview.

The Normal view is a worksheet’s default view. Page break preview is an editing view that displays a worksheet as it will be printed. Page break preview shows what data will go on each page so you can adjust the print area and page breaks. Using Aspose.Cells, developers can enable normal view or page break preview modes.

Controlling View Modes

Aspose.Cells provides a class Workbook that represents a Microsoft Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in an Excel file.

A worksheet is represented by the Worksheet class. The Worksheet class provides a wide range of methods for managing worksheets. To enable normal or page break preview modes, use the SetIsPageBreakPreview method of the Worksheet class. IsPageBreakPreview returns a bool value, which means that it can only store a true or false value.

Enabling Normal View

Set a worksheet to normal view by calling the SetIsPageBreakPreview method with false.

Enabling Page Break Preview

Set any worksheet to page break preview by calling the SetIsPageBreakPreview method with true. Doing so switches the worksheet from normal view to page break preview.

A complete example is given below that demonstrates how to use the SetIsPageBreakPreview method to enable page break preview mode for the first worksheet of an Excel file.

Zoom Factor

Using Microsoft Excel

Microsoft Excel provides a feature that lets users set a worksheet’s zoom or scaling factor. This feature helps users see the worksheet contents in smaller or larger views. Users can set the zoom factor to any value.

Aspose.Cells & Zoom Factor

Aspose.Cells also allows developers to set the worksheet zoom factor. Aspose.Cells provides a class Workbook that represents a Microsoft Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in an Excel file.

A worksheet is represented by the Worksheet class. The Worksheet class provides a wide range of methods for managing worksheets. To set a worksheet’s zoom factor, use the SetZoom method of the Worksheet class. The zoom factor is set by passing a numeric (integer) value to the SetZoom method.

A complete example is given below that demonstrates how to use the SetZoom method to set the zoom factor of the first worksheet of the Excel file.

Freeze Panes

Using Microsoft Excel

Freeze panes is a feature provided by Microsoft Excel. Freezing panes allows you to keep selected data visible when scrolling in a worksheet.

Aspose.Cells & Freeze Panes

Aspose.Cells also allows developers to apply freeze panes to worksheets at runtime. Aspose.Cells provides a class Workbook that represents a Microsoft Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in an Excel file.

A worksheet is represented by the Worksheet class. The Worksheet class provides a wide range of methods for managing worksheets. To configure freeze panes, call the FreezePanes method of the Worksheet class. The FreezePanes method takes the following parameters:

  • Row – the row index of the cell from which the freeze will start.
  • Column – the column index of the cell from which the freeze will start.
  • Frozen rows – the number of visible rows in the top pane.
  • Frozen columns – the number of visible columns in the left pane.

A complete example is given below that shows how to use the FreezePanes method to freeze rows and columns (starting from C4, represented by the 4th row and 3rd column, where rows and columns are zero‑based) of the first worksheet of the Excel file.

Split Panes

If you need to split the screen to get two different views in the same worksheet, you can use split panes. Microsoft Excel offers a very handy feature that allows you to view more than one copy of your worksheet and scroll through each pane independently.

The panes work simultaneously. If you make a change in one, the change appears in the other. Aspose.Cells provides the split panes feature for users.

Applying and Removing Split Panes

Splitting Panes

Aspose.Cells provides a class Workbook that represents a Microsoft Excel file. The Workbook class provides a wide range of methods for managing an Excel file. To implement split views, use the Split method of the Worksheet class. To remove the split panes, use the RemoveSplit method.

In the example, we load a simple template file, apply the split panes feature to a cell in the first worksheet, and then save the updated file.

Removing Panes

Remove split panes using the RemoveSplit method.