from excel import Excel
class WorkBook(Excel):
val1 = 'Total'
val2 = 'Total+directive'
list_content = list() # the content of the current worksheet
def __init__(self):
super().__init__()
def get_rows(self,sheet = ""):
if sheet == '':
sht = self.xlBook.Worksheets(1)
else:
sht = self.xlBook.Worksheets(sheet)
self.rows = sht.usedrange.rows.count
return sht.usedrange.rows.count
def get_cols(self,sheet = ""):
if sheet == '':
sht = self.xlBook.Worksheets(1)
else:
sht = self.xlBook.Worksheets(sheet)
self.cols = sht.usedrange.columns.count
return sht.usedrange.columns.count
def get_worksheets(self):
for i in self.xls.worksheets:
print(i.name)
def getCell(self, row=1, col=1, sheet=""): # 获取单元格的数据
if sheet == '':
sht = self.xlBook.Worksheets(1)
else:
sht = self.xlBook.Worksheets(sheet)
return sht.Cells(row, col).Value
def setCell(self, row, col, value, sheet = ''): # 设置单元格的数据
if sheet == '':
sht = self.xlBook.Worksheets(1)
else:
sht = self.xlBook.Worksheets(sheet)
sht.Cells(row, col).Value = value
def get_usedrange(self,sheet = None ):
if sheet == None:
sht = self.xlBook.Worksheets(1)
else:
sht = self.xlBook.Worksheets(sheet)
self.list_content = sht.usedrange.value
#print(self.list_content)
return sht.usedrange.address
def getRange(self, sheet, row1, col1, row2, col2): # 获得一块区域的数据,返回为一个二维元组
"return a 2d array (i.e. tuple of tuples)"
sht = self.xlBook.Worksheets(sheet)
return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).Value
def find(self,value):
print('ok')
print(self.xlBook.activesheet.name)
print(self.xlBook.activesheet.UsedRange.address)
print(self.xls.cells.find(value))
pass
excel-xls
最新推荐文章于 2022-02-04 15:16:15 发布