Excel 文件的覆盖不断发生; xlsx; python

Overwriting of Excel files keeps occurring; xlsx; python

我试过搜索,但找不到与我正在使用的 worksheet.xslx 类似的。我的程序中没有熊猫模块。

目标:例如有5个文件。从文件 1 中提取一些值并放入第 1 列。从文件 2 中提取一些值并放入第 2 列,依此类推

问题:我使用的代码如下图。我的程序是 运行 的最新文件将继续覆盖工作表,而较早的文件将被擦除。 (即最后的 excel 文件仅显示第 5 列。第 1-4 列为空。) 请就我应该做什么提出建议。谢谢!

代码:

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()

我已经下载并使用 openpyxl 来解决这个问题。

wb.save(direct + "/newbie.xlsx")