使用 to_xls 未显示标题

发布于 2024-12-05 02:39:18 字数 703 浏览 0 评论 0原文

我正在使用 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.

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海的爱人是光 2024-12-12 02:39:18

to_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"]
    )
}

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:

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"]
    )
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文