TX Sheet Control

Workbooks and Worksheets

Topic

A workbook is the document of TX Sheet Control. It owns the worksheets, named ranges, calculation, history, events and dashboards. The editor displays one active worksheet or dashboard view, while backend code can work with explicit worksheet handles without selecting a UI view.

What follows covers the worksheets and their names, the handles that point into the document, the transactions that group edits and the bounds of the document.

Add and Rename Worksheets

The following code renames the first worksheet to Sales, adds a worksheet Summary and sums a column of Sales on it. editor is the Spreadsheet of the browser editor, created as in JavaScript:

const book = editor.workbook;
const sales = book.sheets.at(0);
sales.rename('Sales');

const summary = book.sheets.add('Summary');
summary.cell('A1').setText('Revenue');
summary.cell('B1').setFormula("=SUM(Sales!F2:F25)");

The code works as follows:

Four rules apply to worksheets and their addresses:

  • Indices and addresses. Collection indices are zero-based. A1 addresses are one-based labels.
  • IDs and handles. Prefer stable worksheet IDs, such as Worksheet.id, or handles when names can change.
  • Names. Worksheet names must remain valid and distinct.
  • Tab colors. A tab color, set with Worksheet.setTabColor, affects the navigation, not the print or PDF content.

Resolve Handles After the Document Is Replaced

load() replaces the current document atomically. Existing worksheet, range, table, chart and drawing handles can become stale after a replacement or a deletion. Resolve them again after a successful load.

Warning

Stale Handles. Do not catch a stale-handle error and continue writing through the old handle.

Group Edits Into One Transaction

Group synchronous related edits with book.batch(() => { ... }), the Workbook.batch method. A batch can form one undoable transaction and roll back failed changes. Do not use an asynchronous batch callback: fetch the application data first, then collect the synchronous mutations.

For the supported authoring history, call book.history.undo() or redo() of Workbook.history.

In .NET, use the worksheet handles returned by Workbook.Sheets and await the operations. BatchAsync collects supported typed commands synchronously. It is not a callback for arbitrary awaited server operations.

How the Document Bounds Work

Sparse data storage does not imply that every logical row or column is prepopulated. The initial rows and columns, the automatic growth and the maximum limits control the bounds of the document. Scrolling and resizing the host can reveal or grow capacity without stretching the cell dimensions.

Screen zoom differs from the row and column size and from the PDF print scaling.

Next Steps