私は自分自身のGoogleスプレッドシートラッパーを作成しようとしていましたが、これまでのところ不満足な経験でした。私が現時点で抱えていることは、シートデータの対称イン/アウトフォーマットを得る方法です。GoogleシートAPI v4のセルから書式設定情報を取得するPythonの例ですか?
基本的には、values()。get()を呼び出し、結果のハッシュを変更し、同じハッシュをupdate()に送信します。
values()の出力を処理または強制する独自のソリューションを作成してもよろしいですか?batchUpdate()に必要な構造体にget()を実行しますが、各セルの書式設定情報が必要ですその。
がimport requests
import json
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
#Set up credentials object
auth_key_url = "<JSON CREDENTIALS FILE>"
file_contents = requests.get(auth_key_url).content
key_dict = json.loads(file_contents)
creds = ServiceAccountCredentials.from_json_keyfile_dict(key_dict, ['https://spreadsheets.google.com/feeds'])
#Now build the API object
discoveryUrl = "https://sheets.googleapis.com/$discovery/rest?version=v4"
gsheet = build('sheets', 'v4', discoveryServiceUrl=discoveryUrl, credentials=creds)
result = gsheet.spreadsheets().values().get(spreadsheetId="<A SHEET ID>", range="Sheet1!A1:ZZ").execute()
これは "結果" を生成し、辞書にある:
bod = {
'updateCells': {
'start': {
'sheetId': 0,
'rowIndex': 7,
'columnIndex': 0
},
'rows': [
{
'values': [
{
"userEnteredValue": {
'stringValue': 'LOL'
},
"userEnteredFormat": {
'backgroundColor': {
'red': .2,
'blue': .75,
'green': .75
}
}
},
{
"userEnteredValue": {
'stringValue': 'LOL2'
},
"userEnteredFormat": {
'backgroundColor': {
'red': .2,
'blue': 1,
'green': .75
}
}
},
{
"userEnteredValue": {
'stringValue': 'LOL3'
},
"userEnteredFormat": {
'backgroundColor': {
'red': .2,
'blue': 1,
'green': 1
}
}
}
]
}
],
'fields': 'userEnteredValue,userEnteredFormat.backgroundColor'
}
}
私は値を取得していますどのようには現在、次のようになります。
batchUpdateメ()は、このような書式設定情報が期待します2つのキー、「範囲」および「値」、および「値」はスプレッドシートの値のリストです。これらのリストには、書式設定データは含まれていません。セル内の値だけです。
誰かが私に、セル値、背景色、配置、およびその他のセルの書式設定情報をスプレッドシート()。values()またはスプレッドシートから得る方法をPythonで教えてもらえますか?