Introduction
Google Docs and Google Slides are powerful tools for creating documents and presentations, but repetitive tasks like cleaning up tables can become a time‑consuming hassle. One common annoyance is the presence of blank rows that linger after data imports, copy‑pastes, or collaborative edits. While manually deleting each empty row works for tiny tables, it quickly becomes impractical for larger files or multiple tables spread across a document or slide deck. Fortunately, Google Apps Script—Google’s cloud‑based JavaScript platform—offers a programmable solution that can scan any table, identify rows without content, and remove them in seconds. This article walks you through the entire process, from preparing your document to writing, testing, and extending the script for both Docs and Slides, ensuring a clean, professional look without manual effort.
Understanding Blank Rows in Google Docs Tables
Blank rows are not merely rows that appear empty; they often contain invisible characters, spaces, or line breaks that prevent simple detection. In Google Docs, a row is considered “blank” when every cell’s text content is an empty string after trimming whitespace. Recognizing this nuance is crucial because a naïve script that checks only cell.getText() may miss rows that look empty to the eye but actually contain hidden characters. By standardizing the check to cell.getText().trim() === '', the script reliably distinguishes truly empty rows from those with hidden data, ensuring that only the intended rows are removed.
Preparing Your Document for Script Automation
Before diving into code, organize your document to make the script’s job easier. Follow these steps:
- Give each table a unique identifier using a heading or a comment; this allows selective processing if you don’t want to affect every table.
- Remove any merged cells temporarily, as merged cells can cause indexing errors during row deletion.
- Save a backup copy of the document; Apps Script actions are irreversible without version history.
Having a clean, well‑structured document reduces the risk of unexpected behavior and simplifies debugging later on.
Writing the Apps Script to Remove Blank Rows
The core of the solution is a short script that loops through every table, examines each row, and deletes those that meet the blank‑row criteria. Below is a concise example you can paste into the Apps Script editor (Tools → Script editor):
- Access the body:
var body = DocumentApp.getActiveDocument().getBody(); - Iterate over tables:
var tables = body.getTables(); - Check rows from bottom up: Deleting rows from the end prevents index shifting.
- Trim cell content:
cell.getText().trim()ensures hidden spaces are ignored.
After saving, run removeBlankRows() and grant the required permissions. The script will automatically clean every table in the active document, leaving only rows that contain visible data.
Extending the Script to Google Slides Tables
Google Slides stores tables differently, but the same logic applies. Replace the Docs‑specific calls with Slides equivalents: retrieve the active presentation, loop through each slide, then each Table shape, and finally each row. Because Slides tables lack a direct getTables() method, you must filter shapes by shape.getTable(). The row‑deletion loop remains identical—iterate backwards, trim each cell’s text, and delete the row when all cells are empty. Adding this block to the same script file enables a single “clean‑up” function that works across both Docs and Slides, streamlining workflow for users who maintain parallel documents and presentations.
Running, Testing, and Troubleshooting
Once the script is in place, perform a controlled test on a copy of your document. Verify that:
- No non‑blank rows were inadvertently removed.
- All tables, including those nested in sections or footnotes, are processed.
- The script runs without exceeding Google’s execution time limits (typically 6 minutes for simple loops).
If you encounter issues, use Logger.log() to output row indices and cell contents during execution. Common pitfalls include hidden characters that aren’t trimmed, merged cells that throw index errors, and read‑only slides that require additional permissions. Adjust the script accordingly, and re‑run until the desired clean result is achieved.
Conclusion
Removing blank rows from tables in Google Docs and Slides no longer needs to be a manual chore; a well‑crafted Apps Script can automate the process across entire documents and presentations. By first understanding how blank rows are defined, preparing your files for automation, and implementing a robust script that checks each cell’s trimmed text, you ensure accurate deletions without affecting valid data. Extending the same logic to Slides broadens the utility, giving you a single tool for all Google Workspace table clean‑ups. With careful testing and troubleshooting, the script becomes a reliable part of your workflow, saving time and keeping your documents polished and professional.









