开发者

export to excel,pdf and doc using Ruby on Rails

开发者 https://www.devze.com 2022-12-24 06:32 出处:网络
Could y开发者_运维问答ou please help me in exporting files to excel,pdf and .doc format through rails applications?? For Excel

Could y开发者_运维问答ou please help me in exporting files to excel,pdf and .doc format through rails applications??


For Excel

  1. I've used FasterCSV and this post to generate csv files that open in excel very well.
  2. You can also create an HTML table and use iqy files to load excel. To do this you can create some new aliases and then handle the new .iqy and .excel formats.

In config/initializers/mime_types.rb

Mime::Type.register_alias "text/html", :excel
Mime::Type.register "text/x-ms-iqy", :iqy

Then in your controller handle the .iqy and .excel formats

respond_to do |format|
  format.html
  format.excel
  format.iqy {
    text = "WEB\n1\n%s" % URL_FOR_DATA_VIA_GET, :format => :excel)
    render :text => text
  }
end

Your template for the excel format should just be an HTML table with the data in it. The iqy format just renders text, now action template needed. You may want an application.excel.erb file that doesn't have all your navigation etc, so you get a nice clean html table. Also see this KB article for more iqy information.

For PDF

  1. See this other SO question, the suggested plug-in looks good, but I haven't used it.
  2. I've played with, but never actually used in production, prawn. It seemed good, just haven't used it.

For Doc

I would suggest that you just stick with simple text or RTF. I'm not aware of any plug-ins for this, but there is probably something.

Another approach

I've used JasperReports on pure Java projects with great success. It would be possible to use the JasperServer product, JRuby, your own application wrapper, or the ruby-java bridge to generate the outputs with Jasper. See this post. Once you go part Java, you also get the wonderful JExcelApi.

0

精彩评论

暂无评论...
验证码 换一张
取 消