enter image description here 我现在在合并多个csv文件时遇到一个技术问题。 我有一个包含260个文件的文件夹,所有文件都具有相同的数据格式。我想在每一个中选择E列第25行-Row124,并将它们合并到一个新的csv文件中。 使用此链接中提供的代码,我可以轻松快捷地完成操作 https://answers.microsoft.com/en-us/msoffice/forum/all/using-excel-macros-to-extract-data-from-a-spe ... 但是,它们没有按照我想要的顺序进行合并,因此输出的csv文件中的数据我无法弄清楚哪个列来自哪个文件。 因为我的文件全都是数字名称,例如1520 + 0-2、1520 + 0-4 ... 1520 + 15-2、1520 + 15-4 ... 不按字母顺序排列。 我该怎么解决。
下面列出了我为案例修改的宏代码,
from tkinter import *
from PIL import Image, ImageDraw
tk = Tk()
cvs = Canvas(tk, width=500,height=500)
cvs.pack()
img = Image.new('RGB',(500,500),(255,255,255))
draw = ImageDraw.Draw(img)
mousePressed = False
last=None
def press(evt):
global mousePressed
mousePressed = True
def release(evt):
global mousePressed
mousePressed = False
cvs.bind_all('<ButtonPress-1>', press)
cvs.bind_all('<ButtonRelease-1>', release)
def finish():
img.save('img.png')
tk.destroy()
Button(tk,text='done',command=finish).pack()
def move(evt):
global mousePressed, last
x,y = evt.x,evt.y
if mousePressed:
if last is None:
last = (x,y)
return
draw.line(((x,y),last), (0,0,0))
cvs.create_line(x,y,last[0],last[1])
last = (x,y)
else:
last = (x,y)
cvs.bind_all('<Motion>', move)
tk.mainloop()
请帮助我使此代码按我想要的顺序运行。
答案 0 :(得分:0)
为解决这个问题,一个可能的解决方案(如果它对您有用)是在第1行中添加文件名,并将其余数据粘贴到第2行中。
非常容易实现-更改
wb1.Sheets(1).Range(Cells(N, sC), Cells(L, sC)).Copy wb.Sheets(1).Cells(1, c)
到
wb.Sheets(1).Cells(1, c).Value = sFile
wb1.Sheets(1).Range(Cells(N, sC), Cells(L, sC)).Copy wb.Sheets(1).Cells(2, c)