Class: RubyReport::Generator::Xlsx::Worksheet

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

Constant Summary collapse

SIZES =
{header_height: 40, item_height: 20}.freeze
ALIGNMENT =
{vertical: :center, horizontal: :left, wrap_text: true}.freeze
COLORS =
{tb: "0a9700", white: "ff"}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(workbook, name) ⇒ Worksheet

Returns a new instance of Worksheet.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_report/generator/xlsx.rb', line 17

def initialize(workbook, name)
  @workbook = workbook
  @worksheet = @workbook.add_worksheet(name: name)
  @styles = ::OpenStruct.new(
    item: @workbook.styles.add_style(alignment: ALIGNMENT),
    header: @workbook.styles.add_style(
      bg_color: COLORS.fetch(:tb),
      fg_color: COLORS.fetch(:white),
      alignment: ALIGNMENT
    )
  )
end

Instance Method Details

#add_header(data) ⇒ Object



30
31
32
33
34
# File 'lib/ruby_report/generator/xlsx.rb', line 30

def add_header(data)
  worksheet.add_row(
    data, style: styles.header, height: SIZES.fetch(:header_height)
  )
end

#add_row(data) ⇒ Object



36
37
38
39
40
# File 'lib/ruby_report/generator/xlsx.rb', line 36

def add_row(data)
  worksheet.add_row(
    data, style: styles.item, height: SIZES.fetch(:item_height)
  )
end