All Excel file merge a file folder

. 1  # the Author: Winter Liu 
2  Import to xlrd
 . 3  Import xlsxwriter
 . 4  Import OS
 . 5  
. 6  # Get File Directory 
. 7 file_list the os.listdir = ( " C: \ PycharmProjects \ Python Level up \ excel_file " )
 . 8 end_xls = " xkb_end.xlsx " 
. 9  
10 Data = []
 . 11  for xls_name in file_list:
 12 is      # open xls file 
13 is      F = xlrd.open_workbook ( "C: \ PycharmProjects \ Python Level up \ \\ excel_file " + xls_name)
 14      # Create a table object list 
15      sheets = f.sheets ()
 16      # table object 
. 17      Sheet = sheets [0]
 18 is      # table function 
. 19      n-= Sheet. nrows
 20 is      m = 0 IF len (Data) == 0 the else . 1
 21 is      for I in Range (m, n-):
 22 is          # retrieve each row 
23 is          RDATA = sheet.row_values (I)
 24          data.append (RDATA)
 25 
26  # prepare to write the file open 
27 WR = xlsxwriter.Workbook (end_xls)
 28  # Add Table 
29 WS = wr.add_worksheet ()
 30 I = 0
 31 is  for Row in Data:
 32      for col_num, DA in the enumerate (Row):
 33 is          # writing data cell by cell 
34 is          ws.write (I, col_num, DA)
 35      I = I +. 1
 36 wr.close ()

 

Guess you like

Origin www.cnblogs.com/nmucomputer/p/12002934.html