The AI Break

The AI Break

Share this post

The AI Break
The AI Break
β˜•πŸ€– Tutorial: How To Use ChatGPT In Google Sheets!

β˜•πŸ€– Tutorial: How To Use ChatGPT In Google Sheets!

PLUS: Just copy and paste the script...

The AI Break's avatar
The AI Break
Dec 12, 2024
βˆ™ Paid
15

Share this post

The AI Break
The AI Break
β˜•πŸ€– Tutorial: How To Use ChatGPT In Google Sheets!
Share

πŸ‘‹ Hi AI Break family! Luis and Rui here with another AI tutorial.

Imagine having the power of ChatGPT right inside your Google Sheets - yes, inside the spreadsheet itself!

In this tutorial, you’ll learn exactly how to bring ChatGPT into Google Sheets using Apps Script and OpenAI’s API.

(full script at the end!)

Why Integrate ChatGPT into Google Sheets?

  • Rapid Content Generation: Draft emails, generate product descriptions, or brainstorm ideas directly within a cell.

  • Data Analysis Aid: Use ChatGPT to summarize text data, explain complex information, or assist with research queries.

  • Custom Solutions: Tailor prompt and response logic to your unique workflowβ€”no more copying and pasting between browser tabs.

What You’ll Need

  1. Google Workspace Account: Ensure you have access to Google Sheets.

  2. OpenAI API Key: Sign up at OpenAI’s platform and retrieve your API key.

    1. Don’t forget to add credits to your Open API account ($5 should be more than enough for testing this)

  3. A Blank Spreadsheet: Start fresh or use an existing spreadsheet that you’d like to add ChatGPT.

Step-by-Step Tutorial

Step 1: Obtain Your OpenAI API Key

  1. Go to the OpenAI API Keys page.

  2. Click "Create new secret key" and copy the generated key. Keep it confidential.

Step 2: Open Your Google Sheets and Access the Script Editor

  1. Open a new or existing Google Sheet.

  2. In the top menu, navigate to Extensions > Apps Script. This will open the Apps Script editor in a new tab.

Step 3: Add the Custom Apps Script

  1. In the Apps Script editor, you’ll see a code window with a default function myFunction(). Delete it.

  2. Paste the code snippet (provided at the end of this tutorial) into the editor.

  3. Important: Replace "YOUR_OPENAI_API_KEY_HERE" in the code with the API key you obtained earlier.

  4. If you want you can change the model here (in this example we are using the chatgpt 4o mini)

Step 4: Save and Deploy the Script

  1. Click the Save icon in the toolbar, or press Ctrl+S (Windows) / Cmd+S (Mac).

  2. This should be enough for you to be able to use the function. If not then run the script once to trigger the authorization process. If prompted, grant the script the necessary permissions.

Step 5: Using the Custom Function in Your Sheet

  1. Return to your Google Sheet.

  2. In any cell, type the following formula:
    =GPT("Your Prompt")

  3. Press Enter and wait a moment. The cell will populate with ChatGPT’s response.

  4. If you want to use ChatGPT with information from other cells just add β€œ& CELL NUMBER” after the prompt like the example below.

  5. And here is the result:

Step 6: Experiment with Different Prompts

  • Try =GPT("Summarize the content of cell” & A1) to quickly summarise the information.

  • Experiment with different topics, tones, and instructions to see what fits best into your workflow.

  • Don’t forget you can easily drag the formula across multiple cells in order to use ChatGPT at scale πŸ˜‰

Step 7: Refining Your Requests

  • Adjust max_tokens to limit the length of replies.

  • Explore additional parameters of the OpenAI API for more control over ChatGPT’s behavior.

ChatGPT Script To Copy and Paste Into GSheets

To integrate ChatGPT, simply paste the following Apps Script code into the Script Editor (which you can access through Extensions β†’ Apps Script):

This post is for paid subscribers

Already a paid subscriber? Sign in
Β© 2025 The AI Break
Privacy βˆ™ Terms βˆ™ Collection notice
Start writingGet the app
Substack is the home for great culture

Share