[英]I'm using the ruby gem “roo” to read xlsx file, how to return the content of one column as an array?
[英]How to access the column/row info of existing content of a xlsx file
我想獲取現有 xlsx 文件的最后一列和最后一行的信息,以便我可以在現有內容的正下方 append 新內容。 我如何使用 RubyXL 做到這一點? 如果那不可能,您會推薦什么替代寶石?
正如我在評論中所寫,我不知道這是否正是您要查找的內容:
require 'rubyXL'
workbook = RubyXL::Parser.parse("Workbook1.xlsx")
worksheet = workbook[0]
rows = worksheet.map {|row| row && row.cells.each { |cell| cell && cell.value != nil}}
p last_row = rows.size
p last_column = rows.compact.max_by{|row| row.size}.size
讓worksheet
成為第一個(例如worksheet = workbook[0]
)。
你可以使用:
last_row = worksheet.count
last_col = worksheet.map{|i| i.cells.count}.max
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.