Google Sheets
Latest: v1.0.8
- Improved documentation for Google Sheets secure management commands.
- Added detailed usage examples for creating, reading, writing, and managing spreadsheets, tabs, and sharing.
- Clarified environment variables and authentication methods.
- Included explanation of key command-line flags and parameters.
- Provided advanced usage notes, best practices, and troubleshooting tips for efficient Sheets operations.
Full description
Google Sheets Secure Management. Use when the user wants to create, read, write, or append spreadsheet data; manage tabs (read/add/delete); copy spreadsheets; or manage sharing, permissions, renames, and deletes.
porteden sheets
Use porteden sheets for Google Sheets data operations and file management. Use -jc flags for AI-optimized output.
If porteden is not installed: brew install porteden/tap/porteden (or go install github.com/porteden/cli/cmd/porteden@latest).
Setup (once)
- Browser login (recommended):
porteden auth login— opens browser, credentials stored in system keyring - Direct token:
porteden auth login --token <key>— stored in system keyring - Verify:
porteden auth status - If
PE_API_KEYis set in the environment, the CLI uses it automatically (no login needed). - Drive access requires a token with
driveAccessEnabled: trueand a connected Google account with Drive scopes.
Sheets commands (porteden sheets)
Data operations
- Create new spreadsheet (blank):
porteden sheets create --name "Q1 Budget" - Create in folder:
porteden sheets create --name "Data" --folder google:0B7_FOLDER - Create seeded with CSV:
porteden sheets create --name "Sales 2026" --csv-file ./sales.csv - Create seeded with inline CSV:
porteden sheets create --name "Data" --csv "Name,Score\nAlice,95" - Spreadsheet metadata (tabs, dimensions):
porteden sheets info google:SHEETID -jc - Read all tabs at once (best for AI agents — single upstream call):
porteden sheets content google:SHEETID -jc - Read all tabs with row cap:
porteden sheets content google:SHEETID --max-rows 500 -jc - Read specific ranges (no per-tab cap):
porteden sheets content google:SHEETID --ranges "Summary!A1:C100,Raw Data!A:Z" -jc - Read cell range (single range):
porteden sheets read google:SHEETID --range "Sheet1!A1:C10" -jc - Read whole sheet (single tab):
porteden sheets read google:SHEETID --range "Sheet1" -jc - Write cells (JSON):
porteden sheets write google:SHEETID --range "Sheet1!A1:B2" --values '[["Name","Score"],["Alice",95]]' - Write cells (CSV string):
porteden sheets write google:SHEETID --range "Sheet1!A1:B2" --csv "Name,Score\nAlice,95" - Write cells (CSV file):
porteden sheets write google:SHEETID --range "Sheet1!A1" --csv-file ./data.csv - Batch write multiple ranges (one atomic call):
porteden sheets write google:SHEETID --updates '[{"range":"Summary!A1:B1","values":[["Metric","Value"]]},{"range":"Detail!A1","values":[["x"]]}]' - Append rows (JSON):
porteden sheets append google:SHEETID --range "Sheet1!A:B" --values '[["Bob",87]]' - Append rows (CSV):
porteden sheets append google:SHEETID --range "Sheet1!A:B" --csv "Bob,87"
Tab management
- Read one tab in full (single call, no A1 range to compute):
porteden sheets read-tab google:SHEETID --title "Q2 Forecast" -jc - Read tab by numeric id:
porteden sheets read-tab google:SHEETID --sheet-id 0 -jc - Add a tab:
porteden sheets add-tab google:SHEETID --title "Q2 Forecast" - Add a tab with dimensions/position:
porteden sheets add-tab google:SHEETID --title "Q2 Forecast" --rows 200 --cols 12 --index 2 - Delete a tab by title:
porteden sheets delete-tab google:SHEETID --title "Q2 Forecast" -y - Delete a tab by id:
porteden sheets delete-tab google:SHEETID --sheet-id 1843502915 -y
File management
-
Copy (duplicate) the spreadsheet:
porteden sheets copy google:SHEETID --name "Q2 Forecast (copy)" -
Copy into a folder:
porteden sheets copy google:SHEETID --folder google:0B7_FOLDER -
Get export links (xlsx, pdf, csv):
porteden sheets download google:SHEETID -jc -
Share:
porteden sheets share google:SHEETID --type user --role writer --email user@example.com -
Share publicly:
porteden sheets share google:SHEETID --type anyone --role reader -
List permissions:
porteden sheets permissions google:SHEETID -jc -
Rename:
porteden sheets rename google:SHEETID --name "Q2 Budget" -
Delete (trash):
porteden sheets delete google:SHEETID -y
Range format
- Full range:
Sheet1!A1:C10 - Whole sheet:
Sheet1 - Open-ended (for append):
Sheet1!A:B
Notes
- Credentials persist in the system keyring after login. No repeated auth needed.
- Set
PE_PROFILE=workto avoid repeating--profile. -jcis shorthand for--json --compact: strips noise, limits fields, reduces tokens for AI agents.- File IDs are always provider-prefixed (e.g.,
google:1BxiMVs0XRA5...). Pass them as-is. - Prefer
porteden sheets contentover multipleporteden sheets readcalls when you need more than one tab — it returns every tab in a single upstream call. porteden sheets contentis capped at 200 rows × 26 columns per tab by default. Tabs with more data come back markedclipped: truewith afullRangestring you can feed straight intoporteden sheets read --range <fullRange>to drill in. Use--max-rows 5000to raise the cap, or--rangesto pass explicit A1 ranges with no cap.porteden sheets createaccepts optional--csv/--csv-fileto seed the first tab. Without them a blank spreadsheet is created. Both flags are mutually exclusive.- CSV-seeded spreadsheets get a tab named after the file, not
Sheet1. When Drive imports CSV the resulting tab takes the file's name (e.g.,--name "Q1 Numbers"→ tab titleQ1 Numbers). Range examples below default toSheet1!...which only works on truly blank spreadsheets created via the Google Sheets UI. For CSV-seeded sheets, first callporteden sheets info <id> -jcto discover the actual tab names, then quote them in your range:'Q1 Numbers'!A1:C10. - On
sheets write/sheets append:--values,--csv, and--csv-fileare mutually exclusive — provide exactly one. - Batch write (
sheets write --updates): a JSON array of{"range","values"}objects, written in one atomic call (a bad range fails the whole batch — no partial writes). Up to 50 ranges / 50,000 cells.--updatesis mutually exclusive with--range/--values/--csv/--csv-file;--rawstill applies request-wide. Prefer it over multiplesheets writecalls when populating several tabs/ranges at once. sheets read-tabandsheets delete-tabtake exactly one of--titleor--sheet-id.--sheet-id 0is valid (the first tab is often sheetId 0).read-tabreturns the tab's entire used range — no A1 range needed.add-tabreturns the new tab'ssheetId; titles must be unique within the spreadsheet.sheets copyduplicates the whole spreadsheet (not idempotent — calling twice makes two copies) and returns the new file's id. It's a wrapper overdrive copy.--csvinline: use\nas row separator (e.g.,"Name,Score\nAlice,95\nBob,87").--rawflag disables formula evaluation (values written literally, not parsed as formulas).porteden sheets downloadreturns URLs only — no binary content is streamed.accessInfoin responses describes active token restrictions.deletemoves to trash (reversible). Files can be restored from Google Drive trash.- Confirm before sharing or deleting.
- Environment variables:
PE_API_KEY,PE_PROFILE,PE_FORMAT,PE_COLOR,PE_VERBOSE.
