Skip to content

Instantly share code, notes, and snippets.

@zhangxu
Created March 7, 2016 20:06
Show Gist options
  • Save zhangxu/9e1e64a6e2d6f0c35c41 to your computer and use it in GitHub Desktop.
Save zhangxu/9e1e64a6e2d6f0c35c41 to your computer and use it in GitHub Desktop.
Generate Xls
@sheets = [
{
:name => "s 1",
:headers => ["h11", "h12"],
:rows => [["s1r1c1", "s1r1c2"], ["s1r2c1", "s1r2c2"]]
},
{
:name => "s2",
:headers => ["h21", "h22"],
:rows => [["s2r1c1", "s2r1c2"], ["s2r2c1", "s2r2c2"]]
}
]
t = ERB.new File.new("#{Rails.root}/app/views/cals/index.xls.erb").read
File.open('/workspace/data/output.xls', 'w') { |file| file.write(t.result(binding())) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment