Reputation: 107
If I have two worksheets and I am trying to access values from another worksheet. Is there a way from axlsx gem that can do that?
wb.add_worksheet(name: "Table A".excel_worksheet) do |sheet|
end
wb.add_worksheet(name: "Table B".excel_worksheet) do |sheet|
end
If I am inside worksheet B right now, and want to perform some calculations using the values from table A (for example rows in A). Is there a way to do that?
Upvotes: 1
Views: 445
Reputation: 3139
Here you go, first keep the sheet A around, and secondly use that when you add the chart on sheet B.
sheet_a = wb.add_worksheet(name: "Table A".excel_worksheet) do |sheet|
# ...
end
wb.add_worksheet(name: "Table B".excel_worksheet) do |sheet|
sheet.add_chart(Axlsx::BarChart, start_at: 'A1', end_at: 'F10', title: 'Chart from Table A', ) do |chart|
chart.add_series data: sheet_a["$'Table A'.$B$2:$F$20"]
end
end
Upvotes: 1
Reputation: 475
You can do something like:
sheet_a = wb.add_worksheet(name: "Table A") do |sheet|
sheet
end
wb.add_worksheet(name: "Table B") do |sheet|
puts sheet_a.name
end
Upvotes: 0