import xlrd import xlwt ##输入 input_ip = raw_input("请输入一个ip:") input_count_values = int(raw_input("请输入-1 or +1 :")) #新建电子表格 wbk =xlwt.Workbook(encoding=‘utf-8‘, style_compression=0) new_sheet1 =wbk.add_sheet(‘Sheet1‘, cell_overwrite_ok=True) style = xlwt.XFStyle() #读取电子表格 data = xlrd.open_workbook(‘d:\\1.xls‘) table_Sheet1 = data.sheet_by_name(u‘Sheet1‘) #取得原表格的总行数与总列数 Sheet1_nrows = table_Sheet1.nrows Sheet1_ncols = table_Sheet1.ncols #创建一个空 list 用于取得 不可写的对象 table_Sheet1_data =[] for i in range(Sheet1_nrows): table_Sheet1_data.append(table_Sheet1.row_values(i)) #print table_Sheet1_data #循环判断条件 count_for_find = 0 for where_you_need in table_Sheet1_data: if input_ip in where_you_need: print "FIND",count_for_find if where_you_need[-1] > 0 or input_count_values == +1: where_you_need[-1] = where_you_need[-1] + input_count_values #print where_you_need else: print "last_values=0 cannot -1" break count_for_find = count_for_find + 1 print table_Sheet1_data #将全新的list 写入新的电子表格 count_x = 0 for x in table_Sheet1_data: count_y =0 for y in x: new_sheet1.write(count_x,count_y,y,style) count_y = count_y + 1 count_x = count_x + 1 wbk.save(‘D:\TestData2.xls‘)
本文出自 “浪漫的偷笑” 博客,请务必保留此出处http://lmdtx.blog.51cto.com/6942028/1643537
原文地址:http://lmdtx.blog.51cto.com/6942028/1643537