I am trying to create an excel sheet in ruby on rails. So I used the plugin Rexcel. When I am running the application I am getting the following error.
uninitialized constant Rexcel::Workbook::Builder
I had added the following code, then this error hitting
workbook = Rexcel::Workbook.new
worksheet = workbook.add_worksheet("Customers")
worksheet.add_line("name","test")
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = 'attachment; filename="excel-export.xlsx"'
headers['Cache-Control'] = 'max-age=0'
headers['pragma']="public"
workbook.build
How to solve this?
I would advice to use Spreadsheet instead of Rexcel because is definitely more mature and I'm using it with Rails 3 with no problems.
Here is the documentation.
The overall process would be:
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => 'Customers'
sheet.row(0).concat %w{Name Country Acknowlegement}
book.write '/path/to/output/excel-file.xls'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With