Comment utiliser la formule IMPORTHTML de Google Sheets ?

Si vous voulez pull online data into Google Sheets from a website, IMPORTHTML Google Sheets formula is a great tool to have up your sleeve. It imports data from a table ou liste on any webpage without you having to copy-paste or adjust the data using other formulas.

Copy-pasting tabular data from the internet into a spreadsheet can generate formatting issues. For this reason, IMPORTHTML is an easier way to import data from sites like Wikipedia directly into your spreadsheet while retaining the correct layout. In addition, this formula ensures your data is always up-to-date. Google Sheets updates in real time, pulling live data directly into your spreadsheet. When the website is updated, your Google Sheet is updated automatically too. Here’s how to use the formula.

Syntaxe

IMPORTHTML(url, query, index)

  • url – this is the address (uniform resource locator) of the web page containing the table or list you want to import. This can take two forms.
    • Un emplacement valide et entièrement qualifié sous forme de texte (entre guillemets). Par exemple : “https://en.wikipedia.org/wiki/Demographics_of_the_world”
    • Or it can be a reference to a cell (such as B1) dans Google Sheets, où l'URL est stockée.
  • interrogation – this will be either “list” or “table” depending upon the structure of the data.
  • index – the index number identifies the list or table within the web page. Note that the indexes for lists and tables are treated separately. Both a table and list can exist with same index number.

How to import data from a webpage into Google Sheets

Option 1: IMPORTHTML(url, “table”, index)

Take a look at the screenshot below. I want to import data into cell B3, so this is where I enter my IMPORTHTML formula.

importhtml google sheets 1

Make sure that the url is valid, i.e. enclose the url avec guillemets doubles and hit Entrer.

While Google Sheets fetches the table data, it displays a Loading notification. Wait a few moments. The bigger the table, the longer it might take to finish the data import.

Importhtml Google Sheets: Loading Data

While the data import is in progress, cell B3 looks like it has returned an error. See the little red speck on the top right hand corner of the cell. However, it isn’t an error, just a état transitoire. Hover the mouse over the cell to see the following description:

Importhtml Google Sheets: Snapshot of Error

As soon as Google Sheets has finished loading the data, the red speck disappears. You’ll notice the data extends from the formula cell (B3) to the right and further down the spreadsheet.

importhtml google sheets 4

Make sure you leave enough room in the spreadsheet for the entire table of data. If you don’t, IMPORTHTML formula might cough up a #REF! error. Take a look at the following image to see what happens when I have data in cell C9.

importhtml google sheets 5
Option 2: IMPORTHTML(url cell reference, “list”, index)

In this example, I have stored the url in cell B1. This is the url to the HTML page containing the list we want to import. I’ll refer to that cell in the IMPORTHTML Google Sheets formula, which I enter into cell B3. The result is the same except this time I want a list instead of a table.

importhtml google sheets 6

Looking for more timesaving formulas and tricks in Google Sheets? If you regularly need to import data from from .csv or .tsv files from the web, check out the following how to use the IMPORTDATA formula in Google Sheets.

Vous pouvez aussi aimer...

Fonctionnalités et formules de google sheets

Comment calculer le taux d'intérêt nominal à l'aide de Google Sheets ?

Sarah est une jeune professionnelle qui doit prendre des décisions financières importantes. Des cartes de crédit aux hypothèques, en passant par les prêts étudiants et les...
Fonctionnalités et formules de google sheets

Extraire les données de Google Calendar dans Google Sheets à l'aide d'Apps Script

Cet article a été publié à l'origine dans notre forum communautaire. Objectif : Ce guide montre comment utiliser Google Apps Script pour extraire des données...
Fonctionnalités et formules de google sheets

Utilisation de la fonction PROPER pour mettre en majuscule la première lettre de chaque mot dans Google Sheets

Note : Cet article a été publié à l'origine dans notre forum communautaire. Vous avez déjà eu besoin de nettoyer une liste de noms, de titres ou d'autres...