Python csv-improved xls code, pythoncsv-xls
# Coding: UTF-8 # import the corresponding module import csv, xlwt, sys, OS, fnmatch, xlrdfrom xlutils. copy import copy # calculate the maximum value for the absolute value data in the xls file and list def max_excel (excel): P4 = xlrd. open_workbook (excel) # sheet0 = rb1.sheets () [1] wb1 = copy (P4) # The number of rows and columns can be obtained only after the sheet name is obtained on the sheet page, but cannot be written, the sheet obtained by subscript can be written, but the number of rows and columns cannot be obtained. 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 'Blow point % d' % (k + 1 )) cols = sheet0.col _ values (k) cmax = max (cols [1:]) sheet3.write (1, k, cmax) wb1.save (excel) # Calculate the absolute value of data in the xls file def abs_excel (excel): # print "3" 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) # save As xls file def ex_file (mycsvfile): csvfile = open (mycsvfile, "rb") # csvfile = open ("test.csv ", "rb") # create an excel file myexcel = xlwt. workbook () # create a sheet page mysheet1 = myexcel. add_sheet ("data") mysheet2 = myexcel. add_sheet ("Absolute") mysheet3 = myexcel. add_sheet ("MAX") # obtain the csv file name portion = OS. path. splitext (mycsvfile) # Read the file information in csv reader = csv. reader (csvfile, dialect = 'excel ') l = 0 # obtain the information of a single row in a loop for line in reader: r = 0 # obtain the information of a single unit in a dual loop for I in line: # Write the excel table mysheet1.write (l, r, I) r + = 1 l + = 1 myexcel in a double loop. 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) # batch processing 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 ')
Finally, you can use the python pyinstaller -- console -- onefile absolute path \ py file. py command to generate the corresponding exe file.