In order to use package xlrd, the first thing is download the package xlrd.zip
In the following code, we can get the information about how to open Excel file and locate which sheets
-
import xlrd
-
class testlibrary_AD_Operation:
-
def __init__(self):
-
self.measurement_data = [];
-
self.title_row = 1
-
self.colTitleHash = {}
-
self.__workbook_init()
-
self.__columnTitles()
-
self.__allMeasurementsChecked()
-
-
def __workbook_init(self):
-
if not os.path.exists(AD_file):
-
raise Exception("can not find AD file : " + AD_file)
-
return
-
self.workbook = xlrd.open_workbook(AD_file)
-
self.meash = self.workbook.sheet_by_name("Measurements")
In the following code, we can know the methods of getting value from specific cell.
-
def get_attribute_byMid(self,mid,attr):
-
"""get attribute of measurement by mid from AD file.
-
the attribute is the title name in sheet Measurements
-
Examples:
-
| ${omesname}= | get_attribute_byMid | CELLRES | OMeS Name |
-
| ${meaname}= | get_attribute_byMid | CELLRES | Measurement Name |
-
"""
-
mid_row = self.__get_spec_measure_byMid(mid)
-
attrIndex = self.__getColIndexByTitle(attr)
-
if not attrIndex:
-
raise Exception("can not get %s value from %s by mid %s " %(attr,AD_file,mid))
-
return self.meash.cell(mid_row,attrIndex).value.strip()
-
#get value from cell
-
#cell(1,1) means row:1,column:1
-
value = self.meash.cell(1,1).value.strip()
-
#update the value of cell
-
self.meash.cell(1,1).value = 'inserted'
xlrd is powerful package to operate excel, which includes abundant functions. The details please refer to revelent document.
get date format value from cell
-
value = self.meash.cell(1,1).value
-
date_value = xlrd.xldate_as_tuple(value,0)
阅读(177) | 评论(0) | 转发(0) |