我有一个函数,它将xlrd.Cell
对象作为参数。但是,该函数还需要访问"拥有"单元格的xlrd.Sheet
对象。如果不需要的话,我不想同时传递它所来自的工作表对象。API是否提供了一种方法来获取拥有单元格的工作表?
如果可能的话,从图纸对象访问xlrd.Book
对象也很有用。
我仔细查看了API,但它似乎不可用,但我因为忽略了这样的东西而臭名昭著。
否。xlrd.Cell
对象的定义是:
# Type: Cell
# String Form:number:42.0
# File: c:python27libsite-packagesxlrdsheet.py
# Source:
class Cell(BaseObject):
__slots__ = ['ctype', 'value', 'xf_index']
def __init__(self, ctype, value, xf_index=None):
self.ctype = ctype
self.value = value
self.xf_index = xf_index
def __repr__(self):
if self.xf_index is None:
return "%s:%r" % (ctype_text[self.ctype], self.value)
else:
return "%s:%r (XF:%r)" % (ctype_text[self.ctype], self.value, self.xf_index)
因此,在Cell
对象中没有对父Worksheet
的引用。您可以很容易地扩展xlrd.Worksheet
和xlrd.Cell
类来添加这样的引用,但您也可以将父工作表传递给您的函数,从而省去麻烦。