Sub topic 10
Pulling a CSV from a URL with IMPORTDATA
Prerequisites: you should know how to enter formulas, work with sheets and ranges, and recognize a CSV file. You also need a public URL that points directly to a CSV or TSV file.
IMPORTDATA is a Google Sheets function that downloads delimited text from a URL and places the result into the cells below and to the right of the formula. A comma-separated values (CSV) file uses commas between fields. A tab-separated values (TSV) file uses tabs.
How IMPORTDATA works
Enter the function in an empty cell:
=IMPORTDATA("https://example.com/data.csv")Sheets requests the file, reads its rows, separates each row into columns, and spills the result into the sheet. “Spill” means that one formula fills a larger range automatically.
The URL must be reachable without a sign-in, browser session, or special permission. A link to a web page that displays a CSV is not always sufficient. The link should return the file itself.
Place the formula where the imported data can expand. Existing values in the spill area can prevent the import or cause an overwrite warning. A common pattern is to use a separate sheet named RawImport for the formula.
Choosing the delimiter
The first argument is the URL. The optional second argument specifies the delimiter:
=IMPORTDATA("https://example.com/data.csv", ";")Use the second argument when the file uses semicolons or another delimiter instead of commas. For a TSV file, use a tab character as the delimiter. If the file has inconsistent separators, quoted fields, or embedded line breaks, IMPORTDATA may not parse it as expected.
A delimiter is a character that separates fields. It is different from the spreadsheet locale, which controls conventions such as decimal marks and date formats.
Type conversion and data risks
IMPORTDATA interprets values as it loads them. A value such as 42 may become a number. A value such as 2026-11-28 may become a date, depending on the spreadsheet locale and the input format. A code such as 00127 may become the number 127, losing its leading zeros.
Because IMPORTDATA does not provide the import dialog's text-conversion option, treat the imported range as an input layer. Keep the original formula available, then create cleaned or typed columns beside it.
For example, if column A contains five-digit postal codes and the import converted them to numbers, restore the display with:
=TEXT(A2, "00000")If imported text contains unwanted spaces, trim it in a separate column:
=ARRAYFORMULA(TRIM(A2:A))These formulas create derived values. They do not change the source file or alter the original imported range.
Refreshing and troubleshooting
Sheets can refresh an external import when the formula recalculates, but the update is not an immediate, user-controlled synchronization service. If the source changes, allow time for Sheets to fetch the new content. Re-entering the formula or editing its URL can trigger a new request, but avoid repeatedly forcing requests.
Check these causes when the import fails:
- The URL requires authentication or redirects to a login page.
- The server blocks automated requests.
- The file is too large or takes too long to download.
- The delimiter does not match the file.
- The source contains malformed quoting or inconsistent rows.
- The imported range is blocked by existing cell contents.
After loading the data, compare the expected row and column counts with the result. Inspect headers, blank rows, dates, decimal values, and identifier columns. Use filters or COUNTIF to find unexpected blanks and duplicates.
Exercise
A semicolon-delimited public file is available at https://example.com/orders.csv. Write an IMPORTDATA formula that loads it into the sheet, and state one risk to check after loading.
Show answer
Use =IMPORTDATA("https://example.com/orders.csv", ";"). Check whether identifiers lost leading zeros or whether dates and decimal values were interpreted using the wrong locale.