Module: AxlsxEnhanced::Helpers::Injections::Cell

Included in:
Axlsx::Cell
Defined in:
lib/axlsx_enhanced/helpers/injections/cell.rb

Instance Method Summary collapse

Instance Method Details

#smart_style=(value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/axlsx_enhanced/helpers/injections/cell.rb', line 5

def smart_style=(value)
  return if value.nil?
      
  # Get sheet and workbook
  sheet = self.row.worksheet
  book  = sheet.workbook
      
  if value.is_a? Array
    # Iterate style if value is an Array
    new_style = {}
      
    value.each do |v|
      # Find the specified style and merge it into the new style
      s = sheet.smart_styles.find(v.to_sym)
      new_style.deep_merge! s.properties
    end
  else
    # Find the specified style
    new_style = sheet.smart_styles.find(value).properties
  end
      
  # Add the style to the workbook
  style_id = book.styles.add_style new_style
      
  # Assign the style into the cell
  self.style = style_id
      
  # Return the style id
  return style_id
end