python处理excel文档作为配置文件
2010-12-12 19:41
771 查看
#!/usr/bin/env python # -*- coding: utf-8 -*- import xlrd import sys import time def usage(): print "This Program need 4 parameters including command itself:i/n/tconfigfile is configfile format .xls/n/tparameter2 is test environment/n/tparameter3 is testcase/n/nFor Example :/n/tcommand configfile 0 3/n/tcommand configfile 1 5/n/tcommand configfile 0 5/n/nEditor and Programmer:/n/n" sys.exit() def column_num(i): columntypes = sheet_0.col_types(i) column_list_temp = [] # print len(columntypes) for j in range(len(columntypes)): if columntypes[j] == 1 or columntypes[j] == 2: column_list_temp.append(j) column_list_temp.append(sheet_0.nrows) return column_list_temp def action_pro(str, i): print 'Action %s Times %d is running ...'%(str, i) def case_pro(case_str): # times_act = int(case_str.split(',')[1]) for i in range(int(case_str.split(',')[1])): # print case_str.split(',')[0] try: action_pro(case_str.split(',')[0],i) except: print 'Action %s Times %d run Failed ...'%(case_str.split(',')[0], i) continue time.sleep(1) print 'Finish one step/n' def testcase_pro(string_temp): actions = string_temp.split(';') for act in actions: try: case_pro(act) except: print 'Test Case Action %s run Failed ...'%(act.split(',')[0]) continue print time.strftime('%Y-%m-%d-%H-%M-%S'),'/nFinish one case/n' def test_bed(str_bed): print 'Test Bed %s is preparing ... and Finished'%str_bed def row_print(column_list_temp2, cols): length_coln0 = len(column_list_temp2) # print '/n/n',length_coln0 for i in range(length_coln0 - 1): # print column_list_temp2[i] print '/n/Start Server Configuration: ' try: test_bed(sheet_0.cell_value(column_list_temp2[i], coln)) except: print 'Test Bed %s prepare Failed ...'%sheet_0.cell_value(column_list_temp2[i], coln) continue # sys.exit() for k in range(column_list_temp2[i] + 1, column_list_temp2[i + 1]): # print sheet_0.cell_value(k, cols) testcase_pro(sheet_0.cell_value(k, cols)) def main(): global coln coln = int(sys.argv[2]) global column_list column_list = column_num(coln) # print column_list row_print(column_list, int(sys.argv[3])) if __name__ == '__main__': if len(sys.argv) != 4: print usage() filename = sys.argv[1] try: workbook = xlrd.open_workbook(filename,'r') sheet_0 = workbook.sheet_by_name('Sheet1') except: print "Error Occur, and Stop ." sys.exit() main()
相关文章推荐
- Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)
- Python编程浅析:Python变量作为配置文件格式的利与弊
- Python处理Excel和PDF文档
- 使用python处理中文csv文件,并让excel正确显示中文
- Python处理Excel文档(xlrd, xlwt, xlutils)
- 用python处理Excel文档(2)——用xlsxwriter模块写xls/xlsx文档
- caffe for windows的python接口学习(3):生成以原始图片作为输入的配置文件
- Python 处理EXCEL的CSV文档分列求SUM
- Log4j配置学习文档之二 处理日滚文件-实现原理
- 如何在 Laravel 项目中处理 Excel 文件--->Laravel配置EXCEL
- python模块xlrd安装-处理excel文件必须
- python xml 与配置文件处理
- Python处理Excel文档(xlrd, xlwt, xlutils)
- Log4j配置学习文档之二 处理日滚文件-模拟实现
- 文件处理python---txt转excel
- $ 用python处理Excel文档(1)——用xlrd模块读取xls/xlsx文档
- Python--键值对配置文件处理
- 标准C处理类似INI配置文件的键值型文档
- 使用python处理中文csv文件,并让excel正确显示中文(避免乱码)
- 快乐Python快速上手系列5 - Excel文件处理