【问题标题】:How to get the cell position in spreadsheet in ruby on rails?如何在 ruby​​ on rails 中获取电子表格中的单元格位置?
【发布时间】:2013-03-25 13:14:13
【问题描述】:

有没有什么方法可以使用 roo、电子表格等 gem 来获取 ruby​​ on rails 中电子表格单元格的位置(坐标)?

假设我在第 C 列和第 2 行中有值“TOTAL”。如何使用 ruby​​ on rails 获得这个职位?

有什么提示吗?

【问题讨论】:

  • 你能把你写的代码贴出来吗??

标签: ruby-on-rails spreadsheet


【解决方案1】:
#http://spreadsheet.rubyforge.org/GUIDE_txt.html

require 'spreadsheet'
book = Spreadsheet.open 'sample.xls'
sheet1 = book.worksheet 0
sheet1.each_with_index do |row, index|
  for column in 0..(row.length-1)
    puts "Row:- #{index}, Column: #{column}, Value: #{row[column]}" 
  end
end

【讨论】:

    【解决方案2】:

    这里是来自roo官方教程http://roo.rubyforge.org/的例子 希望对您有所帮助

    HOURLY_RATE = 123.45
    
    oo = Openoffice.new("simple_spreadsheet.ods")
    oo.default_sheet = oo.sheets.first
    
    4.upto(12) do |line|
        date       = oo.cell(line,'A')
        start_time = oo.cell(line,'B')
        end_time   = oo.cell(line,'C')
        pause      = oo.cell(line,'D')
        sum        = (end_time - start_time) - pause
        comment    = oo.cell(line,'F')
        amount     = sum * HOURLY_RATE
        if date
         puts "#{date}\t#{sum}\t#{amount}\t#{comment}"
     end
    end
    

    【讨论】:

      猜你喜欢
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多