I uploaded .xlsx successfully from my local PC to google drive using this simple function. The mimetype I am using should convert .xlsx to normal google sheet
def writeToGDrive(filename):
file_metadata = {'name': filename,'parents': [FOLDER_ID]}
media = MediaFileUpload(filename,mimetype='application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet', resumable=True)
file = service.files().create(body=file_metadata,media_body=media,fields='id').execute()
return file.get('id')
but when I am trying to read or edit
mySpread=service_sheet.spreadsheets().get(spreadsheetId=spreadSheet_Id).execute()
It gives me this error
returned "This operation is not supported for this document">
Also when tried to use gspread it gives me this error
gspread.exceptions.APIError: {'code': 400, 'message': 'This operation is not supported for this document', 'status': 'FAILED_PRECONDITION'}
I want to edit this .xlsx on google drive then export it as .xlsx again to local drive
I believe your goal as follows.
Please modify as follows and test it again.
From:file_metadata = {'name': filename,'parents': [FOLDER_ID]}
To:
file_metadata = {'name': filename, 'parents': [FOLDER_ID], 'mimeType': 'application/vnd.google-apps.spreadsheet'}
When you exported it as XLSX file, please use the method of "Files: export" as follows.
request = service.files().export_media(fileId=fileId, mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
fh = io.FileIO('exportedSample.xlsx', mode='wb')
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print('Download %d%%.' % int(status.progress() * 100))