Chinaunix首页 | 论坛 | 博客
  • 博客访问: 23642
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 207
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-26 09:51
文章分类

全部博文(20)

分类: Python/Ruby

2013-08-26 11:26:35

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

点击(此处)折叠或打开

  1. import xlrd
  2. class testlibrary_AD_Operation:
  3.     def __init__(self):
  4.         self.measurement_data = [];
  5.         self.title_row = 1
  6.         self.colTitleHash = {}
  7.         self.__workbook_init()
  8.         self.__columnTitles()
  9.         self.__allMeasurementsChecked()

  10.     def __workbook_init(self):
  11.         if not os.path.exists(AD_file):
  12.             raise Exception("can not find AD file : " + AD_file)
  13.             return
  14.         self.workbook = xlrd.open_workbook(AD_file)
  15.         self.meash = self.workbook.sheet_by_name("Measurements")
In the following code, we can know the methods of getting value from specific cell.

点击(此处)折叠或打开

  1. def get_attribute_byMid(self,mid,attr):
  2.         """get attribute of measurement by mid from AD file.
  3.         the attribute is the title name in sheet Measurements
  4.         Examples:
  5.        | ${omesname}= | get_attribute_byMid | CELLRES | OMeS Name |
  6.        | ${meaname}= | get_attribute_byMid | CELLRES | Measurement Name |
  7.         """
  8.         mid_row = self.__get_spec_measure_byMid(mid)
  9.         attrIndex = self.__getColIndexByTitle(attr)
  10.         if not attrIndex:
  11.              raise Exception("can not get %s value from %s by mid %s " %(attr,AD_file,mid))
  12.         return self.meash.cell(mid_row,attrIndex).value.strip()

点击(此处)折叠或打开

  1. #get value from cell
  2. #cell(1,1) means row:1,column:1
  3. value = self.meash.cell(1,1).value.strip()
  4. #update the value of cell
  5. 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

点击(此处)折叠或打开

  1. value = self.meash.cell(1,1).value
  2. date_value = xlrd.xldate_as_tuple(value,0)

阅读(177) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:Simple String operations for Python 2.x

给主人留下些什么吧!~~