繁体   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