I'm trying to export data from my models to an excel spreadsheet. I have seen 3 ways
Export the data model to XMLIn Oracle Policy Modeling, select View | Data Model. The data model view will open in the right hand pane. In this view, right-click anywhere and select Export to XML... In the Save As dialog box specify a location to save the data model to.
Algorithm: Create the DataFrame. Determine the name of the Excel file. Call to_excel() function with the file name to export the DataFrame.
My choice is to just manualy generate CSV file. Like:
File.new("data.csv", "w+") do |f|
@my_data.each do |data|
f << [data.title, data.body, ...].join(", ") + "\n"
end
end
CSV file can be opened with excel or any other spreadsheet soft.
I'm using writeexcel in my most recent Rails project. A fast and simple to use way to export excel files directly - no CSV!
To use it directly in your views you have to register writeexcel as a template handler - this is excalty what my gist does. Then create a new template like export.xls.writeexcel
, insert your code and you're good to go.
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