org spreadsheet application??”using the spreadsheet-excel gem. Install
this gem by using the following command:
CHAPTER 4 n CREATING REPORTS ON THE DESKTOP 52
gem install spreadsheet-excel
nTip 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.
Pages:
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95