This tutorial will help you integrate the CloudXLS API in a Ruby/Ruby on Rails application.

The first step is adding the cloudXLS gem to your application’s Gemfile and run bundle install.

gem 'cloudxls-ruby'
Setup the cloudXLS API key which you can find on the cloudXLS dashboard.

Generate and download xls file
Now we’re creating an Excel file with some sample CSV data. The cloudXLS API accepts data as plain text, multi-part file uploads or from URLs. For small data plain text is recommended.


response = CloudXLS.inline({
data: {text: "Greeting,Receiver\nhello,world\nhello,excel"},
sheet: {name: "Greetings"},
doc: {filename: "hello_excel.xls"}
})"out.xls", "wb") { |f| f.write response }
Use cloudXLS async mode
Instead of downloading the Excel file to your server first and serving it from there, you can also choose to redirect the user to download the file directly from cloudXLS server, the URL is time-limited.


response = CloudXLS.async({
data: {file:"/path/to/data.csv")},
sheet: {name: "Greetings"},
doc: {filename: "hello_excel.xls"}

puts response.url
# in a Rails action:
# redirect_to response.url

Merge data into Templates
To copy data into an Excel template send a xls or xlsx file with the doc[template] parameter.

data: {text: "Greeting,Receiver\nhello,world"},
sheet: {name: "Greetings"},
doc: {template:"/path/to/template.xls")}

More Examples
Check the examples folder in the repository.

You've setup Excel exports for your Ruby app.

Next steps:
If you haven't already Sign up now

Copyright © 2021 | All rights reserved