My Blog
Download and save Google Sheet to CSV with PHP and name today's date
- September 25, 2020
- -
- PHP Programming
- -
- nicolas
Hi, here is a simple solution to a customer's problem.
The client kept a product file in Google Sheets (Google's excel) and wanted to download this file to a csv file once a day and upload it to his server.
Now if it is an import it can be done easily with WP ALL IMPORT, you just share your google sheet, get the url and list it in WP ALL IMPORT during the process of creating a new Import.
However, in case you want the csv as a file and in fact with today's date for various reasons (eg to update your local Microsoft excel daily from a specific online url, etc.), you can do your job very easily with a php script.
I quote the script as it is, anyone who has a question below:
<?php $csv = file_get_contents('https://docs.google.com/spreadsheets/d/ID_ΤΟΥ_GOOGLE_SHEET_ΣΟΥ/export?format=csv'); $fp = fopen("CSVs/".date('d-m-Y').".csv","wb"); fwrite($fp,$csv); fclose($fp); ?>
This post is also available in: Ελληνικά