`

Rails中导出excel的快速简便的方法

阅读更多

controller

 

 

  def to_excele
    headers['Content-Type'] = "application/vnd.ms-excel"
    headers['Content-Disposition'] = 'attachment; filename="report.xls"'
    headers['Cache-Control'] = ''
    @posts = Post.find(:all)
    render :layout => false
  end

 

 

view

 

<html>
  <head>
  <meta http-equiv="Content-Type" content="charset=utf-8" />
  <title>excele表格</title>
  </head>
  <body>
<table border="1">
  <tr><td>标题</td></tr>
  <%@posts.each do |post|%>
<tr>
  <td><%=post.title%></td>
</tr>
<% end %>
</table>
</body>
</html>

 

from:http://bot.iteye.com/blog/442422

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics