Class Spreadsheet::Row
In: lib/spreadsheet/row.rb
Parent: Array
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 Row class. Encapsulates Cell data and formatting. Since Row is a subclass of Array, you may use all the standard Array methods to manipulate a Row. By convention, Row#at will give you raw values, while Row#[] may be overridden to return enriched data if necessary (see also the Date- and DateTime-handling in Excel::Row#[]

Useful Attributes are:

idx:The 0-based index of this Row in its Worksheet.
formats:A parallel array containing Formatting information for all cells stored in a Row.
default_format:The default Format used when writing a Cell if no explicit Format is stored in formats for the cell.
height:The height of this Row in points (defaults to 12).

Methods

Included Modules

Datatypes

Attributes

default_format  [R] 
formats  [R] 
height  [RW] 
idx  [RW] 
worksheet  [RW] 

Public Class methods

[Source]

    # File lib/spreadsheet/row.rb, line 22
22:       def format_updater *keys
23:         keys.each do |key|
24:           unless instance_methods.include? "unupdated_#{key}="
25:             alias_method "unupdated_#{key}=""unupdated_#{key}=", "#{key}=""#{key}="
26:             define_method "#{key}=" do |value|
27:               send "unupdated_#{key}=", value
28:               @worksheet.row_updated @idx, self if @worksheet
29:               value
30:             end
31:           end
32:         end
33:       end

[Source]

    # File lib/spreadsheet/row.rb, line 60
60:     def initialize worksheet, idx, cells=[]
61:       @default_format = nil
62:       @worksheet = worksheet
63:       @idx = idx
64:       super cells
65:       @formats = []
66:       @height = 12.1
67:     end

[Source]

    # File lib/spreadsheet/row.rb, line 34
34:       def updater *keys
35:         keys.each do |key|
36:           ## Passing blocks to methods defined with define_method is not possible
37:           #  in Ruby 1.8:
38:           #  http://groups.google.com/group/ruby-talk-google/msg/778184912b769e5f
39:           #  use class_eval as suggested by someone else in
40:           #  http://rubyforge.org/tracker/index.php?func=detail&aid=25732&group_id=678&atid=2677
41:           class_eval "def \#{key}(*args)\nres = super(*args)\n@worksheet.row_updated @idx, self if @worksheet\nres\nend\n", __FILE__, __LINE__
42:         end
43:       end

Public Instance methods

Set the default Format used when writing a Cell if no explicit Format is stored for the cell.

[Source]

    # File lib/spreadsheet/row.rb, line 71
71:     def default_format= format
72:       @worksheet.add_format format if @worksheet
73:       @default_format = format
74:     end
first_unused()

Alias for formatted_size

first_used the 0-based index of the first non-blank Cell.

[Source]

    # File lib/spreadsheet/row.rb, line 78
78:     def first_used
79:       [ index_of_first(self), index_of_first(@formats) ].compact.min
80:     end

The Format for the Cell at idx (0-based), or the first valid Format in Row#default_format, Column#default_format and Worksheet#default_format.

[Source]

    # File lib/spreadsheet/row.rb, line 84
84:     def format idx
85:       @formats[idx] || @default_format \
86:         || @worksheet.column(idx).default_format if @worksheet
87:     end

Returns a copy of self with nil-values appended for empty cells that have an associated Format. This is primarily a helper-function for the writer classes.

[Source]

    # File lib/spreadsheet/row.rb, line 92
92:     def formatted
93:       copy = dup
94:       @formats.rcompact!
95:       if copy.length < @formats.size
96:         copy.concat Array.new(@formats.size - copy.length)
97:       end
98:       copy
99:     end

Same as Row#size, but takes into account formatted empty cells

[Source]

     # File lib/spreadsheet/row.rb, line 102
102:     def formatted_size
103:       @formats.rcompact!
104:       sz = size
105:       fs = @formats.size
106:       fs > sz ? fs : sz
107:     end

[Source]

     # File lib/spreadsheet/row.rb, line 112
112:     def inspect
113:       variables = instance_variables.collect do |name|
114:         "%s=%s" % [name, instance_variable_get(name)]
115:       end.join(' ')
116:       sprintf "#<%s:0x%014x %s %s>", self.class, object_id, variables, super
117:     end

Set the Format for the Cell at idx (0-based).

[Source]

     # File lib/spreadsheet/row.rb, line 120
120:     def set_format idx, fmt
121:       @formats[idx] = fmt
122:       @worksheet.add_format fmt
123:       @worksheet.row_updated @idx, self if @worksheet
124:       fmt
125:     end

[Validate]