# Tables

> Create Excel-style tables with named columns, styles and calculated columns, pick a style on the Table Design tab and insert, delete or resize rows and columns.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Spreadsheet Documents > Tables
- **1899 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/tables/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/tables/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/tables/llms-full.txt

---

An Excel-style table is an operational worksheet object: a header range, named columns, formatting options and structured references such as `[@Quantity]`. Formatting a plain range with colors alone does not create a table. A table keeps its formulas and column names when its rows and columns change, which also makes it a good source for a dashboard.

### Create a Table

The following code fills a range of the first worksheet with two invoice items and turns it into a table. `editor` is the [Spreadsheet](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/llms-full.txt) of the browser editor, created as in [JavaScript](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/javascript/llms-full.txt):

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

const table = sheet.tables.add('Sales', 'A1:D3', {
    style: 'TableStyleMedium2', hasHeaderRow: true, showRowStripes: true
});

table.setColumn('Amount', { formula: '=[@Quantity]*[@Price]' });
```

The code works as follows:

- [Workbook.sheets](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/sheets-property/llms-full.txt) and [SheetCollection.at](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/sheetcollection/at-method/llms-full.txt) return the first worksheet.
- [Worksheet.range](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/range-method/llms-full.txt) and [Range.setValues](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/range/setvalues-method/llms-full.txt) write the column headings and the items. The `Amount` cells stay empty, because the table calculates them.
- [TableCollection.add](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/tablecollection/add-method/llms-full.txt), reached through [Worksheet.tables](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/tables-property/llms-full.txt), creates the table `Sales` over `A1:D3` with the style `TableStyleMedium2`, a header row and row stripes, and returns a [Table](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/llms-full.txt).
- [Table.setColumn](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/setcolumn-method/llms-full.txt) makes `Amount` a calculated column. The structured references `[@Quantity]` and `[@Price]` refer to the cells of the same row.

Table names are unique across the workbook. Column names derive from the headers unless you provide them explicitly. Use the table's handle or ID for later updates, and acquire a new handle after the document is replaced.

### Choose a Table Style in the Ribbon

Click inside a table, such as `SalesData` in the [sales workbook](https://docs.textcontrol.com/tx-sheet-control/overview/sample-documents/llms-full.txt), to show the **Table Design** tab, then open **More Table Styles**:

![The expanded table-style gallery of the Table Design tab, with its presets grouped under Light, Medium and Dark](https://docs.textcontrol.com/assets/img/tx-sheet-control/table-styles-gallery.b299c8cf.webp)

Choose a preset, then adjust the header and totals rows, the striping, the emphasis and the filter buttons independently. A style tile changes the table's appearance and retains its named columns and formulas. [Ribbon and Contextual Commands](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/ribbon/#table-design-commands-for-the-selected-table) shows where these commands are located on the Table Design tab.

### Set the Display Options and Totals

The display options of a table are independent of each other: the header and totals rows, row and column stripes, emphasis of the first and last column and the filter buttons. The Table Design ribbon groups its style galleries into Light, Medium and Dark. Native style names such as `TableStyleMedium2` are retained in XLSX.

A calculated column propagates its formula across all rows of the table. Totals functions and formulas belong to the settings of a column. After a quantity or a rate changes, review the formula results rather than trusting totals cached in an imported file.

### Change the Structure

Insert and delete table rows and columns with the methods of the table: [insertRows](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/insertrows-method/llms-full.txt), [deleteRows](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/deleterows-method/llms-full.txt), [insertColumns](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/insertcolumns-method/llms-full.txt) and [deleteColumns](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/deletecolumns-method/llms-full.txt). Row indices are zero-based and count the data rows only.

- **What a structure change keeps.** Supported identities are retained and references are adjusted.
- **What it rejects.** Invalid bounds, protection, split ranges and worksheet overflow reject the operation.
- **Removing every column** removes the table.
- **Converting to a range** with [remove](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/remove-method/llms-full.txt) keeps the content and formatting but removes the operational table object.
- **Resizing** with [resize](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/table/resize-method/llms-full.txt) must leave a valid range that does not overlap another one.

Tables are useful sources for [dashboards](https://docs.textcontrol.com/tx-sheet-control/dashboards/creating/llms-full.txt), because their fields have stable identities.

### Custom Table Recipes

Excel custom table styles retain their named role recipes, including header and totals rows, row and column stripes and internal borders. Author the same recipes using `customStyle` when adding or updating a table. Direct cell formatting takes precedence; conditional formatting has highest priority. Changing the selected style does not rewrite cell contents.

```javascript
const sheet = book.sheets.at(0);
sheet.range('A1:B4').setValues([['Category', 'Amount'], ['Site', 500], ['Food', 20], ['Program', 30]]);
const table = sheet.tables.add('BudgetLines', 'A1:B4', {
    style: 'Budget', showRowStripes: true,
    customStyle: { name: 'Budget', elements: [
        { type: 'wholeTable', formatting: { fillColor: '#f2f2f2',
            borderEdges: { horizontal: { style: 'thin', color: '#3c7e51' } } } },
        { type: 'headerRow', formatting: { bold: true, fillColor: '#a4d4b4' } },
        { type: 'firstRowStripe', size: 2, formatting: { fillColor: '#d1e8d8' } }
    ] }
});
```

Recipes accept up to thirteen unique roles, with stripe sizes from 1 to 4096. Their names must match the selected style. XLSX writes native custom table definitions; ODS also writes the resolved cell appearance; TXWB retains editable recipes. PDF uses the same display-style pipeline.

### Next Steps

- [Sorting and Filtering](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/sorting-filtering/llms-full.txt): sort, filter and transform the data of a table.
- [Creating Dashboards](https://docs.textcontrol.com/tx-sheet-control/dashboards/creating/llms-full.txt): use a table as the source of a dashboard.
- [XLSX Compatibility](https://docs.textcontrol.com/tx-sheet-control/document-processing/xlsx-compatibility/llms-full.txt): check how tables and their styles survive the exchange with Excel.

---

## Nearby

- **Previous:** [Dates and Locales](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/dates/llms-full.txt)
- **Next:** [Sorting and Filtering](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/sorting-filtering/llms-full.txt)
