Exporting to excel in rails using roo gem
From https://github.com/roo-rb/roo :
Roo implements read access for all common spreadsheet types
for writing you might want to use something like caxlsx_rails
Ruby on Rails: export xlsx export all html page instead the requested data
I found the problem. I added layout: false when I render the xlsx file in the controller and it worked
Appending Columns to xls and xlsx file in Ruby
You can use the simple_xlsx_writer gem to generate and append data into xls files.
$gem install simple_xlsx_writer
Refer this DOC for more of this gem usage and methods.
Rails - Export records to downloadable excel file using axlsx gem (Keep MVC)
Try using axlsx_rails Gem with template.
In my case i used below configuration to make it work. and also a link with extension .xlsx to render it in xlsx format.
GEM FILE
gem 'axlsx', '~> 2.0'
gem "axlsx_rails"
controller file- payments_controller.rb
def download
@payments = Payment.all
respond_to do |format|
format.xlsx {render xlsx: 'download',filename: "payments.xlsx"}
end
end
View file- download.xlsx.axlsx
wb = xlsx_package.workbook
wb.add_worksheet(name: "Payments") do |sheet|
sheet.add_row ["ID", "Notes","Amount($)","Deposit Date"]
@payments.each do |payment|
sheet.add_row [payment.id, payment.notes,payment.amount,payment.date_deposite]
end
end
How to generate an Excel file with Rails?
Bit late to the game, but there you go.
You should use the axlsx gem
On Github:
https://github.com/randym/axlsx
On Rubygems:
https://rubygems.org/gems/axlsx
On Rubytookbox:
https://www.ruby-toolbox.com/projects/axlsx
From the README
p = Axlsx::Package.new
p.workbook do |wb|
wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
img = File.expand_path('../image1.jpeg', __FILE__)
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
image.width=720
image.height=666
image.hyperlink.tooltip = "Labeled Link"
image.start_at 2, 2
end
end
end
rails gem or plugins for reading and writing excel and csv files both
Can you try roo gem for excel
https://github.com/hmcgowan/roo
And for CSV
https://github.com/arydjmal/to_csv
Related Topics
Installing Rails: "File Not Found: Lib"
Ruby: Finding Most Recently Modified File
Rails Model Has_Many , Belongs_To Relations
Find Most Common String in an Array
Generate Letters to Represent Number Using Ruby
Modifying Database Ids from Rails Console
How to Run Rake Tasks Within My Rails Application
Force Bundle Install to Use Https:// Instead of Git:// for Github-Based Gems
Detect Number of Cpus Installed
How to Avoid Duplicates in a Has_Many :Through Relationship
Error Installing Homebrew - Brew Command Not Found
Why Does Ruby Open-Uri's Open Return a Stringio in My Unit Test, But a Fileio in My Controller
Rails with Paypal Permissions and Paypal Express Checkout
Could Not Find a Valid Gem 'Rails' (>= 0) in Any Repository
Will Uuid as Primary Key in Postgresql Give Bad Index Performance