The TASK_SHEET_UPDATE function generates a JSON-based task definition to manipulate spreadsheet data using a language model. When executed via the "Run" button in the sidebar, it processes specified ranges according to your prompt and modifies the sheet data intelligently.
=TASK_SHEET_UPDATE(header, range, prompt, [model], [image_url], [additional_sheets], [outputRange], [modify_existing_cells])
Parameter | Data Type | Required | Description |
---|---|---|---|
header | string | Yes | Column header for the task template |
range | string | Yes | The range in the active sheet to operate on (e.g., "A1:B10") |
prompt | string | Yes | Instructions describing what you want to perform (e.g., "Fix any spelling mistakes in this data") |
model | string | No | The name of the language model to use (format: 'provider/model_name'). If not specified, your default model is used |
image_url | string | No | Image to include with the prompt for visual context (for multimodal models) |
additional_sheets | string | No | Additional sheets and their ranges to include as input context, separated by semicolons (e.g., "Sheet2(A1:B5);Sheet3") |
outputRange | string | No | The range where the output should be placed. If not specified, the original range will be used |
modify_existing_cells | boolean | No | If true, existing cells can be modified. If false (default), only blank cells will be updated |
The additional_sheets
parameter lets you include data from other sheets as context for the language model:
"SheetName(A1:B10);AnotherSheet(C1:D5);EntireSheet"
;
) to separate multiple sheets"Sheet2"
"Sheet2(A1:B10)"
The outputRange
parameter determines where modified data appears:
"A1:B10"
(must be a valid A1 notation range)Control whether existing cell content can be changed:
modify_existing_cells = false
(default): Only blank cells will be updatedmodify_existing_cells = true
: All cells in the output range can be modifiedFor multimodal models, the image_url
parameter accepts:
Create a formula that standardizes inconsistent contact information:
=TASK_SHEET_UPDATE("Standardize Contacts", "A2:C20", "Standardize the phone numbers to format (XXX) XXX-XXXX, fix email formatting to lowercase, and ensure names are in Title Case", "Gemini/gemini-1.5-pro")
Use data from another sheet to enrich product descriptions:
=TASK_SHEET_UPDATE("Enhance Descriptions", "B2:B10", "Update these product descriptions to include details from the specifications sheet. Make them more compelling and highlight key features.", "Anthropic/claude-3-5-sonnet", "", "Specifications(A1:F20)")
Transform data based on an image reference:
=TASK_SHEET_UPDATE("Chart Analysis", "C2:C10", "Update these sales projections based on the trend shown in the image. Increase declining categories by 5% and growing categories by 3%", "Gemini/gemini-1.5-pro", "https://drive.google.com/uc?id=YOUR_IMAGE_ID")
Generate content only in empty cells:
=TASK_SHEET_UPDATE("Fill Empties", "A1:B10", "Generate appropriate content for empty cells based on the row context and column headers", "", "", "", "", false)
additional_sheets
, reference only what's needed to avoid overwhelming the modelmodify_existing_cells
to false when you want to preserve existing dataCause: The prompt parameter is empty or undefined.
Solution: Ensure you've included a clear instruction in the prompt parameter.
Cause: The range notation is incorrect or not in A1 format.
Solution: Use standard A1 notation format like "A1:B10" for ranges.
Cause: A sheet name in additional_sheets
doesn't exist in the spreadsheet.
Solution: Double-check the spelling of sheet names and ensure they exist in the current spreadsheet.
Cause: A range specified for an additional sheet is invalid.
Solution: Make sure all ranges use valid A1 notation like "A1:B10".
Cause: The language model failed to process your request properly.
Solution: Check if your API key is valid, try a different model, or simplify your prompt.
Cause: The model output wasn't properly formatted, or modify_existing_cells
is false while trying to modify non-empty cells.
Solution: Set modify_existing_cells
to true if you want to update cells that already have content.
Cause: outputRange
is specified incorrectly or has different dimensions than expected.
Solution: Ensure your output range has appropriate dimensions to accommodate the results.
Choose a model based on your task complexity. For simple text transformations, models like "Gemini/gemini-1.5-flash" are fast and cost-effective. For complex reasoning or creative tasks, use "Anthropic/claude-3-opus" or "OpenAI/gpt-4".
By default, it only modifies data in the range you specify, and only updates blank cells unless you set modify_existing_cells
to true. You can also specify a different outputRange
to leave original data untouched.
This depends on your model's context window. Most modern models can handle hundreds of cells, but extremely large ranges might need to be broken down into smaller chunks. Start with modest ranges (under 100 cells) for best results.
TASK_SHEET_UPDATE works with formula results (displayed values) when reading data, but it will replace formulas with static values when writing. Consider copying formula results to a separate range before processing.
Include example outputs in your prompt, be specific about formatting requirements, and consider creating a dedicated "instructions" cell that's included in your range to give the model clear guidance.
Yes, you need to have configured API keys for the language model provider you intend to use. Set them up in the Sheet Workflows settings before using TASK_SHEET_UPDATE.
The TASK_SHEET_UPDATE formula outputs a JSON string that's stored in the cell. You can copy this cell to save the task configuration, then use it later by clicking "Run" when that cell is selected.
Not directly from cells. You need to use the image_url
parameter with a URL to an externally hosted image or a Google Drive link with proper sharing permissions.
You can always revert changes using Google Sheets' Undo feature (Ctrl+Z/Cmd+Z) or edit the prompt to be more specific and run the task again.
No, TASK_SHEET_UPDATE cannot modify protected ranges or sheets. You'll need to temporarily unprotect them before running the function.
Be explicit in your prompt about the desired format (e.g., "Format dates as MM/DD/YYYY and numbers with two decimal places"). Including examples in your prompt helps ensure consistency.
Yes, you can use TASK_SHEET_UPDATE as part of a larger workflow with other functions. The output from one function can serve as input to another.
1 week ago