Class Spreadsheet::Workbook
In: lib/spreadsheet/workbook.rb
Parent: Object
Column Format Row Font Enumerable Worksheet\n[lib/spreadsheet/excel.rb\nlib/spreadsheet/worksheet.rb] Link Workbook Workbook\n[lib/spreadsheet/excel.rb\nlib/spreadsheet/excel/workbook.rb] SstEntry String Row Array Worksheet ExcelCompatibleWorkbook Format Worksheet Workbook DelegateClassSpreadsheet::Format Writer Compatibility Formula Reader\n[lib/parseexcel/parseexcel.rb\nlib/spreadsheet/excel/reader.rb\nlib/spreadsheet/excel/reader/biff5.rb\nlib/spreadsheet/excel/reader/biff8.rb] Error lib/spreadsheet/excel.rb lib/spreadsheet/link.rb lib/spreadsheet/formula.rb lib/spreadsheet/workbook.rb lib/spreadsheet/font.rb lib/spreadsheet/column.rb lib/spreadsheet/format.rb lib/spreadsheet/writer.rb lib/spreadsheet/row.rb Encodings lib/spreadsheet/excel.rb lib/spreadsheet/excel/row.rb lib/spreadsheet/excel/reader/biff5.rb lib/spreadsheet/excel/worksheet.rb lib/spreadsheet/excel/sst_entry.rb lib/spreadsheet/excel/error.rb lib/spreadsheet/excel/workbook.rb lib/spreadsheet/excel/writer/format.rb lib/spreadsheet/excel/writer/workbook.rb lib/spreadsheet/excel/writer/worksheet.rb Biff8 Writer Biff5 Biff8 Internals Offset Excel Datatypes ParseExcel Compatibility Spreadsheet dot/m_34_0.png

The Workbook class represents a Spreadsheet-Document and is the entry point for all Spreadsheet manipulation.

Interesting Attributes:

default_format:The default format used for all cells in this Workbook. that have no format set explicitly or in Row#default_format or Worksheet#default_format.

Methods

Included Modules

Spreadsheet::Encodings

Attributes

active_worksheet  [RW] 
default_format  [RW] 
encoding  [RW] 
fonts  [R] 
formats  [R] 
io  [R] 
version  [RW] 
worksheets  [R] 

Public Class methods

[Source]

    # File lib/spreadsheet/workbook.rb, line 17
17:     def initialize io = nil, opts={:default_format => Format.new}
18:       @worksheets = []
19:       @io = io
20:       @fonts = []
21:       @formats = []
22:       if @default_format = opts[:default_format]
23:         @formats.push @default_format
24:       end
25:     end

Public Instance methods

Add a Font to the Workbook. Used by the parser. You should not need to use this Method.

[Source]

    # File lib/spreadsheet/workbook.rb, line 29
29:     def add_font font
30:       @fonts.push(font).uniq! if font
31:       font
32:     end

Add a Format to the Workbook. If you use Row#set_format, you should not need to use this Method.

[Source]

    # File lib/spreadsheet/workbook.rb, line 36
36:     def add_format format
37:       @formats.push(format) if format && !@formats.include?(format)
38:       format
39:     end

Add a Worksheet to the Workbook.

[Source]

    # File lib/spreadsheet/workbook.rb, line 42
42:     def add_worksheet worksheet
43:       worksheet.workbook = self
44:       @worksheets.push worksheet
45:       worksheet
46:     end

Create a new Worksheet in this Workbook. Used without options this creates a Worksheet with the name ‘WorksheetN’ where the new Worksheet is the Nth Worksheet in this Workbook.

Use the option :name => ‘My pretty Name‘ to override this behavior.

[Source]

    # File lib/spreadsheet/workbook.rb, line 54
54:     def create_worksheet opts = {}
55:       opts[:name] ||= client("Worksheet#{@worksheets.size.next}", 'UTF-8')
56:       add_worksheet Worksheet.new(opts)
57:     end

The Font at idx

[Source]

    # File lib/spreadsheet/workbook.rb, line 60
60:     def font idx
61:       @fonts[idx]
62:     end

The Format at idx, or - if idx is a String - the Format with name == idx

[Source]

    # File lib/spreadsheet/workbook.rb, line 66
66:     def format idx
67:       case idx
68:       when Integer
69:         @formats[idx] || @default_format
70:       when String
71:         @formats.find do |fmt| fmt.name == idx end
72:       end
73:     end

[Source]

    # File lib/spreadsheet/workbook.rb, line 74
74:     def inspect
75:       variables = (instance_variables - uninspect_variables).collect do |name|
76:         "%s=%s" % [name, instance_variable_get(name)]
77:       end.join(' ')
78:       uninspect = uninspect_variables.collect do |name|
79:         var = instance_variable_get name
80:         "%s=%s[%i]" % [name, var.class, var.size]
81:       end.join(' ')
82:       sprintf "#<%s:0x%014x %s %s>", self.class, object_id,
83:                                      variables, uninspect
84:     end

The Worksheet at idx, or - if idx is a String - the Worksheet with name == idx

[Source]

    # File lib/spreadsheet/workbook.rb, line 91
91:     def worksheet idx
92:       case idx
93:       when Integer
94:         @worksheets[idx]
95:       when String
96:         @worksheets.find do |sheet| sheet.name == idx end
97:       end
98:     end

Write this Workbook to a File, IO Stream or Writer Object. The latter will make more sense once there are more than just an Excel-Writer available.

[Source]

     # File lib/spreadsheet/workbook.rb, line 102
102:     def write io_path_or_writer
103:       if io_path_or_writer.is_a? Writer
104:         io_path_or_writer.write self
105:       else
106:         writer(io_path_or_writer).write(self)
107:       end
108:     end

Returns a new instance of the default Writer class for this Workbook (can only be an Excel::Writer::Workbook at this time)

[Source]

     # File lib/spreadsheet/workbook.rb, line 112
112:     def writer io_or_path, type=Excel, version=self.version
113:       if type == Excel
114:         Excel::Writer::Workbook.new io_or_path
115:       else
116:         raise NotImplementedError, "No Writer defined for #{type}"
117:       end
118:     end

[Validate]