0
我试过搜索,但找不到一个类似于我正在使用的worksheet.xslx。我的程序中没有熊猫模块。覆盖Excel文件不断发生; XLSX; python
目标:例如,有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()