朋友們,我無法從“狀態”列中僅獲取第一個 Invisible 值,或者僅獲取“否”。Elemento 列中的比重計值,或所有值。朋友我的電子表格是這樣配置的。
| 元素 | 狀態 | | No Hidr?metro |Invisível | | 萊圖拉 |Invisível | | Diametro do HD |Invisível | | 過濾器 |Invisível |
I need to get the following values:
-- Only the Status column with the value in the first row equal to 'Invisible'
-- All values ??in the Status column only
-- All values ??in Element column only
-- All values ??in rows and columns
require 'spreadsheet'
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet.open('C:/temp/pasta1.xls', "r")
sheet = book.worksheet 0
pp sheet.row(0)
uj5u.com熱心網友回復:
| 元素 | 地位 |
|---|---|
| 1 | 可見的 |
| 2 | 無形的 |
>> book = Spreadsheet.open("excel.xls", "r")
>> sheet = book.worksheet(0)
>> element_column = sheet.first.find_index("element")
=> 0
>> status_column = sheet.first.find_index("status")
=> 1
只有第一行中的值等于“不可見”的狀態列
>> sheet.detect { |row| row[status_column] =~ /invisible/i }&.fetch(status_column)
=> "Invisible"
僅Status列中的所有值
>> sheet.column(status_column).to_a[1..]
=> ["Visible", "Invisible"]
僅Element列中的所有值
>> sheet.column(element_column).to_a[1..]
=> [1, 2]
行和列中的所有值
>> sheet.rows[1..]
=> [[1, "Visible"], [2, "Invisible"]]
https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md#reading-is-easy
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/498158.html
標籤:红宝石
