INTERNET Programming

How to Paste Wikipedia Table in Google Sheets

Google Sheets Command copy Wikipedia table in Google Sheets

Copying tables in Google Docs is easy as you just have to use the universal copy Shortcut keys like Ctrl + C to copy the data from a web page and then Ctrl + V command to paste it in your Google Docs document. 

However you may not be able to use this method to paste data in Google sheets. Copying and pasting table data copied from a web page in a Google Sheets cell using the simple copy paste method may not give you the expected results. 

Copy Table data From a Webpage in Google Sheets.

We would be importing table data from a Wikipedia page but the  method described below can copy tabular data from any webpage and import it in a Google Sheets document.

Step 1

Copy the web URL of the wikipedia page where the table you want to copy is located. Also, note down the table number (their position in the page as they appear from top to bottom) of the table you want to copy . Let’s say you want to copy the second table on the following URL. (The first table is hidden, so the table we want to copy is table number two)

Step 2

Now we would use one of the Google Sheets functions to import the table into the Google Sheets document. The syntax of the table is as follows. 

IMPORTHTML(url, query, index)
ABOUT
Imports data from a table or list within an HTML page.
url
The URL of the page to examine, including protocol (e.g. http:// or https://).
query
Either “list” or “table” depending on what type of structure contains the desired data.
index
The index, starting at 1, which identifies which table or list as defined in the HTML source should be returned.

We would modify the above function using the URL of the page where our table is located. The modified function with the URL and table number is given below. (Also remember to use the straight quotation marks ” ” instead of the typographic curly quotation marks to enclose the arguments of this function)

=IMPORTHTML("https://en.wikipedia.org/wiki/List_of_American_films_of_2023", "table", 2)

Step 3

Copy the entire command and paste it into a single cell where you want the table to appear and hit the Enter key.

Google Sheets would copy the entire table in Google Sheets in plain text formatting.

If you get the following Warning then simply click on Allow access button.

Also, If you do not get the right table then you can simply try changing the table number argument in the following command.

=IMPORTHTML("https://en.wikipedia.org/wiki/List_of_American_films_of_2023", "table", 3)

You can also use this function to import ordered lists from a webpage into a Google Sheets document. Simply replace the second argument to "list"

=IMPORTHTML("https://www.example.com/list_item" , "list", 1)

Also remember to use the straight quotation marks " " instead of the typographic “ ” curly quotation marks to enclose the arguments of this function.