The flow of my desired program is:
- Upload an xlsx spreadsheet to drive (it was created using pandas
to_excel
) - Convert it to Google Sheets format
- Specify that it is editable by anyone with the link
- Get the link and share it with someone who will enter information
- Download the completed sheet
I am currently using PyDrive, which solves steps 1 and 5, but there are a few unsolved problems.
How can I convert to google sheets format? I tried to just specify the mimeType as 'application/vnd.google-apps.spreadsheet'
when I created the file to upload with PyDrive, but that gave me an error.
How can I set the file to be editable by anyone with the link? Once that is set, I can get the sharing link easily enough with PyDrive.
UPDATE: conversion from xlsx to google sheets is easy with a convert=True
flag. See below. I am still seeking a way to set the sharing settings of my new file to "anyone with the link can edit".
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
test_file = drive.CreateFile({'title': 'testfile.xlsx'})
test_file.SetContentFile('testfile.xlsx')
test_file.Upload({'convert': True})
In order to set the file to be editable for anyone with the link , you have to insert a new permission with the following information:
then to get the link you go to : file["alternateLink"]
There is an Optional query parameter of "convert", for both the "INSERT" and "COPY" method;
There is a python example here:
Google Documentation - Copy
You need to use the Python client library for the code to work.
I haven't tried this, so you'll need to test it.