AI for Sheets.

AI Integration for Google Sheets.

This beginner-friendly guide will help you set up AI-powered content generation right in your Google Sheets. No coding experience required!

What You Need Before Starting

  1. A Google account (like the one you use for Gmail)
  2. An OpenAI API key
    • Go to OpenAI's website
    • Click "Sign up" (or "Log in" if you already have an account)
    • Once logged in, click on your profile icon โ†’ "View API keys"
    • Click "Create new secret key"
    • Copy your API key and keep it safe!

Step 1: Create Your Spreadsheet

  1. Go to sheets.google.com
  2. Click the plus icon (+) to create a new spreadsheet
  3. Name your spreadsheet (click "Untitled spreadsheet" at the top)

Step 2: Add the AI Script

  1. Click "Extensions" in the top menu
  2. Click "Apps Script" - this will open a new tab
  3. You'll see a blank file named "Code.gs"
  4. Delete any code that's already there
  5. Copy and paste this code:
Code Preview Download Free GPT Script

The script adds an OpenAI menu to Google Sheets. Select a cell with your prompt, click OpenAI โ†’ Generate Content, and the script uses that selected cell as the input.

Step 3: Add Your API Key

  1. In the code above, find the line with const apiKey = 'sk-your-api-key-here';
  2. Replace sk-your-api-key-here with your actual OpenAI API key (keep the quotes!)
  3. Click the ๐Ÿ’พ Save button (or press Ctrl+S / Cmd+S)

Step 4: First-Time Setup and Authorization

When you first use the script, Google will ask for permissions. Here's what to expect:

  1. Go back to your spreadsheet
  2. Refresh the page - you should see a new "OpenAI" menu at the top
  3. Click "OpenAI" โ†’ "Generate Content"
  4. You'll see a "Authorization Required" popup:
    • Click "Continue"
    • Choose your Google account
    • You'll see a warning saying "Google hasn't verified this app"
    • Click "Advanced" โ†’ "Go to [Your Project Name] (unsafe)"
    • Click "Allow"

These security warnings appear because you're using your own script. It's safe to proceed since you created the script yourself.

How to Use the Script

  1. Set up your spreadsheet:
    • Column A: Your prompts
    • Column B: Will contain AI responses
    • You can add headers if you want (like "Prompt" and "Response")
  2. Using the script:
    • Type your prompt in Column A (example: "Write a short product description for a coffee mug")
    • Click on the cell containing your prompt
    • Click the "OpenAI" menu at the top
    • Wait a few seconds - the response will appear in Column B

Checking Execution Logs

If something goes wrong, you can check the execution logs:

  1. Go back to the Apps Script editor (Extensions โ†’ Apps Script)
  2. Click "View" โ†’ "Execution log" in the menu
  3. Run your script again to see what's happening
  4. You'll see detailed information about:
    • When the script ran
    • Any errors that occurred
    • API responses and issues

Language Models

This script uses GPT-3.5-turbo, which is OpenAI's efficient and cost-effective language model. Key points:

For more details about available models and their capabilities, visit the OpenAI Models Documentation.

Authorization Details

This script is set to only work with the current document. You'll see this in the authorization screen because of these permissions:

Troubleshooting

If you see "Authorization Required" again:

If you get an error about the API key:

If nothing happens when you click "Generate Content":

Code Preview Download Free GPT Script

This version is built around a menu command, not a cell formula. It reads the active cell, checks that it contains text, and runs generateContent() when you choose Generate Content from the menu.

Need Help?

Remember: Keep your API key private and never share it with anyone!

Note: Using the OpenAI API may incur costs. Please refer to the OpenAI API pricing page for more details.

Disclaimer: Users are responsible for how they use information and code provided on this website.

Send Feedback