Hourly invoice extraction from Google Drive to Sheets with Gemini

Every hour, new PDF invoices dropped into a Google Drive folder are read by Gemini and appended to a Google Sheets tracker, so finance has a running ledger with zero manual entry.

Deterministic Code
Google DriveGoogle GeminiGoogle SheetsFinanceOperationsDocument ProcessingData Sync
PromptCreate

Build me a code-based workflow that runs on a cron trigger every hour and turns a Google Drive folder full of PDF invoices into a running Google Sheets ledger, with zero manual data entry.

Inputs I'll configure: the Google Drive folder ID for my invoices inbox, the Google Sheets spreadsheet ID for the tracker, the name of the visible tracker tab (e.g. Invoices), and the name of a hidden tab (e.g. _processed) used as a dedupe log. Also let me pick the Gemini model (default to gemini-2.5-pro).

Step 1. Read the last-run watermark. Load the hidden _processed tab from Google Sheets and compute the max modifiedTime already seen, plus the set of Drive file IDs already processed. If the tab is empty, use a watermark of the workflow's first-run timestamp.

Step 2. List new PDFs in Google Drive. Call List Files scoped to the configured folder ID with a q filter that requires mimeType = 'application/pdf', trashed = false, the folder as parent, and modifiedTime > the watermark. Request id, name, modifiedTime, and webViewLink. Skip any file whose ID appears in the processed set.

Step 3. For each unseen PDF, use Google Drive Download File Content to fetch the raw PDF bytes.

Step 4. Extract structured data with Google Gemini Generate Content. Pass the PDF as inline data (base64) with mimeType application/pdf, and use a response schema (responseMimeType application/json + responseSchema) requiring: vendor_name, invoice_number, invoice_date (ISO), due_date (ISO or null), currency (ISO 4217), subtotal (number), tax (number), total (number), and line_items as an array of { description, quantity, unit_price, amount }. Include a short system instruction telling Gemini to return null for missing fields and to never invent values.

Step 5. Append one row per invoice to the tracker tab via Google Sheets Append Values. Columns, in order: Processed At, Source File (a HYPERLINK formula wrapping the Drive webViewLink with the file name as label), Vendor, Invoice Number, Invoice Date, Due Date, Currency, Subtotal, Tax, Total, Line Item Count. Flatten line_items into the row as a Line Item Count only; the full JSON is not needed in the visible tab.

Step 6. Record the file in the hidden _processed tab: append a row with file_id, file_name, modifiedTime, processed_at, and extraction_status (ok | error). If Gemini extraction fails for a file, still record it as an error row so we don't retry every hour, but include the error message and skip the tracker append for that file.

Process files sequentially in modifiedTime order so the watermark advances cleanly. Keep the code deterministic: no free-form agent reasoning, just list, download, extract-with-schema, append. Log the count of new invoices processed at the end of each run.

Additional information

What does this prompt do?
  • Watches a Google Drive folder you designate as your invoices inbox and picks up any new PDF once an hour.
  • Uses Google Gemini to read each invoice and pull out vendor, invoice number, dates, currency, subtotal, tax, total, and line items.
  • Appends one row per invoice to a Google Sheets tracker, including a link back to the original file so finance can open the source in a click.
  • Remembers which invoices it has already handled, so the same PDF never lands in the sheet twice.
What do I need to use this?
  • A Google account with access to the Drive folder where invoices arrive.
  • A Google Sheets tracker where new invoice rows should be appended.
  • A Google Gemini account for reading and extracting data from PDFs.
How can I customize it?
  • Change the schedule from hourly to every 15 minutes, twice a day, or only during business hours.
  • Adjust the fields Gemini extracts, for example adding PO numbers, payment terms, or a category tag.
  • Point the output at a different tracker, or split invoices into separate tabs by vendor or currency.

Frequently asked questions

What file types does it handle?
PDF invoices dropped into the designated Google Drive folder. Scanned PDFs work too, because Gemini can read images inside a PDF.
Will it double-count an invoice if someone edits the file?
No. The workflow keeps a hidden log of processed file IDs, so a file that gets renamed or re-uploaded with the same ID will not be added a second time.
What if Gemini misreads a field on one invoice?
Because every row links back to the source PDF in Drive, finance can spot-check and correct any row in seconds without leaving the sheet.
Do I need a separate OCR tool?
No. Gemini reads the PDF directly, including scanned pages, so there is no separate OCR step to set up.
Can I use this with more than one invoice folder?
Yes. Duplicate the workflow and point each copy at a different folder and tracker, for example one per entity or per region.

Stop retyping invoices into a spreadsheet.

Connect Google Drive, Gemini, and Google Sheets once, and Geni keeps your invoice tracker up to date every hour.