Skip to content

feat(sheets): add table manipulation commands with smart sheet resolution#470

Open
Pedrohgv wants to merge 6 commits intosteipete:mainfrom
Pedrohgv:feat/sheets-table-manipulation
Open

feat(sheets): add table manipulation commands with smart sheet resolution#470
Pedrohgv wants to merge 6 commits intosteipete:mainfrom
Pedrohgv:feat/sheets-table-manipulation

Conversation

@Pedrohgv
Copy link
Copy Markdown

feat(sheets): add table manipulation commands with smart sheet resolution

What is this feature?

Adds comprehensive Google Sheets Tables API support to gogcli. Tables are structured Excel-like data containers with typed columns (dropdowns, dates, percentages), headers, footers, and named references. This feature enables programmatic table creation, data manipulation, and aggregation via the CLI.

Key Features

  • 7 table commands — create, list, get, update, append, clear, delete
  • Smart sheet resolution — create and append tables on any sheet (Sheet1, TestSheet, SalesData)
  • Column types — TEXT, DOUBLE, CURRENCY, DATE, DROPDOWN, PERCENT, and more
  • Footer formulas — automatic preservation when tables expand
  • Named references — use =SUM(TableName[Column]) syntax for formulas
  • Auto-expansion — tables grow automatically when appending beyond capacity
  • Data validation — dropdown columns with custom lists
  • JSON output — machine-readable for scripting

Usage Examples

# Create a table with dropdown and footer
gog sheets table create SPREADSHEET_ID Sheet1!A1:D10 \
  --name "Project Tracker" \
  --columns-json '[{"columnName":"Task","columnType":"TEXT"},{"columnName":"Status","columnType":"DROPDOWN","dataValidation":{"condition":{"type":"ONE_OF_LIST","values":[{"userEnteredValue":"Done"},{"userEnteredValue":"In Progress"}]}}},{"columnName":"Due","columnType":"DATE"},{"columnName":"Complete","columnType":"PERCENT"}]' \
  --footer

# Add data (auto-expands if needed)
gog sheets table append SPREADSHEET_ID TABLE_ID \
  --values-json '[["Design","In Progress","2024-01-15","75%"],["Implement","Done","2024-01-10","100%"]]'

# Add aggregation formulas to footer
gog sheets update SPREADSHEET_ID Sheet1!C10 \
  --values-json '[["=SUM(Project_Tracker[Complete])"]]'

# List all tables
gog sheets table list SPREADSHEET_ID

Implementation Details

Smart Range Parsing: parseA1ToGridRangeWithLookup() resolves sheet names (e.g., "SalesData") to actual sheet IDs using spreadsheet metadata. This ensures tables are created on the correct sheet, not just Sheet1.

Footer Formula Preservation: Before append, captures footer cell formulas. After append, detects table expansion by comparing ranges. If expanded, re-applies formulas to the new footer row location using Values.Update.

Sheet Location Fix: Changed from AppendCellsRequest (which ignored table sheet location) to Values.Append with explicit sheet name in range (SheetName!Col:Col), ensuring data appends to the correct sheet.

Commits

  1. feat(sheets): add table manipulation commands — initial implementation (7 commands, 871 lines)
  2. fix(sheets): correct table append for multiple rows — fixed row flattening bug
  3. fix(sheets): correct table range formatting — use sheet names in A1 notation
  4. fix(sheets): footer update field mask — removed tableId from fields list
  5. feat(sheets): smart range parsing + footer preservation — sheet ID lookup and formula preservation
  6. fix(sheets): make append respect sheet location — fixed critical sheet routing bug

Files Changed

  • internal/cmd/sheets_table.go — new file with all table commands (992 lines)
  • internal/cmd/sheets.go — added Table SheetsTableCmd field

Testing

Comprehensive manual testing performed:

  • ✅ Created tables on multiple sheets (Sheet1, TestSheet, SalesData)
  • ✅ Verified smart range parsing resolves correct sheet IDs
  • ✅ Tested table expansion when appending beyond capacity
  • ✅ Verified footer formulas are preserved after expansion
  • ✅ Tested all 7 commands (create, list, get, update, append, clear, delete)
  • ✅ Tested column types: TEXT, DOUBLE, CURRENCY, DROPDOWN, DATE, PERCENT
  • ✅ Verified data goes to correct sheet (fixed routing bug)

Checklist

  • Code follows project patterns (Kong CLI, error handling, output formatting)
  • All builds pass (make build)
  • Manual testing completed
  • Commits follow conventional commits format
  • No breaking changes to existing functionality

…ate, append, clear, delete)

Adds comprehensive support for Google Sheets Tables API:
- list: List all tables in a spreadsheet
- get: Get table details with columns and types
- create: Create new tables with column definitions
- update: Modify table properties (name, range, footer)
- append: Add rows to tables (respects footer)
- clear: Clear table contents
- delete: Delete tables (or unformat to keep data)

Table IDs are handled as strings per API spec.
Column types supported: TEXT, NUMBER, DATE, DROPDOWN,
CHECKBOX, PERCENT, RATING, CURRENCY, DATE_TIME, TIME, SMART_CHIP
Fixes bug where all rows were flattened into a single row.
Now creates separate RowData entries for each input row.
Fixes table clear and other commands that were generating invalid ranges
like 'Sheet0!A1:D10' instead of proper A1 notation 'Sheet1!A1:D10'.

Changes:
- formatGridRange() now accepts sheetName parameter
- All callers updated to pass actual sheet name from properties
- Added nil checks for safety
- Fixed Fields() calls to include sheets.properties.title
TableId is an identifier, not an updatable field. Including it in
the fields list caused API errors. Now footer toggle works correctly.
Improvements:
1. Smart Range Parsing: parseA1ToGridRangeWithLookup() resolves sheet names
   to IDs using spreadsheet metadata. Tables now created on correct sheets.

2. Footer Formula Preservation: Before append, captures footer formulas.
   After append, checks if table expanded. If expanded, re-applies formulas
   to new footer row.

- Tables can now be created on any sheet (not just Sheet1)
- Footer formulas automatically preserved when table expands
- Added sheet name resolution helper function
Fixes critical bug where appended data went to Sheet1 instead of
the table's actual sheet (e.g., TestSheet, SalesData).

Changed from AppendCellsRequest (TableId only) to Values.Append
with explicit sheet name in range (SheetName!Col:Col). This ensures
data is appended to the correct sheet location.

Also updates JSON output to use AppendValuesResponse fields.
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.

1 participant