iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
https://docs.iterative.ai/PyDrive2
Other
581 stars 69 forks source link

is it possible to upload excel (.xlsx) files to google drive with your api? #157

Closed WilliamBonvini closed 2 years ago

WilliamBonvini commented 2 years ago

Hi! sorry if the question may seem superficial, but I have some excel files that I want to upload to my google drive within my python project. I've read your documentation and you show the following example of text file upload:

from pydrive2.drive import GoogleDrive

# Create GoogleDrive instance with authenticated GoogleAuth instance.
drive = GoogleDrive(gauth)

# Create GoogleDriveFile instance with title 'Hello.txt'.
file1 = drive.CreateFile({'title': 'Hello.txt'})
file1.Upload() # Upload the file.
print('title: %s, id: %s' % (file1['title'], file1['id']))
# title: Hello.txt, id: {{FILE_ID}}

for file with other extensions is it enough to replace

file1 = drive.CreateFile({'title': 'Hello.txt'})

with

file1 = drive.CreateFile({'title': 'MyExcelFile.xlsx'})?

And if so, where should I specify the path of my excel file?

Thank you in advance for your answer :)

shcheklein commented 2 years ago

@WilliamBonvini please refer to this example - https://github.com/iterative/PyDrive2/blob/master/examples/Upload-and-autoconvert-to-Google-Drive-Format-Example/upload.py#L53 . It uploads a file and makes it a Google Sheet (it's optional).

Line 53 is the important part here and answers your question I hope :)

WilliamBonvini commented 2 years ago

Ok, thanks! :)