import xlrdimport xlwt# #输入input_ip = raw_input ("Please enter an IP:") input_count_values = Int (raw_input ("Enter -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.nrowssheet1_ncols = table_ sheet1.ncols# Create an empty list object to get non-writable Table_sheet1_data =[]for i in range ( Sheet1_nrows): table_sheet1_data.append (Table_sheet1.row_values (i)) #print table_ sheet1_data# Cyclic judging condition count_for_find = 0for 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 + 1print table_sheet1_data# writes the new list to a newer spreadsheet count_x = 0for 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 + 1wbk.save (' D:\TestData2.xls ')
This article is from the "Romantic Laugh" blog, make sure to keep this source http://lmdtx.blog.51cto.com/6942028/1643537
Python processing spreadsheets