Class: NeatSpreadsheet::Helpers::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/neat-spreadsheet/helpers/sheet.rb

Instance Method Summary collapse

Constructor Details

#initialize(workbook, options = {}) {|_self| ... } ⇒ Sheet

Returns a new instance of Sheet.

Yields:

  • (_self)

Yield Parameters:



3
4
5
6
7
8
9
10
11
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 3

def initialize(workbook, options={}, &block)
  options.reverse_merge! title: nil, columns_width: [10, 10, 10, 10, 10]

  init_sheet workbook, options[:title]
  init_columns options[:columns_width]
  init_styles

  yield self
end

Instance Method Details

#cell(value, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 13

def cell(value, options={})
  if options[:colspan]
    options[:horizontal_align] = :merge

    (@column_position..(@column_position+options[:colspan]-1)).each do |i|
      current_row.set_format(i, current_format(options))
    end
  else
    current_row.set_format(@column_position, current_format(options))
  end

  set_current_column value

  @column_position += 1
end

#row(options = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 29

def row(options={}, &block)
  options.reverse_merge! height: nil, start_at_column: 0, style: :normal

  @column_position = 0

  set_current_style options[:style]
  set_current_height options[:height]

  (0..options[:start_at_column]-1).each { |i| cell(' ') } if options[:start_at_column] > 0

  yield self

  @row_position += 1
end

#skip_cellObject



44
45
46
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 44

def skip_cell
  skip_cells 1
end

#skip_cells(nb) ⇒ Object



48
49
50
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 48

def skip_cells(nb)
  (@column_position..(@column_position+nb-1)).each { |i| cell(' ') }
end

#skip_rowObject



52
53
54
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 52

def skip_row
  @row_position += 1
end

#spacer(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/neat-spreadsheet/helpers/sheet.rb', line 56

def spacer(options={})
  options.reverse_merge! height: 20

  @column_position = 0

  current_row.height = options[:height]
  (0..@total_columns-1).each { |i| current_row.set_format(i, Spreadsheet::Format.new(horizontal_align: :merge)) }
  set_current_column ' '

  @row_position += 1
end