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



我目前正在使用 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

无法找到解决方案。同时,解决方法就是将所需的数据调用到当前工作表上,并使用这些值创建图表。所以我做了:

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 

最新更新