Skip to content

Add Google Sheets integration with full CRUD operations#8

Merged
plosson merged 1 commit intomainfrom
claude/gsheets-agentio-commands-ucRgp
Jan 27, 2026
Merged

Add Google Sheets integration with full CRUD operations#8
plosson merged 1 commit intomainfrom
claude/gsheets-agentio-commands-ucRgp

Conversation

@plosson
Copy link
Copy Markdown
Owner

@plosson plosson commented Jan 27, 2026

Summary

This PR adds comprehensive Google Sheets support to the CLI, enabling users to manage spreadsheets directly from the command line. The implementation includes OAuth authentication, spreadsheet listing, CRUD operations on cell values, metadata retrieval, and export functionality.

Key Changes

OAuth & Authentication

  • Added gsheets service to OAuth configuration with appropriate scopes for spreadsheet access, Drive file management, and user email retrieval
  • Updated OAuthService type to include 'gsheets'

New Google Sheets Client

  • Created GSheetsClient class (src/services/gsheets/client.ts) implementing the ServiceClient interface
  • Supports all major Sheets API operations:
    • Read: get() - retrieve values from ranges with formatting options
    • Write: update() - replace values, append() - add rows
    • Manage: clear() - clear ranges, metadata() - get spreadsheet structure
    • Create/Copy: create() - new spreadsheets with optional sheets, copy() - duplicate spreadsheets
    • Export: export() - download in multiple formats (xlsx, pdf, csv, ods, tsv)
    • List: list() - search and filter spreadsheets with Drive query syntax
  • Handles spreadsheet ID extraction from URLs and range normalization
  • Comprehensive error handling with user-friendly messages for common API errors (401, 403, 404, 429)

CLI Commands

  • Registered 8 new subcommands under gsheets:
    • list - search spreadsheets with Drive query filters
    • get - retrieve cell values with render options
    • update - modify cell values with input options
    • append - add rows with insert strategies
    • clear - clear cell ranges
    • metadata - view spreadsheet structure
    • create - create new spreadsheets with optional sheet names
    • copy - duplicate spreadsheets to folders
    • export - download in various formats
    • profile add - authenticate and configure profiles

Value Parsing

  • Implemented flexible value input supporting two formats:
    • Simple: Comma-separated rows, pipe-separated cells (e.g., "a|b,c|d")
    • JSON: 2D arrays via --values-json flag
  • Comprehensive help text with examples for each command

Type Definitions

  • Created src/types/gsheets.ts with complete type definitions for credentials, operations, and results
  • Updated ServiceName type to include 'gsheets'
  • Updated config interface to support gsheets profiles

Output Formatting

  • Added 7 specialized output formatters in src/utils/output.ts:
    • printGSheetsList() - formatted spreadsheet listings
    • printGSheetsMetadata() - spreadsheet structure display
    • printGSheetsValues() - tab-separated cell values
    • printGSheetsUpdateResult() - update operation summary
    • printGSheetsAppendResult() - append operation summary
    • printGSheetsClearResult() - clear operation confirmation
    • printGSheetsCreated() - creation/copy result display

Notable Implementation Details

  • URL Handling: Supports both spreadsheet IDs and full Google Sheets URLs
  • Range Normalization: Handles shell escaping of ! character in A1 notation
  • Profile Management: Auto-detects profile name from user email if not specified
  • Query Syntax: Full Drive API query support for advanced filtering (ownership, dates, names)
  • Export Formats: Supports 5 export formats with appropriate MIME types
  • Error Recovery: Distinguishes between token expiration and permission issues

https://claude.ai/code/session_01LLvpSDsbSSEpfR2jh6g9Nu

Implements Google Sheets integration based on gogcli's sheets functionality:
- list: List recent spreadsheets
- get: Get values from a range
- update: Update values in a range
- append: Append values to a range
- clear: Clear values in a range
- metadata: Get spreadsheet metadata (sheets, properties)
- create: Create a new spreadsheet with optional sheet names
- copy: Copy a spreadsheet (via Drive API)
- export: Export to xlsx/pdf/csv/ods/tsv formats

Features:
- Supports both simple value format (pipe/comma delimited) and JSON arrays
- URL or ID input for spreadsheet identification
- OAuth integration with Sheets and Drive APIs
- Profile management with auto-detected email naming

https://claude.ai/code/session_01LLvpSDsbSSEpfR2jh6g9Nu
@plosson plosson merged commit ecc5a33 into main Jan 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants