Dashing Dashboard上的Excel数据表?

时间:2015-11-16 09:45:44

标签: ruby-on-rails excel dashing roo

我一直在尝试转换名为spreadsheetDemo的Dashing小部件,以使用Roo GEM来简化它,并允许它来满足本地和Google Doc Excel文件。(就像Roo一样) ) 我首先查看已经使用Roo的其他小部件和源代码(类似于表格而非图表),我尝试将其代码重用于文件源代替原始代码,从而生成下面的代码。 我正在尝试使用Roo访问本地电子表格,获取6列和行的标题和数据,然后将它们推送到表格。 我相信我的问题可能在于正确访问speadsheet。 一切都在第一本工作簿上,并从单元格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

0 个答案:

没有答案