Instantly Create a Clickable Table of Contents in Google Docs with Apps Script

If you work with long Google Docs—guides, reports, lesson plans, ebooks, or AI-generated drafts—navigation quickly becomes painful. Headings exist… but readers still scroll endlessly. In this post, we’ll build a smart Apps Script that: ✅ Scans all headings in a document✅ Automatically generates a clickable Table of Contents✅ Inserts it at the top of the … Read more

100 Advanced Google Apps Script Examples

https://github.com/lsvekis/100-Advanced-Google-Apps-Script-Examples A) Sheets: Performance, Data Ops, Automation (1–25) 1) Batch update with RangeList (fast formatting) Does: Applies formatting to many ranges in one go. 2) Write values + formulas in one pass Does: Sets values and formulas efficiently. 3) Build an index of unique keys → row numbers Does: Creates a lookup map for fast … Read more

Google Apps Script 50 Exercises Explained Vol 2

1) Custom menu in Google Sheets Does: Adds a menu item so users can click to run functions.How it works: onOpen() runs automatically when the file opens (for editors), and SpreadsheetApp.getUi() adds UI. function onOpen() {   SpreadsheetApp.getUi()     .createMenu(‘Tools’)     .addItem(‘Say Hello’, ‘sayHello’)     .addToUi(); } function sayHello() {   SpreadsheetApp.getUi().alert(‘Hello from Apps Script!’); } 2) Show a toast … Read more

Google Apps Script 50 Exercises Explained Vol 1

https://github.com/lsvekis/Apps-Script-Code-Examples 1) Add a Custom Menu on Open (Sheets) Does: Adds a menu to your spreadsheet UI.Use when: You want easy buttons for scripts. function onOpen() {   SpreadsheetApp.getUi()     .createMenu(‘Tools’)     .addItem(‘Say Hello’, ‘sayHello’)     .addSeparator()     .addItem(‘Run Cleanup’, ‘cleanup’)     .addToUi(); } function sayHello() {   SpreadsheetApp.getUi().alert(‘Hello from Apps Script!’); } function cleanup() {   SpreadsheetApp.getUi().alert(‘Cleanup placeholder.’); } 2) Show a … Read more

Docs Service vs Apps Script Why it works

Why Google Apps Script Couldn’t Convert My H2 Headings (and the Fix That Actually Works) If you’ve ever tried to programmatically convert Heading 2 → Heading 3 in Google Docs using Apps Script, you probably expected something simple like: And yet… nothing happened.Or worse: Exception: Unexpected error while getting the method or property setHeading on … Read more

How to Chunk Google Apps Script Code to Avoid Exceeded Maximum Execution Time

https://github.com/lsvekis/Apps-Script-Code-Snippets/tree/main/google-apps-script-chunking-pattern If you’ve ever run a Google Apps Script and hit this dreaded error: Exceeded maximum execution time —you’re not alone. This happens a lot when working with Google Docs, Sheets, Drive, or Gmail, especially when looping through large documents, spreadsheets, or folders. The good news?You don’t need to rewrite everything or give up on … Read more

Auto-Timestamp Rows in Google Sheets with Apps Script (When Status Changes)

https://github.com/lsvekis/Apps-Script-Code-Snippets If you use Google Sheets for workflows—submissions, approvals, task tracking, content pipelines—one thing always comes up: “When did this actually happen?” You can add timestamps manually, but: In this tutorial, you’ll create an Apps Script that automatically: ✅ Adds a timestamp when a row becomes Submitted / Complete / Approved✅ Only sets the timestamp … Read more

Automatically Protect Finalized Rows in Google Sheets with Apps Script

https://github.com/lsvekis/Apps-Script-Code-Snippets Accidentally overwriting data is one of the most common problems in shared Google Sheets. Someone edits a completed row.A formula gets replaced.A “final” value quietly changes. Google Sheets has Protected Ranges, but managing them manually doesn’t scale. In this tutorial, you’ll build a Google Apps Script that: ✅ Watches for edits✅ Detects when a … Read more

Highlight Duplicates Above in Google Sheets with Apps Script

https://github.com/lsvekis/Apps-Script-Code-Snippets Duplicates in a spreadsheet aren’t always “bad”—but sometimes they’re a sign of a problem. A common pattern is: you want values to be unique as you enter them, and if someone repeats a value that already appeared earlier in the same column, you want an instant visual warning. In this tutorial, you’ll build an … Read more

Built a Google Docs AddOn from Scratch

How to Build a Google Docs Add-On with Apps Script (Step-by-Step) https://github.com/lsvekis/Google-Docs-Addon Google Docs is incredibly powerful—but when documents are copied from Word, PDFs, LMS systems, or email, formatting quickly turns into chaos. Instead of fixing formatting manually every time, you can build a Google Docs Add-on using Google Apps Script that runs directly inside … Read more