diff options
| author | Weston Ganger <[email protected]> | 2022-09-29 20:45:39 -0700 |
|---|---|---|
| committer | Weston Ganger <[email protected]> | 2022-09-29 20:45:39 -0700 |
| commit | fd8366970d9cb3f5fb431ba6c40a2a2ac2737615 (patch) | |
| tree | 4e7fc2f0520d3a5cd4485d101b60a8280e624bb7 /lib/axlsx/workbook/worksheet/cell.rb | |
| parent | bcc88ca556b3b8527ba0ad56424f93ef170b9c31 (diff) | |
| download | caxlsx-fd8366970d9cb3f5fb431ba6c40a2a2ac2737615.tar.gz caxlsx-fd8366970d9cb3f5fb431ba6c40a2a2ac2737615.zip | |
Merge axlsx_styler gem into caxlsx
Diffstat (limited to 'lib/axlsx/workbook/worksheet/cell.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 3277b8c5..626cf60f 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -82,6 +82,37 @@ module Axlsx defined?(@style) ? @style : 0 end + attr_accessor :raw_style + + require 'active_support/core_ext/hash/deep_merge' ### TODO: can/should we remove this dependency + # The index of the cellXfs item to be applied to this cell. + # @param [Hash] styles + # @see Axlsx::Styles + require 'set' ### TODO: move to appropriate place + def add_style(style) + self.raw_style ||= {} + + # using deep_merge from active_support: + # with regular Hash#merge adding borders fails miserably + new_style = raw_style.deep_merge(style) + + all_edges = [:top, :right, :bottom, :left] + + if !raw_style[:border].nil? && !style[:border].nil? + border_at = (raw_style[:border][:edges] || all_edges) + (style[:border][:edges] || all_edges) + new_style[:border][:edges] = border_at.uniq.sort + elsif !style[:border].nil? + new_style[:border] = style[:border] + end + + self.raw_style = new_style + + wb = row.worksheet.workbook + + wb.styled_cells ||= Set.new + wb.styled_cells << self + end + # The row this cell belongs to. # @return [Row] attr_reader :row |
