A Google Apps Script tool that automatically extracts trivia questions from Google Docs and populates them into Google Sheets.
This script processes trivia question documents stored in Google Drive, extracting three types of questions:
- Bonus Questions (Table 2 → Sheet 0)
- Game One Questions (Table 0 → Sheet 1)
- Game Two Questions (Table 1 → Sheet 2)
Files are marked as "starred" after processing to prevent duplicate entries.
- Automatic Processing: Processes all unstarred files in the "Trivia Questions" folder
- Smart Skipping: Skips header and separator rows specific to each question type
- Error Handling: Continues processing files even if individual files fail
- Duplicate Prevention: Uses file starring to track processed documents
- Date Extraction: Automatically extracts dates from document filenames
- Google Account with access to Google Drive, Docs, and Sheets
- A Google Spreadsheet to store the questions
- A Google Drive folder named "Trivia Questions"
- Open Google Apps Script
- Create a new project
- Copy the contents of
addBonusQuestions.gsinto the script editor - Update the
SPREADSHEET_URLconstant with your target spreadsheet URL - Save the project
Update these constants at the top of the script:
var SPREADSHEET_URL = 'YOUR_SPREADSHEET_URL_HERE';
var FOLDER_NAME = "Trivia Questions";Documents should follow this naming pattern:
[word] [word] [word] MM-DD-YY [...]
Example: Trivia Night Questions 03-15-24 Final
The date (4th space-separated element) will be extracted and parsed.
Each document must contain exactly 3 tables:
- Table 0: Game One Questions
- Table 1: Game Two Questions
- Table 2: Bonus Questions
Each table should have 4 columns of data.
- Open your Google Apps Script project
- Select the
getFilesfunction from the dropdown - Click the "Run" button
- Grant necessary permissions when prompted
Set up a time-driven trigger:
- In Apps Script editor, click the clock icon (Triggers)
- Click "+ Add Trigger"
- Choose
getFilesfunction - Select time-driven trigger type
- Configure your desired schedule (e.g., daily, weekly)
- Scan Folder: Searches for folders named "Trivia Questions"
- Find Unprocessed Files: Iterates through files that aren't starred
- Extract Data: For each file:
- Extracts the date from the filename
- Opens the document and retrieves tables
- Filters out header/separator rows
- Appends question data to the appropriate sheet
- Mark Complete: Stars the file to prevent reprocessing
- Error Handling: Logs errors and continues with remaining files
getFiles()- Main entry point that processes all unstarred filesaddBonusQuestions(file)- Processes bonus questions from Table 2addGameOneQuestions(file)- Processes Game One questions from Table 0addGameTwoQuestions(file)- Processes Game Two questions from Table 1
extractDate(doc)- Parses date from document namegetRowData(row)- Extracts cell text from table rowaddQuestionsToSheet(...)- Generic function for table-to-sheet transfer
Different question types skip different rows:
- Bonus Questions: Skips row 0 (header)
- Game One: Skips rows 0, 1, 7, 13, 14 (headers and separators)
- Game Two: Skips rows 0, 6, 12 (headers and separators)
This script has been optimized for:
- DRY Principle: Consolidated duplicate code into a single generic function
- Maintainability: Configuration constants at the top for easy updates
- Error Resilience: Try-catch blocks prevent individual file failures from stopping batch processing
- Documentation: JSDoc comments for all functions
- Clean Code: Removed commented-out code and improved formatting
Ensure the script has authorization to access:
- Google Drive (read files)
- Google Docs (read content)
- Google Sheets (write data)
Verify filename format matches: ... ... ... MM-DD-YY ...
Ensure documents contain exactly 3 tables in the expected order
The script only processes unstarred files. If you need to reprocess a file:
- Unstar the file in Google Drive
- Run the script again
See LICENSE file for details.
To modify row skipping logic, update these constants:
var SKIP_ROWS_BONUS = [0];
var SKIP_ROWS_GAME_ONE = [0, 1, 7, 13, 14];
var SKIP_ROWS_GAME_TWO = [0, 6, 12];To change which tables map to which sheets, update:
var SHEET_BONUS = 0; // Target sheet index
var TABLE_BONUS = 2; // Source table index