axlsx_styler 0.1.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +23 -0
- data/README.md +50 -26
- data/Rakefile +18 -4
- data/lib/axlsx_styler.rb +4 -23
- data/lib/axlsx_styler/axlsx_cell.rb +32 -30
- data/lib/axlsx_styler/axlsx_package.rb +17 -0
- data/lib/axlsx_styler/axlsx_styles.rb +36 -0
- data/lib/axlsx_styler/axlsx_workbook.rb +26 -43
- data/lib/axlsx_styler/axlsx_worksheet.rb +34 -17
- data/lib/axlsx_styler/version.rb +1 -1
- data/test/dummy_app/Rakefile +7 -0
- data/test/dummy_app/app/assets/config/manifest.js +3 -0
- data/test/dummy_app/app/assets/javascripts/application.js +0 -0
- data/test/dummy_app/app/assets/stylesheets/application.css +3 -0
- data/test/dummy_app/app/controllers/application_controller.rb +3 -0
- data/test/dummy_app/app/controllers/spreadsheets_controller.rb +7 -0
- data/test/dummy_app/app/models/application_record.rb +3 -0
- data/test/dummy_app/app/views/layouts/application.html.erb +14 -0
- data/{examples/colors_and_borders.rb → test/dummy_app/app/views/spreadsheets/test.xlsx.axlsx} +2 -7
- data/test/dummy_app/config.ru +4 -0
- data/test/dummy_app/config/application.rb +56 -0
- data/test/dummy_app/config/boot.rb +10 -0
- data/test/dummy_app/config/database.yml +25 -0
- data/test/dummy_app/config/environment.rb +5 -0
- data/test/dummy_app/config/environments/development.rb +30 -0
- data/test/dummy_app/config/environments/production.rb +60 -0
- data/test/dummy_app/config/environments/test.rb +41 -0
- data/test/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy_app/config/initializers/inflections.rb +10 -0
- data/test/dummy_app/config/initializers/mime_types.rb +5 -0
- data/test/dummy_app/config/initializers/secret_token.rb +11 -0
- data/test/dummy_app/config/initializers/session_store.rb +8 -0
- data/test/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy_app/config/locales/en.yml +5 -0
- data/test/dummy_app/config/routes.rb +3 -0
- data/test/dummy_app/config/secrets.yml +22 -0
- data/test/dummy_app/db/schema.rb +15 -0
- data/test/dummy_app/db/test.sqlite3 +0 -0
- data/test/dummy_app/log/test.log +1004 -0
- data/test/helper_methods.rb +12 -0
- data/test/integration/application_test.rb +18 -0
- data/test/test_helper.rb +31 -4
- data/test/unit/borders_test.rb +127 -0
- data/test/unit/examples_test.rb +20 -0
- data/test/unit/merge_styles_test.rb +56 -0
- data/test/unit/regresssions_test.rb +44 -0
- data/test/unit/serialize_test.rb +34 -0
- data/test/unit/to_stream_test.rb +34 -0
- metadata +152 -47
- data/.gitignore +0 -24
- data/Gemfile +0 -4
- data/axlsx_styler.gemspec +0 -36
- data/examples/vanilla_axlsx.md +0 -70
- data/spreadsheet.png +0 -0
- data/test/cell_test.rb +0 -14
- data/test/integration_test.rb +0 -234
- data/test/workbook_test.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6da36a303dacdfc72388437e8e993607859fa1fc35bcf7c7937e73c0f85d71ba
|
4
|
+
data.tar.gz: a234265db298461f325be13515e56eeab110c08671ee976c30c59f57ed8b470e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab70334fc493760f7b4f561067d0d3a447bae22b236cbe78926a6ba87aa4fe4e88ae5b0532582eddc14b2d570100cfa04b0b7e3412ca2626badedb659214063
|
7
|
+
data.tar.gz: d5ea3bf3bdb7c611b1ab988963f8916f575d14309443bf9fedb85872e347fc594cf64adebbea615acf4ffdbf4fac1bfabcc615570cc6ef35713029cb235e1f76
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
- **1.1.0 - August 26, 2020**
|
4
|
+
- [Issue #29](https://github.com/axlsx-styler-gem/axlsx_styler/issues/29) - Fix error `Invalid cellXfs id` when applying `dxf` styles
|
5
|
+
- [PR #28](https://github.com/axlsx-styler-gem/axlsx_styler/pull/28) - Allow passing arrays of cell ranges to the `add_style` and `add_border` methods
|
6
|
+
- **1.0.0 - January 5, 2020**
|
7
|
+
- Switch to the `caxlsx` gem (Community Axlsx) from the legacy unmaintained `axlsx` gem. Axlsx has had a long history of being poorly maintained so this community gem improves the situation.
|
8
|
+
- Require Ruby 2.3+
|
9
|
+
- Improve Package and Styles monkey patches using `prepend`
|
10
|
+
- Removed unnecessary module `AxlsxStyler::Axlsx`
|
11
|
+
- Major test suite improvements
|
12
|
+
- Add Rails dummy app to test suite and test with `axlsx_rails`
|
13
|
+
- **0.2.0**
|
14
|
+
- Add support for `axlsx` v3 (at this time for v3.0.0.pre).
|
15
|
+
- Update test suite to run against both v2 and v3 of `axlsx`
|
16
|
+
- **0.1.7**
|
17
|
+
- Allow mixing vanilla `axlsx` styles and those from `add_style` and `add_border`. See [this example](./examples/mixing_styles.rb)
|
18
|
+
- **0.1.5**
|
19
|
+
- Hide `Workbook#apply_styles` method to make it easier to use.
|
20
|
+
- **0.1.3**
|
21
|
+
- Make border styles customizable.
|
22
|
+
- **0.1.2**
|
23
|
+
- Allow applying multiple style hashes.
|
data/README.md
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
# axlsx_styler
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
row is created.
|
3
|
+
<a href="https://badge.fury.io/rb/axlsx_styler" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/axlsx_styler.svg" alt="Gem Version"></a>
|
4
|
+
<a href='https://travis-ci.org/axlsx-styler-gem/axlsx_styler' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://api.travis-ci.org/axlsx-styler-gem/axlsx_styler.svg?branch=master' border='0' alt='Build Status' /></a>
|
5
|
+
<a href='https://rubygems.org/gems/axlsx_styler' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/axlsx_styler?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
|
7
6
|
|
8
|
-
`axlsx_styler` allows to
|
9
|
-
a spreadsheet with data and apply styles later. Paired with
|
10
|
-
[axlsx_rails](https://github.com/straydogstudio/axlsx_rails) this gem
|
11
|
-
allows to build clean and maintainable Excel views in a Rails app. It can also
|
12
|
-
be used outside of any specific Ruby framework as shown in example below.
|
7
|
+
`axlsx_styler` is a gem that allows you to build clean and maintainable styles for your `axlsx` spreadsheets. Build your spreadsheeet with data and then apply styles later.
|
13
8
|
|
14
|
-
|
9
|
+
While [`axlsx`](https://github.com/randym/axlsx) is an excellent tool to build Excel spreadsheets in Ruby, the sheets styles are only applied immediately as the row is created. This makes it very difficult to style easily and effectively.
|
15
10
|
|
16
|
-
|
11
|
+
To solve this issue, `axlsx_styler` was born to allow the separation of styles from content within your `axlsx` code. It gives you the ability to fill out a spreadsheet with data and apply styles later.
|
12
|
+
|
13
|
+
Works well in any Rails app or outside of any specific Ruby framework.
|
14
|
+
|
15
|
+
# Usage
|
16
|
+
|
17
|
+
This gem provides a DSL that allows you to apply styles or borders to ranges of cells.
|
18
|
+
|
19
|
+
## Styles
|
17
20
|
|
18
21
|
```ruby
|
19
22
|
sheet.add_style 'A1:D10', b: true, sz: 14
|
20
23
|
```
|
21
24
|
|
22
|
-
The styles can be overlayed, so that later on you can add another style
|
23
|
-
to cells that already have styles, e.g.
|
25
|
+
The styles can be overlayed, so that later on you can add another style to cells that already have styles.
|
24
26
|
|
25
27
|
```ruby
|
26
28
|
sheet.add_style 'A1:D1', bg_color: 'FF0000'
|
27
29
|
```
|
28
30
|
|
29
|
-
Applying multiple styles as a sequence of Ruby hashes is also possible
|
31
|
+
Applying multiple styles as a sequence of Ruby hashes is also possible.
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
bold = { b: true }
|
@@ -34,25 +36,41 @@ centered = { alignment: { horizontal: :center } }
|
|
34
36
|
sheet.add_style 'A2:D2', bold, centered
|
35
37
|
```
|
36
38
|
|
37
|
-
|
39
|
+
Applying a style to multiple ranges at once.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
sheet.add_style ['A2:G2', "A8:G8", "A12:G12"], b: true, sz: 14
|
43
|
+
```
|
44
|
+
|
45
|
+
## Borders
|
46
|
+
|
47
|
+
The border style is to draw a thin black border on all four edges of the selected cell range.
|
38
48
|
|
39
49
|
```ruby
|
40
50
|
sheet.add_border 'B2:D5'
|
51
|
+
```
|
52
|
+
|
53
|
+
You can easily customize the border styles.
|
54
|
+
|
55
|
+
```ruby
|
41
56
|
sheet.add_border 'B2:D5', [:bottom, :right]
|
42
57
|
sheet.add_border 'B2:D5', { edges: [:bottom, :right], style: :thick, color: 'FF0000' }
|
43
58
|
```
|
44
59
|
|
45
|
-
|
60
|
+
Applying border to multiple ranges at once.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
sheet.add_border ['A2:G2', "A8:G8", "A12:G12"]
|
64
|
+
```
|
46
65
|
|
47
66
|
|
48
|
-
|
67
|
+
## Example
|
49
68
|
|
50
69
|
Suppose we want create the following spreadsheet:
|
51
70
|
|
52
71
|
![alt text](./spreadsheet.png "Sample Spreadsheet")
|
53
72
|
|
54
|
-
You can apply styles after all data is entered, similar to how you'd create
|
55
|
-
an Excel document by hand:
|
73
|
+
You can apply styles after all data is entered, similar to how you'd create an Excel document by hand.
|
56
74
|
|
57
75
|
```ruby
|
58
76
|
require 'axlsx_styler'
|
@@ -79,13 +97,19 @@ end
|
|
79
97
|
axlsx.serialize 'grocery.xlsx'
|
80
98
|
```
|
81
99
|
|
82
|
-
|
100
|
+
If you try creating this same spreadsheet using only `axlsx`, you will find this is much more difficult. See this [See this example](./examples/vanilla_axlsx.md)
|
101
|
+
|
102
|
+
For more examples, please see the [examples folder](./examples/)
|
103
|
+
|
104
|
+
# Contributing
|
105
|
+
|
106
|
+
We use the `appraisal` gem for testing multiple versions of `axlsx`. Please use the following steps to test using `appraisal`.
|
107
|
+
|
108
|
+
1. `bundle exec appraisal install`
|
109
|
+
2. `bundle exec appraisal rake test`
|
83
110
|
|
111
|
+
# Credits
|
84
112
|
|
85
|
-
|
113
|
+
Created by Anton Sakovich - @sakovias
|
86
114
|
|
87
|
-
|
88
|
-
--------|-------
|
89
|
-
0.1.5 | Hide `Workbook#apply_styles` method to make it easier to use.
|
90
|
-
0.1.3 | Make border styles customazible.
|
91
|
-
0.1.2 | Allow applying multiple style hashes.
|
115
|
+
Maintained by Weston Ganger - @westonganger - Uses `axlsx_styler` within the gem, [`spreadsheet_architect`](https://github.com/westonganger/spreadsheet_architect)
|
data/Rakefile
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require 'rake/testtask'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
task :test do
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'lib'
|
8
|
+
t.libs << 'test'
|
9
|
+
t.pattern = 'test/**/*_test.rb'
|
10
|
+
t.verbose = false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :test
|
15
|
+
|
16
|
+
task :console do
|
17
|
+
require 'axlsx_styler'
|
18
|
+
|
19
|
+
require 'irb'
|
20
|
+
binding.irb
|
7
21
|
end
|
data/lib/axlsx_styler.rb
CHANGED
@@ -1,31 +1,12 @@
|
|
1
1
|
require 'axlsx'
|
2
|
-
|
3
2
|
require 'axlsx_styler/version'
|
3
|
+
|
4
|
+
require 'axlsx_styler/axlsx_package'
|
5
|
+
require 'axlsx_styler/axlsx_styles'
|
4
6
|
require 'axlsx_styler/axlsx_workbook'
|
5
7
|
require 'axlsx_styler/axlsx_worksheet'
|
6
8
|
require 'axlsx_styler/axlsx_cell'
|
7
9
|
|
8
|
-
|
9
|
-
Axlsx::Worksheet.send :include, AxlsxStyler::Axlsx::Worksheet
|
10
|
-
Axlsx::Cell.send :include, AxlsxStyler::Axlsx::Cell
|
11
|
-
|
12
|
-
module Axlsx
|
13
|
-
class Package
|
14
|
-
|
15
|
-
# Patches the original Axlsx::Package#serialize method so that styles are
|
16
|
-
# applied when the workbook is saved
|
17
|
-
original_serialize = instance_method(:serialize)
|
18
|
-
define_method :serialize do |*args|
|
19
|
-
workbook.apply_styles if !workbook.styles_applied
|
20
|
-
original_serialize.bind(self).(*args)
|
21
|
-
end
|
10
|
+
module AxlsxStyler
|
22
11
|
|
23
|
-
# Patches the original Axlsx::Package#to_stream method so that styles are
|
24
|
-
# applied when the workbook is converted to StringIO
|
25
|
-
original_to_stream = instance_method(:to_stream)
|
26
|
-
define_method :to_stream do |*args|
|
27
|
-
workbook.apply_styles if !workbook.styles_applied
|
28
|
-
original_to_stream.bind(self).(*args)
|
29
|
-
end
|
30
|
-
end
|
31
12
|
end
|
@@ -1,42 +1,44 @@
|
|
1
1
|
require 'active_support/core_ext/hash/deep_merge'
|
2
2
|
|
3
3
|
module AxlsxStyler
|
4
|
-
module
|
5
|
-
|
6
|
-
attr_accessor :raw_style
|
7
|
-
|
8
|
-
def add_style(style)
|
9
|
-
self.raw_style ||= {}
|
10
|
-
add_to_raw_style(style)
|
11
|
-
workbook.add_styled_cell self
|
12
|
-
end
|
4
|
+
module Cell
|
5
|
+
attr_accessor :raw_style
|
13
6
|
|
14
|
-
|
7
|
+
def add_style(style)
|
8
|
+
self.raw_style ||= {}
|
9
|
+
add_to_raw_style(style)
|
10
|
+
workbook.add_styled_cell self
|
11
|
+
end
|
15
12
|
|
16
|
-
|
17
|
-
row.worksheet.workbook
|
18
|
-
end
|
13
|
+
private
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
new_style = raw_style.deep_merge style
|
24
|
-
if with_border?(raw_style) && with_border?(style)
|
25
|
-
border_at = (raw_style[:border][:edges] || all_edges) + (style[:border][:edges] || all_edges)
|
26
|
-
new_style[:border][:edges] = border_at.uniq.sort
|
27
|
-
elsif with_border?(style)
|
28
|
-
new_style[:border] = style[:border]
|
29
|
-
end
|
30
|
-
self.raw_style = new_style
|
31
|
-
end
|
15
|
+
def workbook
|
16
|
+
row.worksheet.workbook
|
17
|
+
end
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
def add_to_raw_style(style)
|
20
|
+
# using deep_merge from active_support:
|
21
|
+
# with regular Hash#merge adding borders fails miserably
|
22
|
+
new_style = raw_style.deep_merge style
|
36
23
|
|
37
|
-
|
38
|
-
[:
|
24
|
+
if with_border?(raw_style) && with_border?(style)
|
25
|
+
border_at = (raw_style[:border][:edges] || all_edges) + (style[:border][:edges] || all_edges)
|
26
|
+
new_style[:border][:edges] = border_at.uniq.sort
|
27
|
+
elsif with_border?(style)
|
28
|
+
new_style[:border] = style[:border]
|
39
29
|
end
|
30
|
+
|
31
|
+
self.raw_style = new_style
|
32
|
+
end
|
33
|
+
|
34
|
+
def with_border?(style)
|
35
|
+
!style[:border].nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_edges
|
39
|
+
[:top, :right, :bottom, :left]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
Axlsx::Cell.send(:include, AxlsxStyler::Cell)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AxlsxStyler
|
2
|
+
module Package
|
3
|
+
|
4
|
+
def serialize(*args)
|
5
|
+
workbook.apply_styles if !workbook.styles_applied
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_stream(*args)
|
10
|
+
workbook.apply_styles if !workbook.styles_applied
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Axlsx::Package.send(:prepend, AxlsxStyler::Package)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module AxlsxStyler
|
2
|
+
module Styles
|
3
|
+
|
4
|
+
# An index for cell styles where keys are styles codes as per Axlsx::Style and values are Cell#raw_style
|
5
|
+
# The reason for the backward key/value ordering is that style lookup must be most efficient, while `add_style` can be less efficient
|
6
|
+
def style_index
|
7
|
+
@style_index ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Ensure plain axlsx styles are added to the axlsx_styler style_index cache
|
11
|
+
def add_style(options={})
|
12
|
+
if options[:type] == :dxf
|
13
|
+
style_id = super
|
14
|
+
else
|
15
|
+
raw_style = {type: :xf, name: 'Arial', sz: 11, family: 1}.merge(options)
|
16
|
+
|
17
|
+
if raw_style[:format_code]
|
18
|
+
raw_style.delete(:num_fmt)
|
19
|
+
end
|
20
|
+
|
21
|
+
style_id = style_index.key(raw_style)
|
22
|
+
|
23
|
+
if !style_id
|
24
|
+
style_id = super
|
25
|
+
|
26
|
+
style_index[style_id] = raw_style
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
return style_id
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Axlsx::Styles.send(:prepend, AxlsxStyler::Styles)
|
@@ -1,56 +1,39 @@
|
|
1
1
|
require 'set'
|
2
|
+
require 'active_support/core_ext/hash/deep_merge'
|
2
3
|
|
3
4
|
module AxlsxStyler
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :styled_cells
|
8
|
-
|
9
|
-
# Checks if styles are idexed to make it work for pre 0.1.5 version
|
10
|
-
# users that still explicitly call @workbook.apply_styles
|
11
|
-
attr_accessor :styles_applied
|
12
|
-
|
13
|
-
# An index for cell styles
|
14
|
-
# {
|
15
|
-
# 1 => < style_hash >,
|
16
|
-
# 2 => < style_hash >,
|
17
|
-
# ...
|
18
|
-
# K => < style_hash >
|
19
|
-
# }
|
20
|
-
# where keys are Cell#raw_style and values are styles
|
21
|
-
# codes as per Axlsx::Style
|
22
|
-
attr_accessor :style_index
|
23
|
-
|
24
|
-
def add_styled_cell(cell)
|
25
|
-
self.styled_cells ||= Set.new
|
26
|
-
self.styled_cells << cell
|
27
|
-
end
|
5
|
+
module Workbook
|
6
|
+
# An array that holds all cells with styles
|
7
|
+
attr_accessor :styled_cells
|
28
8
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
9
|
+
# Checks if styles are indexed to make it work for pre 0.1.5 version
|
10
|
+
# users that still explicitly call @workbook.apply_styles
|
11
|
+
attr_accessor :styles_applied
|
12
|
+
|
13
|
+
def add_styled_cell(cell)
|
14
|
+
self.styled_cells ||= Set.new
|
15
|
+
self.styled_cells << cell
|
16
|
+
end
|
36
17
|
|
37
|
-
|
18
|
+
def apply_styles
|
19
|
+
return unless styled_cells
|
38
20
|
|
39
|
-
|
40
|
-
|
41
|
-
self.style_index ||= {}
|
21
|
+
styled_cells.each do |cell|
|
22
|
+
current_style = styles.style_index[cell.style]
|
42
23
|
|
43
|
-
|
44
|
-
|
45
|
-
cell.style = index_item.first
|
24
|
+
if current_style
|
25
|
+
new_style = current_style.deep_merge(cell.raw_style)
|
46
26
|
else
|
47
|
-
|
48
|
-
new_style = styles.add_style(cell.raw_style)
|
49
|
-
cell.style = new_style
|
50
|
-
# cell.raw_style.delete(:num_fmt)
|
51
|
-
style_index[new_style] = old_style
|
27
|
+
new_style = cell.raw_style
|
52
28
|
end
|
29
|
+
|
30
|
+
cell.style = styles.add_style(new_style)
|
53
31
|
end
|
32
|
+
|
33
|
+
self.styles_applied = true
|
54
34
|
end
|
35
|
+
|
55
36
|
end
|
56
37
|
end
|
38
|
+
|
39
|
+
Axlsx::Workbook.send(:include, AxlsxStyler::Workbook)
|
@@ -1,35 +1,52 @@
|
|
1
1
|
require_relative './border_creator'
|
2
2
|
|
3
3
|
module AxlsxStyler
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
module Worksheet
|
5
|
+
# Example to add a single style:
|
6
|
+
# add_style 'A1:B5', b: false
|
7
|
+
# add_style ['B1', 'B3'], b: false
|
8
|
+
# add_style ['D3:D4', 'F2:F6'], b: false
|
9
|
+
#
|
10
|
+
# Example to add multiple styles:
|
11
|
+
# bold = { b: true }
|
12
|
+
# large_text = { sz: 30 }
|
13
|
+
# add_style 'B2:F8', bold, large_text
|
14
|
+
def add_style(cell_refs, *styles)
|
15
|
+
if !cell_refs.is_a?(Array)
|
16
|
+
cell_refs = [cell_refs]
|
17
|
+
end
|
18
|
+
|
19
|
+
cell_refs.each do |cell_ref|
|
14
20
|
item = self[cell_ref]
|
21
|
+
|
15
22
|
cells = item.is_a?(Array) ? item : [item]
|
23
|
+
|
16
24
|
cells.each do |cell|
|
17
25
|
styles.each do |style|
|
18
26
|
cell.add_style(style)
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Examples:
|
33
|
+
# add_border 'B2:F8', [:left, :top], :medium, '00330f'
|
34
|
+
# add_border 'B2:F8', [:left, :top], :medium
|
35
|
+
# add_border 'C2:G10', [:top]
|
36
|
+
# add_border 'C2:G10'
|
37
|
+
# add_border 'B2:D5', { style: :thick, color: '00330f', edges: [:left, :right] }
|
38
|
+
# add_border ['D3:D4', 'F2:F6'], [:left]
|
39
|
+
def add_border(cell_refs, args = :all)
|
40
|
+
if !cell_refs.is_a?(Array)
|
41
|
+
cell_refs = [cell_refs]
|
42
|
+
end
|
22
43
|
|
23
|
-
|
24
|
-
# add_border 'B2:F8', [:left, :top], :medium, '00330f'
|
25
|
-
# add_border 'B2:F8', [:left, :top], :medium
|
26
|
-
# add_border 'C2:G10', [:top]
|
27
|
-
# add_border 'C2:G10'
|
28
|
-
# add_border 'B2:D5', { style: :thick, color: '00330f', edges: [:left, :right] }
|
29
|
-
def add_border(cell_ref, args = :all)
|
44
|
+
cell_refs.each do |cell_ref|
|
30
45
|
cells = self[cell_ref]
|
31
46
|
BorderCreator.new(self, cells, args).draw
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
35
50
|
end
|
51
|
+
|
52
|
+
Axlsx::Worksheet.send(:include, AxlsxStyler::Worksheet)
|