I'm trying to open a xlsx file from Google Drive as a Google Sheets file in Jupyter.
from googleapiclient.discovery import build
from google.oauth2 import service_account
SERVICE_ACCOUNT_FILE = 'gs_credentials.json'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
creds = None
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
SAMPLE_SPREADSHEET_ID = 'someidhere'
RANGE = 'somerangehere'
service = build('sheets', 'v4', credentials=creds)
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
range=RANGE).execute()
values = result.get('values', [])
this script work for reading data from a Google Sheet, but i have one that's saved as xlsx. Is there a way to convert it? I found a couple answers that went something like:
service = build('drive', 'v3', credentials=creds)
service.files().copy(fileId=ID_OF_THE_EXCEL_FILE, body={"mimeType"="application/vnd.google-apps.spreadsheet"}).execute()
References:
https://developers.google.com/drive/api/v3/reference/files/copy https://developers.google.com/sheets/api/guides/values