Home arrow Ruby-on-Rails arrow Page 2 - Creating Reports on the Desktop
RUBY-ON-RAILS

Creating Reports on the Desktop


You may know how create a report in Ruby using the Active Record, but that's only half the battle. Reports aren't any good if the users they're intended for can't read them. This article will explain how to adjust reports so that they're more user-friendly to their intended audience. It is excerpted from chapter four of the book Practical Reporting with Ruby and Rails, written by David Berube (Apress; ISBN: 1590599330).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
March 23, 2010
TABLE OF CONTENTS:
  1. · Creating Reports on the Desktop
  2. · Generating an Excel Spreadsheet
  3. · Creating a Spreadsheet Report
  4. · Dissecting the Code

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating Reports on the Desktop - Generating an Excel Spreadsheet
(Page 2 of 4 )

You can generate Excel spreadsheet documents--which, incidentally, can also be opened in the OpenOffice.org spreadsheet application--using the spreadsheet-excel gem. Install this gem by using the following command:

gem install spreadsheet-excel


Tip  If you want to generate Excel-compatible spreadsheets from HTML documents, see Chapter 16. The method described in that chapter is a bit of a hack, and you get less control over your output formatting, but it's extremely easy to implement. The method shown in this chapter offers greater control, such as the ability to arrange your Excel document into multiple sheets.


The following code creates a spreadsheet with "Hello, world!" in the upper-left corner:

require "spreadsheet/excel"
include Spreadsheet

workbook = Excel.new("test.xls")
worksheet = workbook.add_worksheet

worksheet.write(0, 0, 'Hello, world!') workbook.close

This code is reasonably straightforward. You require the code (using the library file name spreadsheet/excel) and include the module, create a new workbook, and then add a sheet to it. Note that each spreadsheet (workbook) can have multiple worksheets, which behave similarly to tabs in a tabbed web browser, such as Mozilla Firefox or Opera. After that, you write the phrase "Hello, world!" to 0,0--the upper-left corner--and then close the workbook, which writes it to the indicated file. You can do other actions as well, such as format cells and columns, as we'll examine next.


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials