Introduction: Export Data From Google Spreadsheet in Required CSV Format
I recently was working on a project where my sensor data was sent to a google spreadsheet and hence was displayed on my android application.
I chose to send my sensor data to the google spreadsheet as its an easy task using a temboo.com choreo.
I was using a MSP430 Launchpad with a CC3100 Booster pack but the same choreo runs for arduino uno with a wifi shield and arduino yun.
Now as the android app cannot fetch data directly from the spreadsheet hence we got the values in the desired format.
Step 1: Make Your Google Spreadsheet Shared
In order for the spreadsheet to be accessible by the php script, you need to share the spreadsheet.
On the top right corner there is a button in blue to share the spreadsheet. Click on it and in the popup that appears click on,"get sharable link".
Step 2: Edit the URL to Get CSV Values From Google
The link in the address bar would be like this:
https://docs.google.com/spreadsheets/d/1HZzq8imLd0Rb0IKY6eUlQ3ND1_EUiPXvdjkbSfZRhLc/edit#gid=0
Where "1HZzq8imLd0Rb0IKY6eUlQ3ND1_EUiPXvdjkbSfZRhLc" is the unique sheet ID.
You have to replace the part after the unique ID with,"export?format=csv&id="
and then paste the unique ID again.
Hence the above URL becomes:
https://docs.google.com/spreadsheets/d/1HZzq8imLd0Rb0IKY6eUlQ3ND1_EUiPXvdjkbSfZRhLc/export?format=csv&id=1HZzq8imLd0Rb0IKY6eUlQ3ND1_EUiPXvdjkbSfZRhLc
Step 3: Paste the Edited URL in the PHP Script
Now paste the URL hence obtained in the PHP script we have created and save it.
Download it here
Step 4: Now Upload the PHP Script to the Root Folder of You Webhosting
Now you have to upload the php file to you hosting. You can use a free hosting service for it.
Upload the php file to the root folder of the host.
Step 5: And Hence You Have the Last 5 Values of Column 1 and Column 2 As CSV
Hence the values are available in CSV for whatever use you want.