这样的事情可能会有所帮助:
http://blog.dhavalparikh.co.in/2009/04/export-to-excel-in-ruby-on-rails/
调节器
class UserController < ApplicationController
def export
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = 'attachment; filename="report.xls"'
headers['Cache-Control'] = ''
@users = User.find(:all)
end
Run Code Online (Sandbox Code Playgroud)
视图
export.html.erb
<%= link_to "Export as Excel", export_person_url %>
_report.html.erb
<table border="1">
<tr>
<th>Name</th>
</tr>
<% @users.each do |u| %>
<tr>
<td><%= u.name %></td>
<% end %>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5792 次 |
| 最近记录: |