The code I have is:
import gspread
import pandas as pd
from oauth2client.service_account import ServiceAccountCredentials
from Google import Create_Service
def Create_Service(client_secret_file, api_name, api_version, *scopes):
print(client_secret_file, api_name, api_version, scopes, sep='-')
CLIENT_SECRET_FILE = client_secret_file
API_SERVICE_NAME = api_name
API_VERSION = api_version
SCOPES = [scope for scope in scopes[0]]
print(SCOPES)
credencial = ServiceAccountCredentials.from_json_keyfile_name(CLIENT_SECRET_FILE, SCOPES)
client = gspread.authorize(credencial)
return client
def Upload_pandas(df, gsheet):
tabela = df.reset_index()
gsheet.sheet1.update([tabela.columns.values.tolist()] + tabela.values.tolist())
return
CLIENT_SECRET_FILE = 'XXXXXX.json'
API_SERVICE_NAME = 'sheets'
API_VERSION = 'v4'
SCOPES = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
gsheetId = 'https://docs.google.com/spreadsheets/d/YYYYYYY/edit#gid=0'
cliente = Create_Service(CLIENT_SECRET_FILE, API_SERVICE_NAME, API_VERSION, SCOPES)
gsht = cliente.open_by_url(gsheetId)
I have an Excel file ("C:/Arquivo.xlsx") and want to upload it to the Google Sheets instead of convert the File to Dataframe and upload it, because I lose all formatation, like conditional_format etc. This should be like a Ctrl+C in the whole worksheets and Crtl+V in the Google Sheets document. Is there a way to do it using gspread? If doesn´t, which library could I use and how?
Thanks for any support!