#将指定文件夹中所有excel文件的最后一行汇总到一起
require "win32ole"
excel=WIN32OLE.new("Excel.Application")
excel.visible=false
workbook = excel.Workbooks
#需要处理的文件夹
path="c:/02"
datas=[]
Dir.entries(path) .each{|x|
next if x.length<3
data=[x[0..-11]]
obj=workbook.open path+"/"+x
sheet=obj.activesheet
n = sheet.UsedRange.Rows.Count
a = sheet.UsedRange.Rows(n).Row
"A".upto("Y"){|x|
#~ puts sheet.Range(x+a.to_s).value
data << sheet.Range(x+a.to_s).value
}
datas << data
obj.close
#~ break
}
#~ puts datas
excel.visible=true
obj=workbook.add
n=1
zm=[]
"A".upto("Z"){|x|
zm << x
}
datas.each{|data|
sheet=obj.activesheet
m=0
data.each{|d|
#~ p zm[m]+n.to_s
sheet.Range(zm[m]+n.to_s).value=d
m+=1
}
n+=1
}
excel.quit
require "win32ole"
excel=WIN32OLE.new("Excel.Application")
excel.visible=false
workbook = excel.Workbooks
#需要处理的文件夹
path="c:/02"
datas=[]
Dir.entries(path) .each{|x|
next if x.length<3
data=[x[0..-11]]
obj=workbook.open path+"/"+x
sheet=obj.activesheet
n = sheet.UsedRange.Rows.Count
a = sheet.UsedRange.Rows(n).Row
"A".upto("Y"){|x|
#~ puts sheet.Range(x+a.to_s).value
data << sheet.Range(x+a.to_s).value
}
datas << data
obj.close
#~ break
}
#~ puts datas
excel.visible=true
obj=workbook.add
n=1
zm=[]
"A".upto("Z"){|x|
zm << x
}
datas.each{|data|
sheet=obj.activesheet
m=0
data.each{|d|
#~ p zm[m]+n.to_s
sheet.Range(zm[m]+n.to_s).value=d
m+=1
}
n+=1
}
excel.quit