Author: By Raj

Part of our Google Sheets Automation Expert guides. Need this built for your team? Hire a Google Apps Script developer.

Estimated reading time: 10 minutes

Auto-Import CSV Files into Google Sheets with Apps Script

Operations teams drop CSV exports into a Drive folder expecting Google Sheets to ingest them without manual Import menu clicks. Apps Script watches the folder with time-driven triggers and parses blobs.

Use DriveApp.getFolderById or Advanced Drive API for shared drives. Parse CSV with Utilities.parseCsv(blob.getDataAsString()) and map columns explicitly, never assume column order from vendors.

Idempotency requires a file ID or hash column in a ProcessedFiles tab. Related: /blog/apps-script-google-drive-file-organizer for sorting uploads before import.

Folder watch pattern

Each run lists folder.getFiles() iterator, skips files whose ID exists in ProcessedFiles, imports new ones, then logs ID and timestamp.

Cap files per run to stay under execution limits, resume next hour via Script Properties cursor.

Parsing and type coercion

Trim headers, normalize time zones on date columns, and convert currency strings with replace(/[^0-9.-]/g,'') before writing numbers.

Write to Staging, validate, then append to Production with setValues.

Scheduling and failure alerts

Hourly triggers balance freshness vs quotas. On failure, email admin with file name and stack trace row in RunLog.

If CSVs arrive via SFTP external to Google, land them with Drive desktop sync first.

Schema drift handling

When vendors add columns, map by header name not index. Unknown headers go to an Exceptions sheet for manual review.

Version your mapping object in Script Properties JSON for quick hotfixes without redeploying code.

Example code

function importNewCsvFromInbox() {
  const folder = DriveApp.getFolderById('FOLDER_ID_HERE');
  const dest = SpreadsheetApp.getActive().getSheetByName('Staging');
  const files = folder.getFilesByType(MimeType.CSV);
  while (files.hasNext()) {
    const file = files.next();
    const rows = Utilities.parseCsv(file.getBlob().getDataAsString());
    dest.getRange(dest.getLastRow() + 1, 1, rows.length, rows[0].length).setValues(rows);
    file.moveTo(DriveApp.getFolderById('ARCHIVE_FOLDER_ID'));
  }
}
ApproachBest forTradeoff
Apps Script nativeGoogle Workspace-centric workflows6-min limit, quotas
Zapier / MakeNo-code, many connectorsPer-task cost, vendor lock-in
Python + CloudHeavy data / MLHosting cost, separate auth
Google Sheets automation expertProduction custom logicBuild cost, you own code

FAQ

Can Apps Script run on file upload instantly?

Drive does not offer per-file triggers to Apps Script. Poll with time-driven triggers or use an external webhook to call your web app doPost.

What about Excel .xlsx files?

Convert to Google Sheets format via Drive API Advanced drive.files.copy with mimeType conversion, or require CSV for simpler parsers.

How do I prevent duplicate rows?

Use a natural key column, Order ID, and skip append if VLOOKUP equivalent in Script finds existing key in Production.

Will large CSVs timeout?

Yes above tens of thousands of rows. Split files upstream or process chunks per run, see /blog/google-apps-script-execution-time-limit.

Can I import from HTTPS URLs?

UrlFetchApp.fetch the URL, parse CSV from response body, same as Drive blobs, watch UrlFetch quotas in /blog/google-apps-script-quotas-and-limits.

Need this done for you? I handle this as part of my consulting work, fixed-price quote within 24 hours.

Book a call with Raj →

Get the full Auto-Import CSV Files into Google Sheets with Apps Script script template

I'll email you a production-ready, commented version you can deploy in 10 minutes.

Need help with this? I handle this as part of my Google Sheets Automation Expert service.

CRM, dashboards, invoices, inventory, and report automation in Sheets.

See how it works →