Add rows and tabs to a Google spreadsheet
google_sheets_addAdds rows, columns, duplicated tabs, tables, charts, pivot tables, rules, validation, filters, and metadata to a Google spreadsheet in one atomic batch so all changes apply or none do.
Instructions
Add rows, columns, tabs, tables, conditional rules, data validation, filters, charts, pivot tables and developer metadata to a Google spreadsheet, by spreadsheet (its id or URL): 1 to 100 operations that apply in order as one batch, so all of them land or none does. It never removes or overwrites a cell or an object a person made, but it is not idempotent: applying the same operations again adds again. Each operation is an object with op and its arguments. insert takes a range of whole rows (Plan!5:7) or whole columns (Plan!C:D) and inserts as many empty ones as it spans before them, so the rows or columns named and everything after them shift down or right, and a later operation's range means the cells as they stand by then; inherit (before by default, or after) says whose formatting the new ones take, and the first row or column has none before it. tab_duplicate copies the tab as a new tab, with an optional title (no tab may have it already, ignoring case) and position counted from 0 (left out, right after the original); the result's created lists each new tab's sheet_id, title and index. table makes a native table of range, a closed block with its header row, that overlaps no table; name (default Table1, Table2…), table_columns ({ column, type?, name?, values? }: Google's column type, such as DOUBLE or DROPDOWN with its options in values), header_color, band_colors (one or two) and footer_color are optional, and a column new to the table that is not named keeps its header cell's text as its name; the result's tables lists each new table's table_id, name and range. conditional adds a conditional formatting rule over range or ranges of one tab, as the tab's first rule (the numbers of the others go up by one): either when (Google's condition type, such as NUMBER_GREATER) with its values and at least one style of bold, italic, strikethrough, color and background, or scale, two or three colors from the lowest value up. validate sets a data validation rule over range or ranges that have none: when (such as ONE_OF_LIST, whose options are values, or NUMBER_BETWEEN), values, strict (default true: reject other input, false: warn), dropdown (default true) and help; a range that has validation already is refused (google_sheets_restructure's validate_replace replaces it), and so is a range of more than 10,000 cells, which cannot be checked. filter sets the range's tab's basic filter with optional filter_columns ({ column, hide?, when?, values? }: values to hide, or a condition to show by) on a tab that has none (google_sheets_restructure's filter_replace replaces it). filter_view adds a filter view name over range with optional filter_columns; the result's filter_views lists each new view's view_id and title. chart adds a chart of range, a block or whole columns (Sales!A1:C13, Sales!A:C): its first column labels the rows, each other column is a series, and its first row is the header unless header is false; a pie chart takes two columns. chart_type (column by default, bar, line, area, scatter, combo or pie), title, legend (bottom by default, top, left, right or none), stacked (bar, column, area and combo charts), width and height in pixels are optional, and the chart sits beside the data unless at (the cell its top-left corner is on) or new_tab: true (a tab of its own) says otherwise; the result's charts lists each new chart's chart_id and title. pivot adds a pivot table of the source range (a block or whole columns with its header row): pivot_rows and pivot_columns (each a column letter, or { column, group?, sort?, label?, totals? } to group dates by a part such as YEAR_MONTH, sort desc, set a heading or hide the totals), pivot_values (at least one { column, summarize?, name? }, or { formula, summarize?, name? } with a formula such as =SUM(Amount) that names the source's columns by their header) and pivot_filters ({ column, show }, the values to keep), placed at the cell at or on a new tab with new_tab: true and an optional title (the result's created lists it). A pivot table's size is unknown until Google computes it, so one placed at at is refused when any cell from there to the tab's last row and column holds a value or a pivot table, and when that is more than 10,000 cells, which cannot be checked. metadata attaches developer metadata to the spreadsheet, a tab, or one row or column: a key (1 to 100 characters), an optional value (up to 2000) and visibility (document by default, which anyone with the file can read, or project, which only the Cloud project that made it can), and on: "spreadsheet", { tab }, or { range } of one whole row or column (Plan!5:5, Plan!C:C; Google marks one at a time); the mark moves with its row or column when it is sorted or moved, so google_sheets_edit's expect can find a row by it. The result's metadata lists each new entry's metadata_id and key. Any other operation is refused. Use google_sheets_tab_add for an empty tab, google_sheets_format for formatting and google_sheets_restructure to delete, move or merge, and to change or remove tables, rules, validation, filters, charts, pivot tables and developer metadata. A call names at most 500 ranges in all. account is needed when several accounts are set up.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"spreadsheet": "<spreadsheet>",
"operations": "<operations>"
},
"name": "google_sheets_add"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account | No | The account's label. Left out, the only account is used; with several accounts, the call fails and lists them. | |
| operations | Yes | 1 to 100 operations, each an object with an `op` (insert, tab_duplicate, table, conditional, validate, filter, filter_view, chart, pivot, metadata) and that operation's arguments; they apply in order, and all of them land or none does. | |
| spreadsheet | Yes | The spreadsheet's id, or its URL (https://docs.google.com/spreadsheets/d/<id>/…). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabs | Yes | The titles of the existing tabs that were changed, left to right. | |
| charts | Yes | The charts the call made, in the order of the operations, as Google answered: id and title. | |
| tables | Yes | The tables the call made, in the order of the operations, as Google answered: id, name and range. | |
| applied | Yes | One line per operation, in order, with its ranges as Google resolves them: what was applied. | |
| created | Yes | The tabs the call created, in the order of the operations that made them, as Google answered. | |
| metadata | Yes | The developer metadata the call made, in the order of the operations, as Google answered: id and key. | |
| requests | Yes | How many requests the operations made up in the one batch. | |
| filter_views | Yes | The filter views the call made, in the order of the operations, as Google answered. | |
| spreadsheet_id | Yes |