Skip to content

Instantly share code, notes, and snippets.

@okhiroyuki
Created March 31, 2010 01:14
Show Gist options
  • Save okhiroyuki/349811 to your computer and use it in GitHub Desktop.
Save okhiroyuki/349811 to your computer and use it in GitHub Desktop.
Import CSV Data to Excel
#! ruby -Ks
require "exlap"
filename2 = "template.xls"
path = "./hoge"
a_path = Dir.entries(path)
xl = Exlap.new
i = 0
Dir.foreach(path){|file|
if(i > 1) then
filename1 = File.join(path,"\\",file)
wb1 = xl.book_opentext({'Filename'=>filename1,
'DataType'=>XlDelimited,
'Tab'=>true, 'TextQualifier'=>XlTextQualifierNone,
'FieldInfo'=>[[1,XlTextFormat]]})
wb2 = xl.book_open({'Filename' => filename2,'ReadOnly' => true})
ss1 = wb1.select_sheet(1)
ss2 = wb2.select_sheet(1)
addr = ss1.UsedRange.Address
ss1.Range(addr).Copy(ss2.Range(addr))
newfile = File.basename(filename1,".*") + ".xls"
wb2.save newfile
wb1.close
wb2.close
end
i+=1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment