#coding:utf-8#導入相應模塊import csv,xlwt,sys,os,fnmatch,xlrdfrom xlutils.copy import copy#對xls文件中的絕對值數據求最大值并列表def max_Excel(excel): rb1=xlrd.open_workbook(excel) #sheet0=rb1.sheets()[1] wb1=copy(rb1) #sheet頁通過sheet名稱得到的才能獲取行數和列數,但是不能進行寫操作,通過下標獲得的sheet可以進行寫操作,但是不能獲得行數和列數 sheet0=rb1.sheet_by_name("Absolute") sheet3=wb1.get_sheet(2) nrows1=sheet0.nrows ncols1=sheet0.ncols for k in range(0,ncols1,): sheet3.write(0,k,u'炸點%d' %(k+1)) cols = sheet0.col_values(k) cmax=max(cols[1:]) sheet3.write(1,k, cmax) wb1.save(excel)#對xls文件中的data數據求絕對值def abs_excel(excel): # rb=xlrd.open_workbook(excel) #sheet=rb.sheets()[0] wb=copy(rb) sheet = rb.sheet_by_name("data") #print sheet sheet2=wb.get_sheet(1) nrows=sheet.nrows ncols=sheet.ncols for i in range(nrows): for j in range(ncols): w=sheet.cell(i,j).value if (i==0): sheet2.write(i,j,w) else: v = float(w) sheet2.write(i,j,abs(v)) wb.save(excel) max_excel(excel)#另存為xls文件def ex_file(mycsvfile): csvfile = open(mycsvfile,"rb") #csvfile = open("test.csv","rb") #新建excel文件 myexcel = xlwt.Workbook() #新建sheet頁 mysheet1= myexcel.add_sheet("data") mysheet2= myexcel.add_sheet("Absolute") mysheet3= myexcel.add_sheet("MAX") #獲取csv的文件名 portion = os.path.splitext(mycsvfile) #讀取csv中文件信息 reader = csv.reader(csvfile,dialect='excel') l = 0 #通過循環獲取單行信息 for line in reader: r = 0 #通過雙重循環獲取單個單元信息 for i in line: #通過雙重循環寫入excel表格 mysheet1.write(l,r,i) r+=1 l+=1 myexcel.save(portion[0]+".xls") excel = portion[0]+".xls" #print portion[0]+".xls" abs_excel(excel) def iterfindfiles(path, fnexp): for root, dirs, files in os.walk(path): for filename in fnmatch.filter(files, fnexp): yield os.path.join(root, filename) #批量處理if __name__=="__main__": mypath=raw_input("Please enter a path:") myfnexp='*.csv' #print 1 for filename in iterfindfiles(mypath,myfnexp): #print filename ex_file(filename) #abs_excel(filename) #max_excel(filename) raw_input ('please enter to exit')
最后可以通過 python pyinstaller --console --onefile 絕對路徑/py文件.py 命令生產成對應的exe文件。
新聞熱點
疑難解答