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.
Creating a Spreadsheet Report
Let??™s say that your manager at Transmegtech Studios, the fictional game development
company we??™ve used for the examples in previous chapters, wants a report on the game
players??™ win/loss records per game in the form of a formatted spreadsheet. Listing 4-1
shows the script to create a simple Excel report.
Listing 4-1. Player Win/Loss Spreadsheet (spreadsheet_team_performance.rb)
require 'active_record'
require 'optparse'
require 'rubygems'
require 'active_record'
CHAPTER 4 n CREATING REPORTS ON THE DESKTOP 53
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'insert_your_mysql_username_here',
:password => 'insert_your_mysql_password_here',
:database => 'players_4')
class Player < ActiveRecord::Base
has_many :plays
end
class Game < ActiveRecord::Base
has_many :plays
end
class Play < ActiveRecord::Base
belongs_to :game
belongs_to :player
end
require 'spreadsheet/excel'
include Spreadsheet
spreadsheet_file = "spreadsheet_report.
Pages:
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96