2017-03-15 17 views
0

私は検索しようとしましたが、私が使用しているworksheet.xslxに類似したものを見つけることができませんでした。私は自分のプログラムにパンダモジュールを持っていません。Excelファイルの上書きが続けられます。 xlsx; python

目的:例。 5つのファイルがあります。ファイル1からいくつかの値を抽出して列1に入れます。ファイル2からいくつかの値を抽出して列2に入れます。

問題:私が使用したコードは以下の通りです。私のプログラムが実行している最新のファイルは、ワークシートを上書きし続け、以前のファイルは消去されます。 (つまり、最後のExcelファイルは第5列のみを表示します)。 あなたが何をすべきかについて親切にアドバイスします。ありがとうございました!

コード:

import csv 
import os 
import py2exe 
from os import rename, listdir 
from xlrd import open_workbook 
from xlwt import Workbook 
import xlrd 
import xlwt 
import py2exe 
import xlsxwriter 
from os.path import basename 


filesnum=() 
wb=Workbook() 

class Window: 

def process_csv(self): 
    global index 
    global abc 
    abc = 0 

    direct=self.filename2 #assuming directory is correct 

    filesname = "C:\file1" "C:\file2", "etc etc")): #ignore the errors made here as my original codes is correct for this part 
    for b in range (len(filesname)): 
     abc+=1 
     if "123456" in open(filesnum[b]).read(): 
      wantedarray=list() 
      count = 0 
      workbook = xlsxwriter.Workbook(direct + "/newbie.xlsx") 
      worksheet=workbook.add_worksheet("newbie") 

      for line in copyid: 
       if "abcde" in line: 
        wantedno=line[:8] 
        arrayfound.append(wantedno) #take out the number 
       elif "ending" in line: 
        break 
       else: 
        continue   
      for index, value in enumerate(arrayfound): 
       worksheet.write(index+2, abc, value) 
      workbook.close() 
     else: 
      continue 

root = Tk() 
window=Window(root) 
root.mainloop() 

答えて

0

私はダウンロードしてこれを解決するopenpyxlを使用しました。

wb.save(direct + "/newbie.xlsx") 
関連する問題