Ruport目前自带支持PDF,HTML,CSV,TXT格式输出,如果想打印.xml,.bat报表怎么办?
本例将以XML格式为例,实现Ruport::Formatter的另一种自定义应用。
Ruport的应用参考: Ruby Ruport实践—简单报表系统
注:其他格式的报表只需要修改renders对应的内容(如希望保存为.bat格式,将renders :xml改为renders :bat),模板输出内容均用
"output<<"方法进行输出即可
一、在ReportOutputController中添加xml格式
class ReportXml < Ruport::Formatter renders :xml, :for => ReportOutputController build :data_sheet do eval(options[:outputContent]) end end
二、report_templates中定义为如下内容的模板
output<<"<products>" data.each do |d| output<<"<product>" output<<"<title>#{d.title}</title><type>#{d.description}</type><price>#{d.price}</price>" output<<"</product>" end output<<"</products>"
注:为了测试方便,可将"eval(options[:outputContent])"直接替换成模板内容
演示效果:

Ruport XML报表定制
本文介绍如何使用Ruport gem自定义生成XML格式的报表。通过继承Ruport::Formatter并指定renders参数,可以轻松创建不同格式的报表输出。文章提供了一个具体的例子来说明如何配置XML报表的输出。
194

被折叠的 条评论
为什么被折叠?



