我的代码是:
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)
我有一个Excel文件(“ C:/Arquivo.xlsx”),并希望将其上传到Google表格而不是将文件转换为数据框并上传,因为我丢失了所有格式,例如conditional_format等。就像整个工作表中的Ctrl + C和Google表格文档中的Crtl + V一样。有没有办法使用gspread做到这一点?如果没有,我可以使用哪个库以及如何使用?
感谢您的支持!