Skip to content

Instantly share code, notes, and snippets.

@nakamura-akifumi
Created November 6, 2012 07:30
Show Gist options
  • Save nakamura-akifumi/4023255 to your computer and use it in GitHub Desktop.
Save nakamura-akifumi/4023255 to your computer and use it in GitHub Desktop.
rooでエクセルファイル(xlsx)を読むサンプル
# see 1) http://roo.rubyforge.org/
# 2) http://roo.rubyforge.org/rdoc/index.html
require 'rubygems'
require 'roo'
require 'pp'
oo = Excelx.new("./sample.xlsx")
puts "sheet list"
oo.sheets.each_with_index do |s, i|
puts "sheet no=#{i} name=#{s.to_s}"
end
puts "first sheet cells"
oo.default_sheet = oo.sheets.first
2.upto(8) do |line|
c1 = oo.cell(line,'A')
c2 = oo.cell(line,'B')
c3 = oo.cell(line,'C')
c4 = oo.cell(line,'D')
puts "c1=#{c1} c2=#{c2} c3=#{c3} c4=#{c4}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment