Class: XLSX::Worksheet

Inherits:
Object
  • Object
show all
Defined in:
lib/xlsx/worksheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workbook, params = {}) ⇒ Worksheet

Returns a new instance of Worksheet.



29
30
31
32
33
34
35
# File 'lib/xlsx/worksheet.rb', line 29

def initialize(workbook, params={})
  @workbook = workbook
  @title = params[:name] || ''
  @rows = {}
  @min_row = 0
  @max_row = 0
end

Instance Attribute Details

#max_rowObject (readonly)

Returns the value of attribute max_row.



27
28
29
# File 'lib/xlsx/worksheet.rb', line 27

def max_row
  @max_row
end

#min_rowObject (readonly)

Returns the value of attribute min_row.



27
28
29
# File 'lib/xlsx/worksheet.rb', line 27

def min_row
  @min_row
end

#titleObject

Returns the value of attribute title.



26
27
28
# File 'lib/xlsx/worksheet.rb', line 26

def title
  @title
end

Instance Method Details

#get_row(row_number) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/xlsx/worksheet.rb', line 61

def get_row(row_number)
  raise "Row number must be a non-negative integer" unless row_number.is_a?(Integer) && row_number >= 0
  r = row(row_number)
  return r unless r.nil?

  @min_row = row_number if row_number < @min_row
  @max_row = row_number if row_number > @max_row
  @rows[row_number] = Row.new(self, row_number)
end

#max_colObject



41
42
43
# File 'lib/xlsx/worksheet.rb', line 41

def max_col
  rows.map { |r| r.max_col }.max
end

#min_colObject



37
38
39
# File 'lib/xlsx/worksheet.rb', line 37

def min_col
  rows.map { |r| r.min_col }.min
end

#row(row_number) ⇒ Object



45
46
47
# File 'lib/xlsx/worksheet.rb', line 45

def row(row_number)
  @rows[row_number]
end

#rowsObject



49
50
51
# File 'lib/xlsx/worksheet.rb', line 49

def rows
  @rows.keys.sort.map { |n| @rows[n] }
end

#update_row(row_number, *values) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/xlsx/worksheet.rb', line 53

def update_row(row_number, *values)
  row = get_row(row_number)
  0.upto(values.length - 1) do |col|
    row[col] = values[col]
  end
  row
end