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

你可能感兴趣的:(Excel,Ruby,ruby excel,rails excel)