Get AI summaries of any video or article — Sign up free
MIT App Inventor Google Sheets Tutorial (Easy) - Google Sheets App Inventor (Spreadsheet component) thumbnail

MIT App Inventor Google Sheets Tutorial (Easy) - Google Sheets App Inventor (Spreadsheet component)

Obsidian Soft·
5 min read

Based on Obsidian Soft's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Enable both the Google Sheets API and Google Drive API in Google Cloud Console for the service account to access sheet data.

Briefing

MIT App Inventor’s built-in spreadsheet component can read and modify Google Sheets rows—but only after setting up Google Cloud credentials and wiring the sheet ID and JSON key into App Inventor’s Storage settings. The workflow starts in Google Cloud Console: create a project, enable the Google Sheets API and Google Drive API, then generate a service account key (JSON). That service account email must be granted access to the target Google Sheet via the sheet’s Share dialog. Once the JSON file is uploaded into App Inventor and the spreadsheet ID is pasted, the spreadsheet component becomes usable inside the app.

After setup, the app’s logic centers on treating sheet data as a list of rows. On screen initialization, the app calls “Read Sheet” for the worksheet name (defaulting to “sheet one”). When the “Got Sheet Data” event fires, it clears a global students list and rebuilds it by iterating through each returned row. Each row’s first two columns—name and age—are combined into a single display string using a separator (space-hyphen-space). That combined list then populates a ListView, enabling the UI to show and select entries.

CRUD operations follow a consistent pattern: validate selection, call the appropriate spreadsheet method, then reload the sheet when the operation finishes. The delete button checks the ListView selection index to ensure the user selected a real data row (index > 1), preventing accidental deletion of the header row (column titles). If valid, it calls “Remove Row” with the sheet name and the selected row index; on “Finished Remove Row,” the app reads the sheet again and shows a confirmation alert. If nothing valid is selected, it uses a notifier alert to prompt the user to choose a proper data row.

The save button doubles as both “add” and “update.” It first verifies that both the name and age text boxes are not empty; otherwise it alerts the user to enter both fields. It then uses the ListView selection index to decide whether to insert a new row (selection index == 0) or update an existing one. For adding, it calls “Add Row” with a two-item list containing the entered name and age. For updating, it calls the “Update Row” procedure using the selected row index and the same two-item payload. After “Finished Add Row” or “Finished Write Row,” the app reloads the sheet and clears the input fields.

The update button performs similar validation and selection checks, but it also reconstructs the separate name and age values from the ListView’s joined string. It splits the selected text at the separator (“ - ”) to recover two items, then writes them back into the name and age text boxes so the user can edit. The tutorial closes by noting that the spreadsheet component supports more than row-level CRUD—such as updating specific columns, filtering data, and reading particular cells—once the credential and spreadsheet ID setup is in place.

Cornell Notes

The tutorial shows how to connect MIT App Inventor to Google Sheets using the Storage spreadsheet component. The key steps are enabling the Google Sheets API and Google Drive API in Google Cloud Console, creating a service account, downloading its JSON key, and granting that service account access to the target sheet. In App Inventor, the JSON key is uploaded into the spreadsheet component settings, and the spreadsheet ID is extracted from the sheet URL. The app then reads rows on screen initialization, builds a ListView from the first two columns (name and age), and implements CRUD: delete removes a selected data row (not the header), save adds or updates based on selection index, and update repopulates text boxes by splitting the selected “name - age” string.

What Google Cloud Console steps are required before App Inventor can access a Google Sheet?

A new Google Cloud project is created, then the Google Sheets API is enabled and the Google Drive API is enabled. A service account is created under “Credentials,” and a JSON private key is generated by adding a key (JSON type). The service account email must be added to the Google Sheet via Share as an editor. Without that API enablement plus the sheet permission and JSON key, the App Inventor spreadsheet component cannot authenticate.

How does the app turn Google Sheets rows into something a ListView can display?

On screen initialization, it calls “Read Sheet” for the worksheet name (default “sheet one”). When “Got Sheet Data” returns, it resets a global students list to empty, then iterates through each returned row. For each row, it joins column 1 (name) and column 2 (age) into a single string using a separator like “ - ”. That list of joined strings becomes the ListView elements.

Why does the delete button check the ListView selection index, and what rule does it enforce?

It prevents deleting the header row (column titles). The logic checks that the selection index is greater than one—index 0 means nothing selected, and index 1 corresponds to the header row. Only when selection index > 1 does it call “Remove Row” with the sheet name and the selected row index; otherwise it shows an alert asking for a valid data row.

How does the save button decide between adding a new row and updating an existing one?

It first validates inputs: both name text and age text must be non-empty. Then it checks the ListView selection index. If selection index == 0, it treats the action as an add and calls “Add Row” with a two-item list [name, age]. Otherwise it treats it as an update and calls the “Update Row” procedure using the selected row index with the same [name, age] payload.

How does the update button restore separate name and age values from the ListView selection?

Because the ListView stores a joined string like “name - age,” the update button splits the selected text using the separator. It uses a text split block at “ - ” to produce a two-item list, then assigns the first item to name text and the second item to age text. This reverses the earlier join used when building the ListView.

Review Questions

  1. What exact combination of Google Cloud API enablement, service account permissions, and App Inventor spreadsheet settings is necessary for authentication to work?
  2. Describe the data transformation pipeline from Google Sheets columns to the ListView display string, including the separator.
  3. How do the delete, save, and update buttons each use ListView selection index to avoid touching the header row and to choose the correct spreadsheet operation?

Key Points

  1. 1

    Enable both the Google Sheets API and Google Drive API in Google Cloud Console for the service account to access sheet data.

  2. 2

    Create a service account, download its JSON key, and upload that JSON into App Inventor’s spreadsheet component credentials.

  3. 3

    Grant the service account email editor access to the target Google Sheet via the sheet’s Share settings.

  4. 4

    Extract the spreadsheet ID from the sheet URL and paste it into the spreadsheet component configuration (the ID between the URL path segments).

  5. 5

    On screen initialization, read the sheet and rebuild a ListView-friendly list by joining the first two columns (name and age) with a consistent separator.

  6. 6

    Use ListView selection index checks to prevent deleting or updating the header row; require selection index > 1 for delete.

  7. 7

    Implement save as add-or-update by branching on selection index, then reload the sheet after the corresponding finished event.

Highlights

The spreadsheet component becomes functional only after enabling APIs, generating a service account JSON key, and granting that service account access to the sheet.
ListView entries are built by joining name and age into a single string (e.g., “name - age”), which later must be split to repopulate text boxes.
Delete is guarded by selection index > 1 to avoid removing the header row.
Save uses selection index == 0 to add a new row and otherwise updates the selected row, with input validation for both fields.

Topics

  • Google Sheets API Setup
  • MIT App Inventor Spreadsheet Component
  • Service Account JSON Credentials
  • ListView Data Binding
  • CRUD Operations in App Inventor