2016-10-11 7 views
-1

ルビを使用してスプレッドシートファイルの列数を数える方法はありますか?私はスプレッドシートの最新版を使用しています。Rubyスプレッドシート:xlsファイルの列数を取得する

+0

どの「スプレッドシートの宝石」を使用していますか?それらのいくつかがあります。 – Josh

+0

その名前の宝石は1つだけです... https://github.com/zdavatz/spreadsheet – danynl

+0

ちょうど明確にしようとしています。特定の名前のルビー宝石には1つの宝石しかありませんが、多くのスプレッドシートの宝石があります。 – Josh

答えて

1

ニーズや状況に基づいて、可能な解の数があるように見えます:

book = Spreadsheet.open('/path/to/an/excel-file.xls') 
sheet1 = book.worksheet(0) 

# get the number of columns in the first row 
sheet1.row(0).size 

# get the maximum number of columns in all the rows 
sheet1.rows.max_by(&:size) 

# use the dimension logic from the gem. It looks like this ignores empty columns at the beginning of the sheet 
sheet1.column_count 

column_countソース: https://github.com/zdavatz/spreadsheet/blob/master/lib/spreadsheet/worksheet.rb#L96-L99

は、私たちはあなたのために働くものを知ってみましょう、あなたがで見つけるものをそれと遊ぶ。

+0

これはうまくいく、ありがとう。 – danynl

関連する問題