Guide
Google Sheets Local AI Assistant Guide
A guide for asking questions, processing selected ranges, and creating formulas with local Ollama from a Google Sheets Apps Script sidebar.
The browser JavaScript inside the sidebar calls the local Ollama API directly.
The Sidebar Origin is displayed so it can be used when configuring OLLAMA_ORIGINS.
Preview the AI result first, then write it only when the selected range fingerprint still matches.
What this generator is for
This generator creates an Apps Script sidebar that connects to Ollama running on the user's local PC for questions, selected-range AI processing, and major formula creation.
It calls /api/tags to list installed models and /api/chat to run Ollama response diagnostics with the selected model.
In edit mode, it reads the current selected range from Google Sheets and shows the A1 notation, size, preview, formula status, and fingerprint in the sidebar.
Selected-range data and instructions are sent from sidebar browser JavaScript to local Ollama. Code.gs does not call localhost, and edit results are written only after user confirmation and fingerprint validation.
Display language selected on the website
Menu display language
Language used for the Google app menu and dialog or panel.
Values checked after setup
Sidebar Origin
Copy the Origin shown in the sidebar when OLLAMA_ORIGINS must be configured.
Installed models
The model list comes from Ollama /api/tags. gemma4:12b-it-q4_K_M is shown as the recommended model.
Ollama response diagnostics
The /api/chat diagnostics send only a tiny prompt and do not read or write sheet data.
Setup steps
Open Apps Script from Google Sheets
Open the Google Sheets file you want to use for the connection test, then open Apps Script from Extensions.
Paste Code.gs
Paste the generated Code.gs into Apps Script. Back up existing code before replacing it.
Create Sidebar.html
Create an HTML file named Sidebar and paste the generated Sidebar.html content.
Create Styles.html and ClientJS.html
Create two more HTML files named Styles and ClientJS, then paste the generated Styles.html and ClientJS.html content.
Review appsscript.json
Enable manifest display in Apps Script project settings, then review and paste the generated appsscript.json if needed.
Save and reload the spreadsheet
Save the Apps Script project and reload Google Sheets. The KOKOCAL Local AI menu appears at the top.
Open the sidebar and test Ollama
Open the local AI assistant from the KOKOCAL Local AI menu, copy the Sidebar Origin if needed, then run the Ollama connection and response diagnostics.
Confirm the selected range
Select cells in Google Sheets, click Confirm selected range in the sidebar, and confirm the A1 range, size, preview, and fingerprint.
Preview the AI result
Enter an instruction, run Process with AI, and confirm that the returned matrix is previewed without changing the sheet yet.
Apply the AI result
Review the preview, click Apply to sheet, and write the result only when the fingerprint and size still match.
Save the implementation guide
After generating the script, use Download setup guide at the top right of the generated result column to save the information needed for setup. Generated results disappear when you leave the page, so saving the guide before setup is recommended.
Post-setup review points
KOKOCAL Local AI menu
Reload the spreadsheet and confirm that the KOKOCAL Local AI menu appears.
Sidebar opens
Choose Open local AI assistant and confirm that the Local AI Assistant sidebar appears.
Sidebar Origin
Confirm that the Sidebar Origin is displayed and can be copied. Use this value when configuring OLLAMA_ORIGINS.
Error while Ollama is stopped
Stop Ollama, run the connection test, and confirm that a helpful connection error appears.
Model list
With Ollama running and the Origin allowed, run the connection test and confirm that models from /api/tags are listed.
Ollama response diagnostics
Select a model, run the Ollama response diagnostics, and confirm that the /api/chat response appears in the sidebar.
Selected range
Select one cell, one column with multiple rows, and a multi-row multi-column range, then confirm that the sidebar shows range metadata and display values.
AI preview
Run a small normalization task and confirm that the result is shown in the preview while the original sheet remains unchanged at this point.
Apply AI result
Apply the preview and confirm that only the current selected range is updated with the AI result.
Fingerprint mismatch block
After previewing, change a source cell or selected range, then confirm that applying is blocked.
No server-side Ollama request
Confirm that Code.gs does not use UrlFetchApp to access http://127.0.0.1:11434.
Notes
Sheet write with confirmation
This script writes the AI result to the current selected range only after preview confirmation. Review the preview before applying and use a file where changes can be reverted if needed.
Important note
Review this point before using the generated script in production.
Review before use
Review this point before using the generated script in production.
Formula and merged cells are blocked
To avoid accidental overwrites, applying the AI result is blocked when the selected range contains formulas or merged cells.
OLLAMA_ORIGINS may be required
If the Apps Script Sidebar Origin is not allowed by Ollama, the browser may block the request with CORS. Use the Sidebar Origin shown in the screen when configuring Ollama.
Browser local network permission
Chrome Local Network Access controls may require permission for loopback access. After allowing it, run the connection test again.
Scope of local AI
AI inference runs on Ollama on the user's PC, but Google Sheets itself is a Google cloud service. Edit mode sends the selected range and instruction to local Ollama to generate a preview, then applies it only after user confirmation.
Ready to generate the script
Connect a Google Sheets sidebar to local Ollama for questions, selected-range AI processing, and formula creation with preview and fingerprint checks.
Guide
Related guides
Review these guides together with this page to make setup and operation smoother.
Getting started
Review the input column, generated result column, code, setup steps, review points, and JSON menu.
Apps Script basics
Review Code.gs, HTML files, saving, first authorization, triggers, and other basics before setup.
Using multiple scripts
Learn how to organize shared functions such as onOpen, menu names, triggers, and permissions when combining generated scripts.