当前位置:嗨网首页>书籍在线阅读

10-工作表对象

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

14.3 工作表对象

一个 Spreadsheet 对象将有一个或多个 Sheet 对象。 Sheet 对象表示每个工作表中的数据的行和列。你可以使用方括号操作符和整数索引来访问这些工作表。

Spreadsheet 对象的 sheets 属性保存了一个元组,其中包含的 Sheet 对象按照它们在电子表格中出现的顺序排列。要访问电子表格中的 Sheet 对象,请在交互式环境中输入以下内容:

>>> import ezsheets
>>> ss = ezsheets.Spreadsheet('1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU')
>>> ss.sheets # The Sheet objects in this Spreadsheet, in order.
(<Sheet sheetId=1669384683, title='Classes', rowCount=1000, columnCount=26>,
<Sheet sheetId=151537240, title='Resources', rowCount=1000, columnCount=26>)
>>> ss.sheets[0] # Gets the first Sheet object in this Spreadsheet.
<Sheet sheetId=1669384683, title='Classes', rowCount=1000, columnCount=26>
>>> ss[0] # Also gets the first Sheet object in this Spreadsheet.
<Sheet sheetId=1669384683, title='Classes', rowCount=1000, columnCount=26>

你也可以用方括号操作符和表的名称字符串来获取一个 Sheet 对象。 Spreadsheet 对象的 sheetTitles 属性保存了一个元组,该元组包括所有工作表标题。例如,在交互式环境中输入以下内容:

>>> ss.sheetTitles # The titles of all the Sheet objects in this Spreadsheet. 
('Classes', 'Resources')
>>> ss['Classes'] # Sheets can also be accessed by title.
<Sheet sheetId=1669384683, title='Classes', rowCount=1000, columnCount=26>

一旦你拥有了一个 Sheet 对象,就可以使用 Sheet 对象的方法从它读取数据或向它写入数据了,这将在下一小节中解释。