Get the FREE Ultimate OpenClaw Setup Guide →
l

Skill to manage and update google sheet

Scanned

@longmaba

npx machina-cli add skill @longmaba/google-sheet --openclaw
Files (1)
SKILL.md
4.0 KB

Google Sheets Skill

Interact with Google Sheets using a service account.

Setup (One-time)

  1. Google Cloud Console:

    • Create/select a project
    • Enable "Google Sheets API"
    • Create a Service Account (IAM → Service Accounts → Create)
    • Download JSON key
  2. Configure credentials (one of these):

    • Set env: GOOGLE_SERVICE_ACCOUNT_KEY=/path/to/key.json
    • Place service-account.json or credentials.json in the skill directory
    • Place in ~/.config/google-sheets/credentials.json
  3. Share sheets with the service account email (found in JSON key as client_email)

  4. Install dependencies:

    cd skills/google-sheets && npm install
    

Usage

node scripts/sheets.js <command> [args]

Commands

Data Operations

CommandArgsDescription
read<id> <range>Read cells
write<id> <range> <json>Write data
append<id> <range> <json>Append rows
clear<id> <range>Clear range

Formatting

CommandArgsDescription
format<id> <range> <formatJson>Format cells
getFormat<id> <range>Get cell formats
borders<id> <range> [styleJson]Add borders
copyFormat<id> <source> <dest>Copy format between ranges
merge<id> <range>Merge cells
unmerge<id> <range>Unmerge cells

Layout

CommandArgsDescription
resize<id> <sheet> <cols|rows> <start> <end> <px>Resize columns/rows
autoResize<id> <sheet> <startCol> <endCol>Auto-fit columns
freeze<id> <sheet> [rows] [cols]Freeze rows/columns

Sheet Management

CommandArgsDescription
create<title>Create spreadsheet
info<id>Get metadata
addSheet<id> <title>Add sheet tab
deleteSheet<id> <sheetName>Delete sheet tab
renameSheet<id> <oldName> <newName>Rename sheet tab

Examples

# Read data
node scripts/sheets.js read "SPREADSHEET_ID" "Sheet1!A1:C10"

# Write data
node scripts/sheets.js write "SPREADSHEET_ID" "Sheet1!A1:B2" '[["Name","Score"],["Alice",95]]'

# Format cells (yellow bg, bold)
node scripts/sheets.js format "SPREADSHEET_ID" "Sheet1!A1:B2" '{"backgroundColor":{"red":255,"green":255,"blue":0},"textFormat":{"bold":true}}'

# Copy format from one range to another
node scripts/sheets.js copyFormat "SPREADSHEET_ID" "Sheet1!A1:C3" "Sheet1!D1:F3"

# Add borders
node scripts/sheets.js borders "SPREADSHEET_ID" "Sheet1!A1:C3"

# Resize columns to 150px
node scripts/sheets.js resize "SPREADSHEET_ID" "Sheet1" cols A C 150

# Auto-fit column widths
node scripts/sheets.js autoResize "SPREADSHEET_ID" "Sheet1" A Z

# Freeze first row and column
node scripts/sheets.js freeze "SPREADSHEET_ID" "Sheet1" 1 1

# Add new sheet tab
node scripts/sheets.js addSheet "SPREADSHEET_ID" "NewSheet"

Format Options

{
  "backgroundColor": {"red": 255, "green": 255, "blue": 0},
  "textFormat": {
    "bold": true,
    "italic": false,
    "fontSize": 12,
    "foregroundColor": {"red": 0, "green": 0, "blue": 0}
  },
  "horizontalAlignment": "CENTER",
  "verticalAlignment": "MIDDLE",
  "wrapStrategy": "WRAP"
}

Border Style

{
  "style": "SOLID",
  "color": {"red": 0, "green": 0, "blue": 0}
}

Border styles: DOTTED, DASHED, SOLID, SOLID_MEDIUM, SOLID_THICK, DOUBLE

Finding Spreadsheet ID

From URL: https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit

Troubleshooting

  • 403 Forbidden: Sheet not shared with service account email
  • 404 Not Found: Wrong spreadsheet ID or sheet name

Source

git clone https://clawhub.ai/longmaba/google-sheetView on GitHub

Overview

This skill lets you read, write, append, and manage Google Sheets using the Google Sheets API via a Node.js SDK. It enables automated spreadsheet workflows for data updates, formatting, and sheet management. A Google Cloud service account with the Sheets API enabled is required, and sheets must be shared with the service account email.

How This Skill Works

Interact with Google Sheets through a Node.js script (scripts/sheets.js) using commands like read, write, append, and format. It authenticates with a service account by loading a JSON key either from an environment variable or a credentials file, and communicates with the Sheets API to perform the requested operations on specified ranges and sheets.

When to Use It

  • Automating data imports from apps into spreadsheets for dashboards
  • Programmatically updating values and applying formats to reports
  • Appending new rows from forms or logs to a sheet
  • Batch formatting, borders, and layout adjustments for consistent reports
  • Managing sheets by creating, renaming, or deleting tabs for new projects

Quick Start

  1. Step 1: Create a Google Cloud project, enable Google Sheets API, and create a Service Account; download the JSON key
  2. Step 2: Configure credentials (set GOOGLE_SERVICE_ACCOUNT_KEY or place key in the skill folder) and share the sheet with the service account email
  3. Step 3: Install dependencies and run a sample command, e.g. node scripts/sheets.js read "SPREADSHEET_ID" "Sheet1!A1:C10"

Best Practices

  • Securely store and rotate the service account key; avoid embedding it in code
  • Share each target sheet with the service account email from the key
  • Use batch operations and proper A1 notation to minimize API calls
  • Implement robust error handling and exponential backoff for retries
  • Log access and monitor changes to spreadsheets with appropriate permissions

Example Use Cases

  • Read a range to populate a live dashboard widget
  • Append user form submissions to a central log sheet
  • Format a range to highlight overdue tasks with color and bold text
  • Copy formatting from one range to another to maintain style consistency
  • Create a new sheet tab and initialize headers for a new project

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers