使用Axlsx gem创建引用另一个工作表的条形图

时间:2017-03-22 17:49:06

标签: ruby-on-rails ruby excel charts axlsx

我目前正在使用Axlsx gem在excel中创建条形图。但是,我正在尝试在一张纸上创建一个条形图,该条形图引用另一张纸上的值,但我遇到了错误。

这是我的代码:

sheet.add_chart(Axlsx::Bar3DChart, :start_at => "B5", :end_at => "I25", :title=> "Top Weight Step (0.5-15) Volume Month over Month", :barDir => :col) do |bars|
   bars.add_series :data => sheet["'Weightsteps Month over Month'!F10:F25"],
    :labels => sheet["'Weightsteps Month over Month'!B10:B25"], 
    :title => sheet["'Weightsteps Month over Month'!F9"]
   bars.valAxis.gridlines = false
   bars.catAxis.gridlines = false
end

1 个答案:

答案 0 :(得分:0)

Haven找不到解决方案了。与此同时,解决方法只是将您需要的数据调用到当前工作表并使用这些值创建图表。所以我做了:

15.times do |count|
   sheet.add_row ["='Weightsteps Month over Month'!B#{count}",
                  "='Weightsteps Month over Month'!C#{count}"]
end

sheet.add_chart(Axlsx::Bar3DChart, 
   :start_at => "D5", 
   :end_at => "I20", 
   :title=> "Top Weight Step (0.5-15) Volume Month over Month", 
   :barDir => :col) do |bars|

   bars.add_series 
   :data => sheet["A1:A15"], 
   :labels => sheet["B1:B15"]
end