我想用pygsheets來獲取google表單中每個單元格的顏色代碼。正在使用的代碼塊:
import pygsheets
gc = pygsheets.authorize(service_file='credentials.json')
sh = gc.open('golden dataset')
wks = sh[0]
count = 1 ]
color_code = []
while count<27628:
cell = pygsheets.Cell('J' str(count),worksheet=wks)
color_code.append(cell.color)
其中27628是列長& 'golden dataset'是作業表名稱& credentials.json有助于將google_sheets與python連接。雖然,這樣做很好,但對于一列來說,速度非常慢(需要7-8小時)。有什么更快的方法嗎?謝謝
。uj5u.com熱心網友回復:
你可以使用get_all_values,將cells作為回傳型別。
import pygsheets
gc = pygsheets.authorize(service_file='credentials.json' )
sh = gc.open('golden dataset')
wks = sh[0]
cells = wks.get_all_values(returnas='cell', include_tailing_empty=False, include_tailing_empty_rows=False)
#調整,如果你也需要尾部空單元格。
color_code = []
for r in cells:
for c in r:
color_code.append(c.color)
如果你想在自定義的批次中獲取資料,你可以使用get_values與wks.rows和wks.cols。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/320551.html
標籤:
