# Rows and Columns

> Size rows and columns in points, pixels or characters, insert, delete and hide them with the rows and columns collections and AutoFit them in the editor.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Spreadsheet Documents > Rows and Columns
- **1410 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/rows-columns/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/rows-columns/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/rows-columns/llms-full.txt

---

Row heights, column widths, inserted and deleted rows and hidden columns are all changed through the `rows` and `columns` collections of a worksheet. Both collections are bound to their worksheet, so you change the structure and size of a sheet without relying on the selected sheet.

Each size you set names its unit: points, CSS pixels or characters.

### Use the Format Menu

Choose **Home → Cells → Format** to open the grouped worksheet commands. **Cell Size** contains Row Height, Column Width and their AutoFit commands. The size dialogs use CSS pixels. **Visibility → Hide & Unhide** acts on the selected rows or columns; select the surrounding visible rows or columns to reveal a hidden run.

**Organize Sheets** provides Rename Sheet, Move or Copy Sheet and Tab Color. The move dialog places the active sheet before a chosen worksheet or at the end, with an option to create a copy. **Protection** provides Protect Sheet, Lock Cell and Format Cells. Lock Cell changes the selected cells' locked state; sheet protection determines whether that state prevents editing.

Default Width, Hide Sheet and Unhide Sheet are shown disabled because workbook-wide default column sizing and worksheet visibility are not supported by the current model.

### Size, Insert and Hide Rows and Columns

The following code sizes a row and two columns of the first worksheet, inserts and removes two rows and then hides and shows two columns. `editor` is the [`Spreadsheet`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/llms-full.txt) of the browser editor:

```javascript
const sheet = editor.workbook.sheets.at(0);
sheet.rows.get(1).setHeight({ points: 24 });
sheet.columns.get('A').setWidth({ pixels: 180 });
sheet.columns.at(1).setWidth({ characters: 16 });
sheet.rows.insert(4, 2); // Insert two rows before visible row 5.
sheet.rows.remove(4, 2);
sheet.columns.setHidden(3, 2, true); // Hide columns D and E.
sheet.columns.setHidden(3, 2, false);
```

The code works as follows:

- [`Worksheet.rows`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/rows-property/llms-full.txt) and [`Worksheet.columns`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/columns-property/llms-full.txt) return the rows and the columns of the worksheet, each as a [`DimensionCollection`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimensioncollection/llms-full.txt).
- [`get()`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimensioncollection/get-method/llms-full.txt) uses visible labels: one-based row numbers or column letters, such as row `1` and column `'A'`. [`at()`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimensioncollection/at-method/llms-full.txt) and the structural indices are zero-based, so `at(1)` is column B. Both return a [`Dimension`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimension/llms-full.txt).
- [`setHeight`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimension/setheight-method/llms-full.txt) sets the height of row 1 to 24 points. [`setWidth`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimension/setwidth-method/llms-full.txt) sets column A to 180 CSS pixels and column B to 16 characters.
- [`insert`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimensioncollection/insert-method/llms-full.txt) inserts two rows before the zero-based index 4, and [`remove`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimensioncollection/remove-method/llms-full.txt) deletes the two rows at that index again.
- [`setHidden`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimensioncollection/sethidden-method/llms-full.txt) hides two columns from the zero-based index 3 with `true` and shows them again with `false`.

### Choose the Units of a Size

| Dimension | Accepted units |
|---|---|
| Row height | Points or CSS pixels |
| Column width | Characters or CSS pixels |

Choose the units explicitly. Character widths depend on the font metrics of the document. Do not treat them as a constant pixel conversion.

[`size`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimension/size-property/llms-full.txt) reports the effective CSS-pixel size of a row or column. [`reset()`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/dimension/reset-method/llms-full.txt) removes the explicit dimension override.

### Fit Rows and Columns to Their Content

In an editor, [`editor.ui.autoFitRows()`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/editorui/autofitrows-method/llms-full.txt) and [`autoFitColumns()`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/editorui/autofitcolumns-method/llms-full.txt) measure the current selection after the required fonts are available. For a deliberate subset, pass supported inclusive zero-based bounds as the `first` and `last` arguments.

AutoFit is a layout operation, not a promise that a long unbreakable value fits a narrow viewport.

### What Structure Changes Affect

Insert and delete operations update supported references and document objects. They can reject invalid bounds, worksheet limits or protected edits.

- **Test realistic templates.** Check merged cells, table calculated columns, names, drawing anchors and dependent formulas in realistic templates.
- **Reacquire handles.** Reacquire handles whose addresses should change after structural edits: a range handle retains its stored address.

### Hide Rows and Columns

Hiding keeps the data and the stored sizes. It is distinct from [AutoFilter](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/sorting-filtering/llms-full.txt) and from deleting rows.

> Warning
>
> **Hidden Data.** Hidden data may still be present in downloadable files and must not be used as an authorization mechanism.

### Next Steps

- [Cells and Ranges](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/cells/llms-full.txt): write values, text and formulas into the cells of the rows and columns.
- [Font Handling](https://docs.textcontrol.com/tx-sheet-control/deployment/fonts/llms-full.txt): deploy the fonts whose metrics decide character widths, wrapping and row heights.
- [DimensionCollection](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/dimensioncollection/llms-full.txt): look up every member of the `rows` and `columns` collections in the TypeScript reference.

---

## Nearby

- **Previous:** [Cells and Ranges](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/cells/llms-full.txt)
- **Next:** [Copy, Paste and Fill](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/copy-fill/llms-full.txt)
