Hi ,
I'm now trying to import data from google spreadsheets. How can I proceed?
I'm now trying to import data from google spreadsheets. How can I proceed?
capture program drop gsheet
program define gsheet
syntax anything , key(string) id(string)
local url "https://docs.google.com/spreadsheets/d/`key'/export?gid=`id'&format=csv"
copy "`url'" `anything', replace
noi disp `"saved in `anything'"'
import delim using `anything', clear
end
**** key comes from url of shareable link
** Example:
** https://docs.google.com/spreadsheets/d/18l-T2xk03s8FEgNdbEP9gONlU6CvUSl6SlKJJpGfFKU/edit?usp=sharing
**** id is the spreadsheet id and can be at the end when in the edit mode in google sheets
gsheet "`c(pwd)'\\test.csv" , key("18l-T2xk03s8FEgNdbEP9gONlU6CvUSl6SlKJJpGfFKU") id("0")
gsheet "`c(pwd)'\\ipejd219\Google Drive\Research\StataCode\test2.csv" , key("18l-T2xk03s8FEgNdbEP9gONlU6CvUSl6SlKJJpGfFKU") id("1504070058")
tempfile sheetsFile copy "https://docs.google.com/spreadsheets/d/<spreadsheetKey>/export?format=xlsx" `sheetsFile', replace import excel `sheetsFile', clear firstrow
tempfile sheetsFile
copy "https://docs.google.com/spreadsheets/d/<spreadsheetkey>/edit?usp=sharing/export?format=xlsx" `sheetsFile', replace
import excel `sheetsFile', clear firstrow
tempfile gsheet copy "published spreadsheet link from above" `gsheet', replace
import excel using `gsheet', first sheet("tabname") clear
Comment