Parent

Spreadsheet::Row

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).

Attributes

formats[R]

(Not documented)

default_format[R]

(Not documented)

idx[RW]

(Not documented)

height[RW]

(Not documented)

worksheet[RW]

(Not documented)

Public Class Methods

format_updater(*keys) click to toggle source

(Not documented)

# File lib/spreadsheet/row.rb, line 22
      def format_updater *keys
        keys.each do |key|
          unless instance_methods.include? "unupdated_#{key}="
            alias_method :"unupdated_#{key}=", :"#{key}="
            define_method "#{key}=" do |value|
              send "unupdated_#{key}=", value
              @worksheet.row_updated @idx, self if @worksheet
              value
            end
          end
        end
      end
new(worksheet, idx, cells=[]) click to toggle source

(Not documented)

# File lib/spreadsheet/row.rb, line 60
    def initialize worksheet, idx, cells=[]
      @default_format = nil
      @worksheet = worksheet
      @idx = idx
      super cells
      @formats = []
      @height = 12.1
    end
updater(*keys) click to toggle source

(Not documented)

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

Public Instance Methods

default_format=(format) click to toggle source

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

# File lib/spreadsheet/row.rb, line 71
    def default_format= format
      @worksheet.add_format format if @worksheet
      @default_format = format
    end
first_unused() click to toggle source

Alias for formatted_size

first_used() click to toggle source

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

# File lib/spreadsheet/row.rb, line 78
    def first_used
      [ index_of_first(self), index_of_first(@formats) ].compact.min
    end
format(idx) click to toggle source

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.

# File lib/spreadsheet/row.rb, line 84
    def format idx
      @formats[idx] || @default_format \
        || @worksheet.column(idx).default_format if @worksheet
    end
formatted() click to toggle source

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.

# File lib/spreadsheet/row.rb, line 92
    def formatted
      copy = dup
      @formats.rcompact!
      if copy.length < @formats.size
        copy.concat Array.new(@formats.size - copy.length)
      end
      copy
    end
formatted_size() click to toggle source

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

# File lib/spreadsheet/row.rb, line 102
    def formatted_size
      @formats.rcompact!
      sz = size
      fs = @formats.size
      fs > sz ? fs : sz
    end
Also aliased as: first_unused
inspect() click to toggle source

(Not documented)

# File lib/spreadsheet/row.rb, line 112
    def inspect
      variables = instance_variables.collect do |name|
        "%s=%s" % [name, instance_variable_get(name)]
      end.join(' ')
      sprintf "#<%s:0x%014x %s %s>", self.class, object_id, variables, super
    end
set_format(idx, fmt) click to toggle source

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

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.