TX Sheet Control

Cells and Ranges

Topic

Cells and ranges are the handles through which you write values, text and formulas into a worksheet and read the results. Resolve the worksheet before a cell or range. A range belongs to that worksheet even when another sheet becomes active.

Write Values and Formulas

The following code writes two invoice items into A1:C3 of the first worksheet, then calculates the amount of each item and their total. editor is the Spreadsheet of the browser editor:

const sheet = editor.workbook.sheets.at(0);
sheet.range('A1:C3').setValues([
    ['Item', 'Quantity', 'Price'],
    ['Hardware', 2, 120], ['Software', 3, 80]
]);

sheet.cell('D2').setFormula('=B2*C2');
sheet.cell('D3').setFormula('=B3*C3');
sheet.cell('D4').setFormula('=SUM(D2:D3)');
console.log(sheet.cell('D4').value); // 480

The code works as follows:

How Input, Value and Display Differ

A cell keeps three layers of its content apart:

  • Input. The entered input may be a formula or literal text.
  • Value. The calculated value is a scalar, an error or an array result.
  • Display. The formatted display adds the number, date or text presentation.

Write each kind of content with its own method:

MethodUse it forWhat it does
setValue()Typed valuesWrites a literal scalar. Strings are not interpreted as formulas.
setText()Literal textPreserves leading zeros and leading equals signs.
setFormula()A formula expressionRequires the leading equals sign.

Avoid interpreting a formatted currency string as a numeric result.

The .NET API follows the same distinction through asynchronous cell methods. GetValueAsync() returns JSON data, a JsonElement, not a locale-formatted display string. Inspect the JSON value kind before reading a number, string or boolean.

Read and Write Whole Ranges

Range APIs read and write matrices, assign formulas and inputs, format and clear cells, merge and unmerge them and perform the supported fill and copy operations:

TaskMembers of Range
Read and write matricesread, values, setValues
Assign formulas and inputssetFormulas, setInputs
Format and clearformat, clear
Merge and unmergemerge, unmerge
Fill and copyfillTo, copyTo

Array dimensions must match the target operation. Worksheet bounds, protection and merged cells can restrict edits. Validate the full rectangle before you apply business updates.

Address Cells and Ranges

Use A1 strings such as B2, rectangles such as A1:D20 or supported coordinate objects. Coordinate row and column indices are zero-based.

Named ranges can make templates more readable. Formula references can span sheets and use absolute or relative coordinates, while a range handle itself represents a rectangle on one sheet.

Next Steps