Hi, Does anyone know of a package that will help with generation of spreadsheets? (xls files, not csv) Thanks, Fredrik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fredrick, I understand there are 2 routes you can take. 1. write to an open format - this likely depends on the version of Office you want to support. 2. Write a native office document using the win32 gem win32ole. I used the second option to generate word documents. Do a google search for win32ole and ruby - you''ll find a few examples that should get you started. Cheers, Jodi General Partner The nNovation Group inc. www.nnovation.ca/blog On 17-Jan-07, at 12:24 PM, Fredrik wrote:> > Hi, > > Does anyone know of a package that will help with generation of > spreadsheets? (xls files, not csv) > > Thanks, > Fredrik > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fredrik wrote:> Hi, > > Does anyone know of a package that will help with generation of > spreadsheets? (xls files, not csv) > > Thanks, > FredrikHi, I think you can use XHTML Templates and serve them with a .xls file extension and application header. I''ve done this with word docs and works a treat. For Example (With Word): 1. Create a "template" document in microsoft word with place holders for dynamic data 2. Save as Microsoft HTML 3. Use this document to develop a template. 3. Serve up as a Word Document with a .doc extension. I assume you can this with Excel too. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/17/07, Jodi Showers <jodi-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org> wrote:> > Fredrick, I understand there are 2 routes you can take. > > 1. write to an open format - this likely depends on the version of > Office you want to support. > 2. Write a native office document using the win32 gem win32ole. > > I used the second option to generate word documents. > > Do a google search for win32ole and ruby - you''ll find a few examples > that should get you started.The Ruby-POI bindings are another option. I''ve never used these myself, however, it seems like a great cross-platform solution. http://jakarta.apache.org/poi/poi-ruby.html> Cheers, > Jodi > General Partner > The nNovation Group inc. > www.nnovation.ca/blog > On 17-Jan-07, at 12:24 PM, Fredrik wrote: > > > > > Hi, > > > > Does anyone know of a package that will help with generation of > > spreadsheets? (xls files, not csv) > > > > Thanks, > > Fredrik > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I currently use spreadsheet/excel (http://raa.ruby-lang.org/project/spreadsheet/) and it''s been working quite well for me. It ends up looking like this: class SpreadsheetController < ApplicationController require ''spreadsheet/excel'' include Spreadsheet def item_list file_path = "tmp/file.xls" # this should actually be a Tempfile object workbook = Excel.new(file_path) worksheet = workbook.add_worksheet format_text = workbook.add_format(:font => ''Verdana'') format_header = workbook.add_format(:font => ''Verdana'', :bold => true, :bg_color => 22, :top => 1, :bottom => 1, :left => 1, :right => 1) # Set column widths worksheet.format_column(0, 12, format_text) worksheet.format_column(1, 15, format_text) #Output column headings worksheet.write(0, 0, ''Item Code'', format_header) worksheet.write(0, 1, ''Item Name'', format_header) #Output actual data items = Item.find(:all) items.each_with_index do |item, i| worksheet.write(i + 1, 0, item.code, format_text) worksheet.write(i + 1, 1, item.name, format_text) end workbook.close send_file file_path, :filename => ''Item List.xls'', :type => ''application/vnd.ms-excel'' end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks guys, that was a bunch of options, some of which I had no idea you could do. That definately solves my problem. :) -Fredrik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I had some time to do some testing and the spreadsheet writer was very familiar from php :) and worked great (current implementation). I did try out the win32ole, but I could not get it to work. Got some file missing error. After browsing around it seemed like you have to have office installed, since it was talking about people installing it with wine, etc under linux. Is this the case? I did try it under windows. The POI extensions seemed ok too, but I could not see what they offer beyond the excel writer gem for my needs (for now download data, modify and upload it back) I am looking for something to read excel files too, and from what I saw, it''s planned for in the POI extensions, but don''t think it is implemented yet. Please let me know if you get a chance about the POI and win32ole assumptions I made if they are correct or not. Thanks, Fredrik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fredrik wrote:> I am looking for something to read excel files too, and from what I > saw, it''s planned for in the POI extensions, but don''t think it is > implemented yet.Although I haven''t had any need for it within any Rails applications, I have used ParseExcel to do this in a few stand-alone ruby scripts, and it''s worked well for me. It should work equally well in a Rails app. Check it out! http://raa.ruby-lang.org/project/parseexcel/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ashleymg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-22 20:35 UTC
Re: Excel sheet generation
I know this is a little late and it''s not a package, but this might help someone searching down the road: Excel 2003 supports XML formats: http://www.microsoft.com/office/xml/default.mspx There''s even a blog: http://blogs.msdn.com/brian_jones/archive/2005/06/27/433152.aspx>From what I could gather, it it *needs* excel 2003.On Jan 17, 12:24 pm, "Fredrik" <fredrik.thures...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Does anyone know of a package that will help with generation of > spreadsheets? (xls files, not csv) > > Thanks, > Fredrik--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yet another way to do it, probably more comfortable if you come from a Java background. Use Rjb (Ruby - Java bridge), and use the Java Excel API (http://www.andykhan.com/jexcelapi/). Here''s some code to read an Excel file: require ''rjb'' require_gem ''rjb'', ''>= 1.0.2'' ... #Returns a Java jxl.Workbook object which may then be used natively. But don''t forget that it''s a Java object! def ESimplyUtil.parse_excel(filename) Rjb::load("#{RAILS_ROOT}/lib/jxl.jar", [''-Xmx512M'']) file_class = Rjb::import(''java.io.File'') workbook_class = Rjb::import(''jxl.Workbook'') workbook = workbook_class.getWorkbook(file_class.new(filename)) end Writing is similarly straightforward. In my app. I ended up writing CSV using FasterCSV, but I did test out writing with JExcelAPI and it worked fine. Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gosh, I''m gonna have to work overtime now to check all these things out. I think Chris'' suggestion about the parse excel would be a nice complement to the excel writer I''m currently using. This is nothing overly complicated I''m trying to do. I have written some java code, but that was a long time ago. Not familiar with much of it. Thanks again guys. Hopefully all your answers will help someone else too. Fredrik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Believe me, Fredrik, I didn''t go with the Java code on the first try. There was something about parseexcel that was missing for me that forced me in that direction. I would recommend parseexcel first, the Java thing is a "just in case." Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of > ashleymg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > Sent: Monday, January 22, 2007 1:36 PM > To: Ruby on Rails: Talk > Subject: [Rails] Re: Excel sheet generation > > > > I know this is a little late and it''s not a package, but this > might help someone searching down the road: Excel 2003 > supports XML formats: http://www.microsoft.com/office/xml/default.mspx > > There''s even a blog: > http://blogs.msdn.com/brian_jones/archive/2005/06/27/433152.aspxThis is the route I would go for a next-gen version of the spreadsheet package if I had to do over again. We''ve got XML generating libraries in pure Ruby (Jim Weirich has one out there, can''t think of the name atm), or a wrapper around a C lib would work. From there it''s just a matter of working out the interface, which you could probably keep very similar (if not identical) to the current implementation. This would solve several problems with the current implementation: * Formula support * Solves 7mb limit (afaik) * Human readable * Greater compatibility with other clients * MUCH easier to debug and maintain. Looking for bugs in packed binary strings SUCKS. Feel free to pass this on to Hannes on the RubyForge project page. Or better yet, join the project and start working on the implementation. I still have admin rights on the project as well, so if you''re serious about creating an XML based implementation, you can contact me offlist as well: djberg96 at nospam at gmail dot com http://rubyforge.org/projects/spreadsheet/ Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---