標籤:python style import 建立 電子
import xlrdimport 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.nrowsSheet1_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 = 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#將全新的list 寫入新的試算表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‘)
本文出自 “浪漫的偷笑” 部落格,請務必保留此出處http://lmdtx.blog.51cto.com/6942028/1643537
python 處理試算表