TX Sheet Control

Freeze Panes and Selection

Topic

Long reports stay readable when their headings stay in view. Freeze the heading rows and columns of a worksheet while the rest of the report scrolls, or split the view into regions that scroll independently. Both are view settings of the worksheet, not cell formatting. Your code also decides when the visible selection follows what it does in the document.

Freeze or Split the View

The following code freezes rows and columns of the first worksheet, selects a range and shows the alternatives to freezing. editor is the Spreadsheet of the browser editor, created as in JavaScript:

const sheet = editor.workbook.sheets.at(0);
sheet.viewport.freeze({ rows: 3, columns: 1 });
editor.ui.selectRange(sheet.range('B4:D8'));
// Use split instead of freeze when separate scroll regions are needed:
sheet.viewport.split({ row: 10, column: 4 });
// Restore one unfrozen viewport:
sheet.viewport.reset();

The code works as follows:

  • Workbook.sheets and SheetCollection.at return the first worksheet.
  • Worksheet.viewport returns the SheetView of the worksheet. Its settings never alter the underlying row heights, column widths or print area.
  • freeze freezes data rows and columns, given by rows and columns.
  • EditorUi.selectRange selects the range B4:D8, which Worksheet.range returns, in the visible interface.
  • split creates split panes at the row and column boundaries given by row and column. Use it instead of freeze when you need separate scroll regions.
  • reset restores one unfrozen viewport.

Counts and boundaries are zero-based, as specified by the public methods. The fixed row and column labels of the editor are separate from frozen worksheet data.

Floating charts, shapes, pictures and barcodes scroll with the worksheet content. When you scroll past frozen rows or columns, those frozen cells cover the objects and their selection handles. Page Layout continues to show objects in their printable positions.

Validate the view in narrow containers and at high zoom values: a frozen area should leave usable space for the scrollable cells.

In-cell barcodes and pictures follow their worksheet cells. Pictures in frozen rows or columns stay pinned on that axis; scrolling pictures are clipped behind the frozen cells. A picture in a merged cell crossing a freeze boundary is displayed as aligned fragments in the corresponding panes. Page layout and PDF use the document layout.

Select Sheets and Ranges From Code

Obtaining book.sheets.at(1).cell('B2') does not select that sheet. Call editor.ui.selectSheet() or selectRange(), the methods selectSheet and selectRange of EditorUi, only when the visible interface should follow the operation of your application.

Selecting a chart or a drawing works the same way and uses the owning editor and a valid object handle, with selectChart or selectDrawing.

Use editor.ui.selection, the selection property, to inspect the supported selection state. Do not calculate document addresses from browser pixel coordinates: UI geometry, font metrics, zoom and panes can all change the mapping.

Next Steps