1

我一直在尝试转换一个名为spreadsheetDemo的 Dashing 小部件以使用Roo GEM来简化它并允许它满足本地和 Google Doc Excel 文件的需求。(与 Roo 一样)我首先查看了其他小部件和来源(类似于这个只是表格而不是图表)已经在使用 Roo 并且我试图将他们的代码重用于文件源来代替原始代码,从而导致我的代码如下。我正在尝试使用 Roo 访问本地电子表格,获取 6 列和行的标题和数据,然后将它们推送到表中。我相信我的问题可能在于正确访问电子表格。一切都在第一个工作簿上,并从单元格 A1 开始。

我使用的来源:https://github.com/Shopify/dashing/issues/78#issuecomment-14940695

http://stackoverflow.com/questions/29400811/use-with-excel-data-to-display-on-dashing-dashboard/29421179?newreg=5c8c7db27d104f5ab3b855c8ea729bc8

require 'roo'

#Tried using roo-xls as it started throwing errors saying I needed too.
#require 'roo-xls'


EM.kqueue = EM.kqueue?
file_path = "#{Dir.pwd}/spreadsheet.xls"

def fetch_spreadsheet_data(path)
  s = Roo::Excel.new(path)

    ws = workbook.sheets[0]

  # create an array to hold the lines
    rows = Array.new
    header = Array.new

  # other variables
    up = ws.updated.localtime
    up = up.strftime "%d.%m.%Y %H:%M"

    #workbook.default_sheet = workbook.sheets[0]


    # fill lines
    for row in 1..ws.num_rows
      if row == 1
          header.push({ :c1 => ws[row, 1], :c2 => ws[row, 2], :c3 => ws[row, 3], :c4 => ws[row, 4], :c5 => ws[row, 5], :c6 => ws[row, 6]})
      else
        rows.push({ :c1 => ws[row, 1], :c2 => ws[row, 2], :c3 => ws[row, 3], :c4 => ws[row, 4], :c5 => ws[row, 5], :c6 => ws[row, 6]})
      end
    end 
        send_event('spread', :modified => up, :header => header, :rows => rows)
        rescue => err
    #puts "Exception: #{err}"
end



module Handler
  def file_modified
    fetch_spreadsheet_data(path)
  end
end

fetch_spreadsheet_data(file_path)

end
4

0 回答 0