1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RubyでODSファイルからデータを取り出す

Last updated at Posted at 2012-12-26

元ネタは http://www.simplegimmick.com/2007/06/read-ods-like-csv/ です(2012-04-05現在、記事がみつかりません)。

2016-11-04追記: GitHubで公開されていました。今まで全然気付かなかった……
simgim/ods-reader: ods reader is a library for reading .ods (OpenOffice Spreadsheet) file.

  1. https://gist.github.com/185322 にある ods.rb をダウンロードします。

    % wget https://raw.github.com/gist/185322/f00115c70ee62ff2a4788b59358881718e24bbcc/ods.rb
    
  2. 動作にはnokogiriとrubyzipが必要です。

    % gem install nokogiri rubyzip
    
  3. ODSクラスを使って、ODSファイルからデータを取り出すことが出来ます。

    require_relative 'ods'
    ods = ODS.new.parse_file('sample.ods')
    sheet = ods.sheet('Sheet 1')
    row = sheet[1]	# 1行目(0オリジン)
    cell = row[2]	# 2(C)列目(0オリジン)
    cell.value		# => C2のセルの内容
    
  4. ODSCSVクラスを使って、CSVライクにODSファイルからデータを取り出すことも出来ます。

    ODSCSV.open('sample.ods') do |rows|
    	rows # => 各行のデータを配列で取り出せる
    end
    
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?