谷歌电子表格的dict包装

dictsheet的Python项目详细描述


以dict方式管理您的电子表格。一个易于使用的google电子表格python api。按行管理工作表中的信息。基于gspread

功能:

  • 以dict方式管理电子表格
  • 获取/设置工作表映射
  • 更新行或行中的元素。
  • 在电子表格中迭代行。

要求

  • python 2.6+或python 3+,gspread

安装

pip install dictsheet

基本用法

  1. [从google开发者控制台获取oauth2凭据](http://gspread.readthedocs.org/en/latest/oauth2.html
  2. 获取工作表标题。
  3. 开始使用听写表

示例代码

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()

贡献者

黄昌德,李赞德

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将Int值传递给另一个类   在使用Sdin(或非交互式)输入| Java时调试奇怪的输入错误   java返回一个文本字符串作为响应struts2   java为什么我们不能在声明局部变量之前初始化它呢?   java从现有XML中读取值并将其填充到Json中   java Spring Boot+Maven:找不到repositoryFactoryBean   java使用regex表示“W o.Rd”。replaceAll(“单词”、“替换”)   java Sub resorce在Jersey REST API框架中不起作用   java在组件启动时,当所述报告存储在Sharepoint中时,是否可以加载预格式化的WebDataRocks报告?   java并发更新列表的最佳方法   servlets Java web应用程序对象调度   应用程序在点击按钮时崩溃,Android Studio(Java)   java如何为掷骰子游戏调用另一个类中的方法?