Ruby on rails 在RubyonRails中导出Excel
我想将页面信息导出到Excel,谁能告诉我怎么做?Ruby on rails 在RubyonRails中导出Excel,ruby-on-rails,export-to-excel,Ruby On Rails,Export To Excel,我想将页面信息导出到Excel,谁能告诉我怎么做? 谢谢大家! 类似的内容可能会有所帮助: 控制器 class UserController < ApplicationController def export headers['Content-Type'] = "application/vnd.ms-excel" headers['Content-Disposition'] = 'attachment; filename="report.xls"' head
谢谢大家! 类似的内容可能会有所帮助: 控制器
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
class UserController
查看
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>
export.html.erb
_report.html.erb
名称
谢谢您的帮助!现在,我使用电子表格插件来解决这个问题,为了它的价值,我检查了一些选项来完成这项工作,最后使用电子表格gem()。文档有点小,但功能相当强大,我能够扩展它以满足我的需要。请下次先用谷歌搜索(例如“rails导出到excel”为您提供与人们在评论部分为您提供的页面相同的页面;)