簡體   English   中英

Ruby電子表格:在xls文件中獲取列數

[英]Ruby spreadsheet : getting column count in xls file

有沒有辦法使用ruby來計數電子表格文件中的列數? 我正在使用最新版本的電子表格gem。

根據您的需求和情況,似乎有許多可能的解決方案:

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

讓我們知道什么對您有用,以及您通過使用它發現了什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM