2017-01-09 45 views
-3

http://openpyxl.readthedocs.io/en/default/_modules/openpyxl/workbook/workbook.html?highlight=set%20active%20sheetopenpyxl设置活动表

文档显示一个工作簿对象具有active财产

@property 
def active(self): 
    """Get the currently active sheet""" 
    return self._sheets[self._active_sheet_index] 

@active.setter 
def active(self, value): 
    """Set the active sheet""" 
    self._active_sheet_index = value 

如果wb = openpyxl.Workbook()调用wb.active给默认的第一个工作是Sheet的称号。 说我创建另一个工作表ws1 = wb.create_sheet('another sheet'),我如何“设置”这是活动表?

该文档显示有一个活动的“setter”,也称为活动。它需要一个额外的参数,一个整数索引值。

wb.active(1)怎么回事?我不打电话

+0

的可能的复制[Python的openpyxl选择片](http://stackoverflow.com/questions/36814050/python-openpyxl-select-sheet) –

回答

0

我不熟悉整个getters和setters的东西。不过,我想出了答案。这对我来说非常混乱,为什么它以这种方式工作 - 因为它看起来不像一个典型的函数调用。在任何情况下,要使用的“setter”你会写

wb.active = 1

其中嗯“吃” 1 =)和改变活性片。只要想到至少有一个其他人可能会提出类似的问题。