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/workbook.rb | |
| parent | bcc88ca556b3b8527ba0ad56424f93ef170b9c31 (diff) | |
| download | caxlsx-fd8366970d9cb3f5fb431ba6c40a2a2ac2737615.tar.gz caxlsx-fd8366970d9cb3f5fb431ba6c40a2a2ac2737615.zip | |
Merge axlsx_styler gem into caxlsx
Diffstat (limited to 'lib/axlsx/workbook/workbook.rb')
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index edf719d1..f9e857fc 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -187,6 +187,34 @@ require 'axlsx/workbook/worksheet/selection.rb' @styles end + # An array that holds all cells with styles + attr_accessor :styled_cells + + # Checks if styles are indexed to make it work for pre 0.1.5 version + # users that still explicitly call @workbook.apply_styles + attr_accessor :styles_applied + + # A helper to apply styles that were added using `worksheet.add_style` + # @return [Boolean] + require 'active_support/core_ext/hash/deep_merge' ### TODO: keep or replace with local solution + def apply_styles + return false if !styled_cells + + styled_cells.each do |cell| + current_style = styles.style_index[cell.style] + + if current_style + new_style = current_style.deep_merge(cell.raw_style) + else + new_style = cell.raw_style + end + + cell.style = styles.add_style(new_style) + end + + self.styles_applied = true + end + # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used. @@date1904 = false |
