IMPORTDATA, IMPORTXML and IMPORTHTML in Google Sheets
What each built-in import formula reads, how often it refreshes, the errors people hit with them, and when a scheduled import is the better fit.
The four formulas, side by side
Google Sheets has four formulas that fetch data from an address. They look alike and they're easy to mix up:
| Formula | Reads | Syntax | Returns |
|---|---|---|---|
| IMPORTDATA | A CSV or TSV file | IMPORTDATA(url) | The file as rows and columns |
| IMPORTXML | XML, HTML, CSV, TSV, RSS and Atom | IMPORTXML(url, xpath_query, [locale]) | Whatever the XPath query selects |
| IMPORTHTML | A table or list on a web page | IMPORTHTML(url, "table" or "list", index) | That one table or list |
| IMPORTFEED | An RSS or Atom feed | IMPORTFEED(url, [query], [headers], [num_items]) | Feed items: title, summary, address and date |
All four need the full address, including https://, either in quotes or in a cell the formula points to.
IMPORTDATA
The simplest one. Point it at a CSV and the file appears:
=IMPORTDATA("https://example.com/exports/orders.csv")
It's ideal for government data, a supplier's price file, or any system that can publish a CSV at a stable address. It can't send a header, so it can't log in to anything.
IMPORTXML
IMPORTXML runs an XPath query over the page or file and returns what matches. To pull every link on a page, =IMPORTXML("https://example.com", "//a/@href"); to pull the titles from a feed, =IMPORTXML("https://example.com/feed.xml", "//item/title"). It's the most flexible of the four and the most fragile when the page changes shape. Pulling structured XML into proper columns has its own guide: how to import XML into Google Sheets.
IMPORTHTML
IMPORTHTML takes the page, the word "table" or "list", and which one counting from 1. Tables and lists are counted separately, so a page can have both a table 1 and a list 1. =IMPORTHTML("https://example.com/rates", "table", 2) returns the second table on the page.
How often they refresh
Google's help page is specific: IMPORTDATA, IMPORTHTML and IMPORTXML check for updates every hour while the document is open, even if nothing in the sheet changes. Deleting and re-adding the formula, or overwriting it with the same formula, makes it fetch again. Opening or reloading the document does not. IMPORTRANGE, the formula that reads another spreadsheet, runs on its own 30-minute cycle.
The consequence that surprises people: these formulas don't run while nobody has the file open. If the sheet feeds a report someone opens on Monday, the numbers are as old as the last time it was open, until the hourly check catches up. The refresh guide covers the ways to update a closed sheet.
The errors you'll see, and what they mean
- Allow access banner, and #REF! until it's clicked. The first time one of these formulas (or IMAGE) is added or edited in a file, Google shows a banner, because the sheet will send and receive data from outside parties. An editor has to click Allow access; until then every import in the file is blocked. On a phone, Google asks you to switch to the desktop site to allow it. Once allowed it can't be undone, except by restoring an earlier version from version history.
- "Loading data may take a while because of the large number of requests." Too many import formulas across the spreadsheets you created. Google counts usage across all of them, including edits your collaborators make. Fewer formulas, or source addresses that change less often, clear it.
- "This function is not allowed to reference a cell with NOW(), RAND(), RANDARRAY(), or RANDBETWEEN()". Import formulas can't depend on those, directly or through another cell, because they change constantly. TODAY is allowed, since it changes once a day.
- "Result too large" (IMPORTXML). The XPath query matched too much. Make it narrower.
- "Admin has not allowed imports from..." Your Google Workspace admin keeps a list of addresses imports may read. Ask them to add this one.
- Empty results from a page that clearly has a table. The formulas read the HTML the server sends. Many pages draw their tables with JavaScript after they load, so the table isn't in that HTML and there's nothing to import. If the site has a CSV download or an API behind the table, import that instead.
When a scheduled import fits better
The import formulas are the right tool for public files that are already shaped like a table. They run out of road when:
- The data needs a key. Nothing can be sent but the address. A key in the address is a key everyone the sheet is shared with can read.
- The data is JSON. Sheets has no built-in JSON formula; most business app APIs answer in JSON.
- The list has pages. Each formula fetches one address, so it gets the first page only. See API pagination in Google Sheets.
- The sheet needs to be current when it's opened. Formulas only refresh while it's open.
- You need yesterday's numbers too. A formula always shows what the address says now and keeps nothing.
If your sheet already has IMPORTDATA or IMPORTXML formulas, or IMPORTJSON formulas from one of the popular scripts, Cellfetch can find them and turn each one into a saved request that writes to the same place and refreshes on a schedule, or into a =CELLFETCH() formula with the same address. Keys in the addresses move into a connection. IMPORTXML formulas over XML feeds and APIs convert; formulas that scrape web pages stay as they are. For the general picture of calling an API from a sheet, start with how to use an API in Google Sheets.
Questions
How often do IMPORTDATA, IMPORTXML and IMPORTHTML refresh?
About once an hour, and only while the document is open. Reloading the page doesn't make them refresh; changing the formula or a cell it reads does.
Why does my IMPORT formula show #REF! until I click something?
The first time an import formula is added to a sheet, Google shows a banner asking an editor to click Allow access. Until someone does, every import in the file is blocked. It's asked once per file, and only editors can answer it.
Can I use IMPORTDATA with an API that needs a key?
Only if the API accepts the key in the address, and then the key is visible to everyone the sheet is shared with. IMPORTDATA takes one argument, the address, so it can't send a header.
Is there a limit on how many IMPORT formulas a sheet can have?
Google doesn't publish a number. Its help page says that when import functions create too much traffic you get an error asking you to reduce them, and that the limits count everything across the spreadsheets you created, including edits by collaborators.
More guides
From inside a sheet: Extensions > Add-ons > Get add-ons, search Cellfetch, Install. Then Extensions > Cellfetch > Start.