LoginSignup
32
34

More than 5 years have passed since last update.

RubyでExcelシートの操作をする

Last updated at Posted at 2013-02-22

ドキュメント

gem install spreadsheet
sample.rb
require 'spreadsheet'

Spreadsheet.client_encoding = 'UTF-8'
dir = './'
file = 'sheet.xls'
book = Spreadsheet.open File.join(dir, file)

# ワークシートの数
puts book.worksheets.count

# 1番目のワークシートを取得
ws = book.worksheets[0]

# ワークシート名
puts ws.name

# ワークシートの行数
puts ws.row_count

# ワークシートの列数
puts ws.column_count

# 1行目を取得
puts ws.row(0)

# 1行目の1列目を取得
puts ws.row(0)[0]

# ワークシートを順番に処理
book.worksheets.each {|ws|
}
32
34
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
34