SheetsBatchUpdateValuesTool()Create a tool from an API key.
Tool for batch updating multiple ranges in Google Sheets efficiently.
Inherits from
SheetsBaseTool.
Updates multiple ranges in a single API call, dramatically improving efficiency.
Tool Output:
success (bool): Whether operation succeeded.
spreadsheet_id (str): The spreadsheet ID.
total_updated_ranges (int): Number of ranges updated.
total_updated_cells (int): Total cells updated across all ranges.
total_updated_rows (int): Total rows updated.
total_updated_columns (int): Total columns updated.
responses (list): Individual results for each range with updated_range
and updated_cells.
Update multiple ranges in one call:
from langchain_google_community.sheets import SheetsBatchUpdateValuesTool
tool = SheetsBatchUpdateValuesTool(api_resource=service)
result = tool.run(
{
"spreadsheet_id": "1TI6vO9eGsAeXcfgEjoEYcu4RgSZCUF4vdWGLBpg9-fg",
"data": [
{
"range": "Sheet1!G1:G3",
"values": [["Status"], ["Active"], ["Active"]],
},
{"range": "Sheet1!H1:H3", "values": [["Country"], ["USA"]]},
{"range": "Sheet1!I1:I3", "values": [["Dept"], ["Eng"]]},
],
}
)Update ranges across different sheets:
result = tool.run(
{
"spreadsheet_id": "1TI6vO9eGsAeXcfgEjoEYcu4RgSZCUF4vdWGLBpg9-fg",
"data": [
{
"range": "Sheet1!A1:A5",
"values": [["Data1"], ["Data2"], ["Data3"]],
},
{"range": "Sheet2!B1:B3", "values": [["Value1"], ["Value2"]]},
],
"value_input_option": "USER_ENTERED",
}
)