谷歌电子表格的dict包装
dictsheet的Python项目详细描述
以dict方式管理您的电子表格。一个易于使用的google电子表格python api。按行管理工作表中的信息。基于gspread
功能:
- 以dict方式管理电子表格
- 获取/设置工作表映射
- 更新行或行中的元素。
- 在电子表格中迭代行。
要求
- python 2.6+或python 3+,gspread
安装
pip install dictsheet
基本用法
- [从google开发者控制台获取oauth2凭据](http://gspread.readthedocs.org/en/latest/oauth2.html)
- 获取工作表标题。
- 开始使用听写表
示例代码
import gspread from oauth2client.service_account import ServiceAccountCredentials from dictsheet import DictSheet # The Credential file obtained from Google CREDENTIAL_FILE = 'My Projecthah-xxxxxxx.json' #Title of the sheet SHEET_NAME = u'titleOfTheSheet' # Create credentials scope = ['https://spreadsheets.google.com/feeds'] credentials = ServiceAccountCredentials.from_json_keyfile_name(CREDENTIAL_FILE, scope) # Use gspread to connect to Google Spread Sheet gc = gspread.authorize(credentials) sh = gc.open(SHEET_NAME) wks = sh.get_worksheet(0) # Initialize dictsheet dict_wks = DictSheet(wks=wks) # Basic usage # Get mapping print dick_wks.mapping # Set mapping map = {"name":1, "phone":2, "address":3} dict_wks.mapping = map # Appending dict_wks.append({"name": "Chandler Huang","phone": 987654321}) # Updating (2 is the row number) dict_wks.update({2: {"name": "Kelly"}, 6:{"phone": 12345}}) # Iterating for idx, dict_data in dict_wks.items(): print idx, ' : ',dict_data # Clearing a row dict_wks[4].clear()
贡献者
黄昌德,李赞德