使用 to_xls 未显示标题
我正在使用 gem to_xls ,从 activerecords 生成 xls 文件非常棒。但由于某种原因,我无法显示标题。
这是控制器:
format.xls {
send_data @tickets.to_xls(
:columns => [:created_at, :title, {:category => :title}, {:group => :name}, {:location => :name}, :starts, :target, {:requestor => :full_name}, :percent_complete, :recurring, :cost, :spent, :task_level],
:headers => [:created, :name, :category, :group, :location, :start_date, :target_date, :requestor, :percent_complete, :recurring, :cost, :spent, :task_level]
)
}
I'm using the gem to_xls and it's great to generate xls files from activerecords. But for some reason I'm not able to get headers to show up.
Here's the controller:
format.xls {
send_data @tickets.to_xls(
:columns => [:created_at, :title, {:category => :title}, {:group => :name}, {:location => :name}, :starts, :target, {:requestor => :full_name}, :percent_complete, :recurring, :cost, :spent, :task_level],
:headers => [:created, :name, :category, :group, :location, :start_date, :target_date, :requestor, :percent_complete, :recurring, :cost, :spent, :task_level]
)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
to_xls 插件不显示具有关联模型的标头,因为它无法理解属性名称。
您可以尝试为标题提供字符串而不是属性:
to_xls plugin does not show headers with associated models because it can't understand attribute names.
You can try to give strings to headers instead of attributes: