Automatically import a Google Drive Sheet (CSV) into TablePress using Automatic Periodic Table Import

To keep this post short-and-sweet, which will be the aim for future articles, I am experimenting with the Situation, Task, Action, Result (STAR) method for this write-up. Do let me know if you think it works or not in the comments or the contact form.

Situation

A TablePress table listing sport fixture results (e.g. football, hockey etc.) requires regular updating.

This had been done by one person using an (offline) Excel spreadsheet and manually importing the .csv file. But the job has now been shared amongst a team of three (in different locations), so maintaining an offline spreadsheet no longer seemed practical.

Thus it made sense to create and maintain a single version on Google Sheets that could be edited by all.

But exporting and importing the file requires extra action. Could this process be automated?

Task

Automatically and periodically import a Google Sheet into TablePress to replace a table of fixture results

Action

  1. Download, install and enable the TablePress Automatic Periodic Table Import extension. Please note this is a premium plugin and so I would strongly encourage you to make a donation to Tobias Bäthge if you find it useful (the current recommended amount is $18).
  2. Login to Google Docs and open the sheet you wish to export.
  3. Click on File → Share → Anyone with the link can view to ensure the extension can access the sheet; simply enabling File → Publish to the web does not always work for the .csv format as this only makes the HTML output public, but not the .csv version.
  4. Copy the URL of the sheet, which should have the following format (where YOUR_DOCUMENT_KEY is the primary ID of your Google Sheet):

    https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/edit?usp=sharing

  5. Paste the URL into the Source field for the relevant table and replace:
    edit?usp=sharing

    with

    export?format=csv
  6. The final format is as follows:

    https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/export?format=csv

    UPDATE with props to Alessandro: The above will import the first sheet (‘Sheet1’) or gid=0 so if you are looking to import a specific tab/sheet in a multi-sheet document, you will need to identify the GID=YOUR_GID_KEY reference and include it in the url.

    The final format of a specific sheet is as follows:

    https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/export?format=csv&gid=YOUR_GID_KEY

  7. Click the check-box to activate the Auto Import, set how frequently this should occur and save changes.

Result

A single online spreadsheet hosted on Google Docs/Sheets editable by multiple authors, which is then automatically and periodically imported into TablePress to replace a table of fixture results.

Demo: https://www.wpsnippets.com/tablepress-auto-import-using-google-sheets/

References

Tagged with: , , , , , ,
14 comments on “Automatically import a Google Drive Sheet (CSV) into TablePress using Automatic Periodic Table Import
  1. Steven says:

    Thanks! Works great. (and STAR method works as well )

  2. Flick says:

    @Steven: Many thanks for your comment. I am delighted to hear that the Google import tutorial was helpful to you (and that STAR works too! :D) If you have any suggestions for this article or ones you might like to see on this site in future, please do feel free to let me know.

  3. Chris Backe says:

    Not sure if it’s an issue with the plug-in or Google Docs, but it’s only possible to import the first sheet of a spreadsheet this way. Followed all the instructions and tried twice, but it only imported the first sheet…

  4. Alessandro Curci says:

    Thanks for this article, very useful.
    I’ve found how to import a specific sheet and even a specific range in the sheet on this stack overflow answer http://stackoverflow.com/a/23394860/666223

  5. Asim says:

    Auto import failed ?
    I have placed the same url in the source type that i used to import the table first.
    when i import a table it works fine,but get failed error with auto import.
    Btw i am using google spreadsheet to test it.

  6. Flick says:

    @Asim: I have tested it again today and Auto Import seems to be working fine, where clicking through to “TablePress -> Import a Table” in the WP-Admin shows me when the csv files were last imported. Can you share the url format that you have been using for your test please? Thanks

  7. Flick says:

    @Alessandro: Thanks for the link. I have just tested it and can confirm this format https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/export?format=csv&gid=THE_SHEET_GID works so will update the article to reflect this 🙂

  8. Very helpful, and I like the STAR approach. Just to note that you can test your url before submitting to Tablepress by copying and pasting the link into a browser. If coded correctly, it should download a .csv file. Mine did.

  9. Flick says:

    @Ralph: Thanks for your comment – appreciate the tip on testing the URL and am glad you found the article helpful!

  10. Boris says:

    That “Source” field is in the Import page of TablePress, correct? When I choose Import Source URL it shows me an input field Datei-URL (data/file url). That’s where I insert my modified Google Spreadsheet link.

    After saving I can no longer edit that source entry, correct?
    The URL is automatically inserted as Table Name and Description, changing that won’t affect the URL to the spreadsheet?

    Kind regards
    Boris

  11. Fatmir says:

    This saved me a lot.. I mean a lot of time and effort. thank you very much.

  12. Flick says:

    @Fatmir, glad you found it helpful and thank you for taking the time to comment and let me know, it is appreciated!

  13. R-Web says:

    Hi @Flick
    How can i display the Last Update Date & time like your demo?
    (Last updated on: 2020-11-18 00:46:50)

  14. Flick says:

    Hi R-Web, thanks for your question. I generate this using the following code, where you’ll need to change the # to your table ID:
    [table-info id=# field="last_modified" format="raw" /]
    Hope this works for you as well.

2 Pings/Trackbacks for "Automatically import a Google Drive Sheet (CSV) into TablePress using Automatic Periodic Table Import"
  1. […] Automatically import and sync a Google Sheets table with TablePress – this is helpful for large data sets. […]

  2. […] On a personal note, I like to use the import feature to build my tables in Google Sheets and then quickly import them into TablePress when I’m finished. It’s even possible to automatically sync your Google Sheets table to TablePress. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*