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
- 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).
- Login to Google Docs and open the sheet you wish to export.
- 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.
- 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
- Paste the URL into the Source field for the relevant table and replace:
edit?usp=sharing
with
export?format=csv
- 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
- 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
- WordPress.org TablePress Support – Auto-Import Google Drive Spreadsheet
- WordPress.org TablePress Support – Automatic Periodic Table Import + Google Sheets
- New Google Spreadsheets publish limitation comment by s4tori
- CSV Auto Fetch using Google Drive Spreadsheet – Step 2
- New Google Spreadsheets publish limitation comment by brilletju