axlsx_styler 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -92
- data/examples/vanilla_axlsx.md +70 -0
- data/lib/axlsx_styler.rb +21 -0
- data/lib/axlsx_styler/axlsx_cell.rb +6 -2
- data/lib/axlsx_styler/axlsx_workbook.rb +7 -1
- data/lib/axlsx_styler/version.rb +1 -1
- data/test/integration_test.rb +109 -21
- data/test/workbook_test.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd31d073d9ff50b0f751553c2623c372ec9a4d1d
|
4
|
+
data.tar.gz: d8c93fe14f0215c0aa0619ebfcb37cc6479f9781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e99d3aae264ab742166af6b76fb34d9d2b19d61e2a57cf56d9d35d3102f7a45365da068cc18f16f945082907ec73beece46e9a79808acfb3b290498b07b6efde
|
7
|
+
data.tar.gz: 392fcc8712ce0fc970894f19671324ff327bc8a712a2753be62230ff80f08df12e6501073c7f0521c57b596b144e06b7cfff45ea6e1737f35a99de20c24d84ff
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ row is created.
|
|
9
9
|
a spreadsheet with data and apply styles later. Paired with
|
10
10
|
[axlsx_rails](https://github.com/straydogstudio/axlsx_rails) this gem
|
11
11
|
allows to build clean and maintainable Excel views in a Rails app. It can also
|
12
|
-
be used outside of any specific
|
12
|
+
be used outside of any specific Ruby framework as shown in example below.
|
13
13
|
|
14
14
|
## Usage
|
15
15
|
|
@@ -44,19 +44,13 @@ sheet.add_border 'B2:D5', { edges: [:bottom, :right], style: :thick, color: 'FF0
|
|
44
44
|
|
45
45
|
Border parameters are optional. The default is to draw a thin black border on all four edges of the selected cell range.
|
46
46
|
|
47
|
-
The styles are applied with a simple call:
|
48
47
|
|
49
|
-
|
50
|
-
workbook.apply_styles
|
51
|
-
```
|
48
|
+
### Example
|
52
49
|
|
53
|
-
|
54
|
-
`axlsx_styler`. Suppose we wand to create the following spreadsheet:
|
50
|
+
Suppose we want create the following spreadsheet:
|
55
51
|
|
56
52
|

|
57
53
|
|
58
|
-
### `axlsx` paired with `axlsx_styler`
|
59
|
-
|
60
54
|
You can apply styles after all data is entered, similar to how you'd create
|
61
55
|
an Excel document by hand:
|
62
56
|
|
@@ -82,92 +76,16 @@ workbook.add_worksheet do |sheet|
|
|
82
76
|
sheet.add_border 'B2:D5'
|
83
77
|
sheet.add_border 'B3:D3', [:top]
|
84
78
|
end
|
85
|
-
workbook.apply_styles
|
86
79
|
axlsx.serialize 'grocery.xlsx'
|
87
80
|
```
|
88
81
|
|
89
|
-
|
90
|
-
|
91
|
-
Whith plain `axlsx` you need to know which styles you're going to use beforehand.
|
92
|
-
The code for our example is a bit more envolved:
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
require 'axlsx'
|
96
|
-
axlsx = Axlsx::Package.new
|
97
|
-
wb = axlsx.workbook
|
98
|
-
border_color = '000000'
|
99
|
-
wb.add_worksheet do |sheet|
|
100
|
-
# top row
|
101
|
-
header_hash = { b: true, bg_color: '95AFBA' }
|
102
|
-
top_left_corner = wb.styles.add_style header_hash.merge({
|
103
|
-
border: { style: :thin, color: border_color, edges: [:top, :left, :bottom] }
|
104
|
-
})
|
105
|
-
top_edge = wb.styles.add_style header_hash.merge({
|
106
|
-
border: { style: :thin, color: border_color, edges: [:top, :bottom] }
|
107
|
-
})
|
108
|
-
top_right_corner = wb.styles.add_style header_hash.merge({
|
109
|
-
border: { style: :thin, color: border_color, edges: [:top, :right, :bottom] }
|
110
|
-
})
|
111
|
-
sheet.add_row
|
112
|
-
sheet.add_row(["", "Product", "Category", "Price"],
|
113
|
-
style: [ nil, top_left_corner, top_edge, top_right_corner ]
|
114
|
-
)
|
115
|
-
|
116
|
-
# middle rows
|
117
|
-
color_hash = { bg_color: 'E2F89C' }
|
118
|
-
left_edge = wb.styles.add_style color_hash.merge(
|
119
|
-
b: true,
|
120
|
-
border: {
|
121
|
-
style: :thin, color: border_color, edges: [:left]
|
122
|
-
}
|
123
|
-
)
|
124
|
-
inner = wb.styles.add_style color_hash
|
125
|
-
right_edge = wb.styles.add_style color_hash.merge(
|
126
|
-
alignment: { horizontal: :left },
|
127
|
-
border: {
|
128
|
-
style: :thin, color: border_color, edges: [:right]
|
129
|
-
}
|
130
|
-
)
|
131
|
-
sheet.add_row(
|
132
|
-
["", "Butter", "Dairy", 4.99],
|
133
|
-
style: [nil, left_edge, inner, right_edge]
|
134
|
-
)
|
135
|
-
sheet.add_row(
|
136
|
-
["", "Bread", "Baked Goods", 3.45],
|
137
|
-
style: [nil, left_edge, inner, right_edge]
|
138
|
-
)
|
139
|
-
|
140
|
-
# last row
|
141
|
-
bottom_left_corner = wb.styles.add_style color_hash.merge({
|
142
|
-
b: true,
|
143
|
-
border: { style: :thin, color: border_color, edges: [:left, :bottom] }
|
144
|
-
})
|
145
|
-
bottom_edge = wb.styles.add_style color_hash.merge({
|
146
|
-
border: { style: :thin, color: border_color, edges: [:bottom] }
|
147
|
-
})
|
148
|
-
bottom_right_corner = wb.styles.add_style color_hash.merge({
|
149
|
-
alignment: { horizontal: :left },
|
150
|
-
border: { style: :thin, color: border_color, edges: [:right, :bottom] }
|
151
|
-
})
|
152
|
-
sheet.add_row(["", "Broccoli", "Produce", 2.99],
|
153
|
-
style: [nil, bottom_left_corner, bottom_edge, bottom_right_corner]
|
154
|
-
)
|
155
|
-
|
156
|
-
sheet.column_widths 5, 20, 20, 20
|
157
|
-
end
|
158
|
-
axlsx.serialize "grocery.xlsx"
|
159
|
-
```
|
160
|
-
|
161
|
-
## Installation
|
162
|
-
|
163
|
-
Add this line to your application's Gemfile:
|
164
|
-
|
165
|
-
gem 'axlsx_styler'
|
166
|
-
|
167
|
-
And then execute:
|
82
|
+
Producing the same spreadsheet with vanilla `axlsx` turns out [a bit trickier](./examples/vanilla_axlsx.md).
|
168
83
|
|
169
|
-
$ bundle
|
170
84
|
|
171
|
-
|
85
|
+
## Change log
|
172
86
|
|
173
|
-
|
87
|
+
Version | Change
|
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.
|
@@ -0,0 +1,70 @@
|
|
1
|
+
This gem is supposed to make styling spreadsheets easier.
|
2
|
+
|
3
|
+
Here's how the [example from the README](../README.md) compares to that implemented with plain `axlsx`.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'axlsx'
|
7
|
+
axlsx = Axlsx::Package.new
|
8
|
+
wb = axlsx.workbook
|
9
|
+
border_color = '000000'
|
10
|
+
wb.add_worksheet do |sheet|
|
11
|
+
# top row
|
12
|
+
header_hash = { b: true, bg_color: '95AFBA' }
|
13
|
+
top_left_corner = wb.styles.add_style header_hash.merge({
|
14
|
+
border: { style: :thin, color: border_color, edges: [:top, :left, :bottom] }
|
15
|
+
})
|
16
|
+
top_edge = wb.styles.add_style header_hash.merge({
|
17
|
+
border: { style: :thin, color: border_color, edges: [:top, :bottom] }
|
18
|
+
})
|
19
|
+
top_right_corner = wb.styles.add_style header_hash.merge({
|
20
|
+
border: { style: :thin, color: border_color, edges: [:top, :right, :bottom] }
|
21
|
+
})
|
22
|
+
sheet.add_row
|
23
|
+
sheet.add_row(["", "Product", "Category", "Price"],
|
24
|
+
style: [ nil, top_left_corner, top_edge, top_right_corner ]
|
25
|
+
)
|
26
|
+
|
27
|
+
# middle rows
|
28
|
+
color_hash = { bg_color: 'E2F89C' }
|
29
|
+
left_edge = wb.styles.add_style color_hash.merge(
|
30
|
+
b: true,
|
31
|
+
border: {
|
32
|
+
style: :thin, color: border_color, edges: [:left]
|
33
|
+
}
|
34
|
+
)
|
35
|
+
inner = wb.styles.add_style color_hash
|
36
|
+
right_edge = wb.styles.add_style color_hash.merge(
|
37
|
+
alignment: { horizontal: :left },
|
38
|
+
border: {
|
39
|
+
style: :thin, color: border_color, edges: [:right]
|
40
|
+
}
|
41
|
+
)
|
42
|
+
sheet.add_row(
|
43
|
+
["", "Butter", "Dairy", 4.99],
|
44
|
+
style: [nil, left_edge, inner, right_edge]
|
45
|
+
)
|
46
|
+
sheet.add_row(
|
47
|
+
["", "Bread", "Baked Goods", 3.45],
|
48
|
+
style: [nil, left_edge, inner, right_edge]
|
49
|
+
)
|
50
|
+
|
51
|
+
# last row
|
52
|
+
bottom_left_corner = wb.styles.add_style color_hash.merge({
|
53
|
+
b: true,
|
54
|
+
border: { style: :thin, color: border_color, edges: [:left, :bottom] }
|
55
|
+
})
|
56
|
+
bottom_edge = wb.styles.add_style color_hash.merge({
|
57
|
+
border: { style: :thin, color: border_color, edges: [:bottom] }
|
58
|
+
})
|
59
|
+
bottom_right_corner = wb.styles.add_style color_hash.merge({
|
60
|
+
alignment: { horizontal: :left },
|
61
|
+
border: { style: :thin, color: border_color, edges: [:right, :bottom] }
|
62
|
+
})
|
63
|
+
sheet.add_row(["", "Broccoli", "Produce", 2.99],
|
64
|
+
style: [nil, bottom_left_corner, bottom_edge, bottom_right_corner]
|
65
|
+
)
|
66
|
+
|
67
|
+
sheet.column_widths 5, 20, 20, 20
|
68
|
+
end
|
69
|
+
axlsx.serialize "grocery.xlsx"
|
70
|
+
```
|
data/lib/axlsx_styler.rb
CHANGED
@@ -8,3 +8,24 @@ require 'axlsx_styler/axlsx_cell'
|
|
8
8
|
Axlsx::Workbook.send :include, AxlsxStyler::Axlsx::Workbook
|
9
9
|
Axlsx::Worksheet.send :include, AxlsxStyler::Axlsx::Worksheet
|
10
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
|
22
|
+
|
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
|
+
end
|
@@ -22,8 +22,8 @@ module AxlsxStyler
|
|
22
22
|
# with regular Hash#merge adding borders fails miserably
|
23
23
|
new_style = raw_style.deep_merge style
|
24
24
|
if with_border?(raw_style) && with_border?(style)
|
25
|
-
border_at = raw_style[:border][:edges] + style[:border][:edges]
|
26
|
-
new_style[:border][:edges] = border_at.uniq
|
25
|
+
border_at = (raw_style[:border][:edges] || all_edges) + (style[:border][:edges] || all_edges)
|
26
|
+
new_style[:border][:edges] = border_at.uniq.sort
|
27
27
|
elsif with_border?(style)
|
28
28
|
new_style[:border] = style[:border]
|
29
29
|
end
|
@@ -33,6 +33,10 @@ module AxlsxStyler
|
|
33
33
|
def with_border?(style)
|
34
34
|
!style[:border].nil?
|
35
35
|
end
|
36
|
+
|
37
|
+
def all_edges
|
38
|
+
[:top, :right, :bottom, :left]
|
39
|
+
end
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -1,9 +1,15 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
module AxlsxStyler
|
2
4
|
module Axlsx
|
3
5
|
module Workbook
|
4
6
|
# An array that holds all cells with styles
|
5
7
|
attr_accessor :styled_cells
|
6
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
|
+
|
7
13
|
# An index for cell styles
|
8
14
|
# {
|
9
15
|
# 1 => < style_hash >,
|
@@ -25,13 +31,13 @@ module AxlsxStyler
|
|
25
31
|
styled_cells.each do |cell|
|
26
32
|
set_style_index(cell)
|
27
33
|
end
|
34
|
+
self.styles_applied = true
|
28
35
|
end
|
29
36
|
|
30
37
|
private
|
31
38
|
|
32
39
|
# Check if style code
|
33
40
|
def set_style_index(cell)
|
34
|
-
# @TODO fix this hack
|
35
41
|
self.style_index ||= {}
|
36
42
|
|
37
43
|
index_item = style_index.select { |_, v| v == cell.raw_style }.first
|
data/lib/axlsx_styler/version.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -6,14 +6,71 @@ class IntegrationTest < MiniTest::Test
|
|
6
6
|
@workbook = @axlsx.workbook
|
7
7
|
end
|
8
8
|
|
9
|
-
# Save
|
10
|
-
def
|
11
|
-
|
12
|
-
|
9
|
+
# Save to a file using Axlsx::Package#serialize
|
10
|
+
def serialize(filename)
|
11
|
+
@axlsx.serialize File.expand_path("../../tmp/#{filename}.xlsx", __FILE__)
|
12
|
+
assert_equal true, @workbook.styles_applied
|
13
|
+
end
|
14
|
+
|
15
|
+
# Save to a file by getting contents from stream
|
16
|
+
def to_stream(filename)
|
17
|
+
File.open(File.expand_path("../../tmp/#{filename}.xlsx", __FILE__), 'w') do |f|
|
18
|
+
f.write @axlsx.to_stream.read
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# New functionality as of 0.1.5 (serialize)
|
23
|
+
def test_works_without_apply_styles_serialize
|
24
|
+
filename = 'without_apply_styles_serialize'
|
25
|
+
assert_equal nil, @workbook.styles_applied
|
26
|
+
@workbook.add_worksheet do |sheet|
|
27
|
+
sheet.add_row ['A1', 'B1']
|
28
|
+
sheet.add_style 'A1:B1', b: true
|
29
|
+
end
|
30
|
+
serialize(filename)
|
31
|
+
assert_equal 1, @workbook.style_index.count
|
32
|
+
end
|
33
|
+
|
34
|
+
# New functionality as of 0.1.5 (to_stream)
|
35
|
+
def test_works_without_apply_styles_to_stream
|
36
|
+
filename = 'without_apply_styles_to_stream'
|
37
|
+
assert_equal nil, @workbook.styles_applied
|
38
|
+
@workbook.add_worksheet do |sheet|
|
39
|
+
sheet.add_row ['A1', 'B1']
|
40
|
+
sheet.add_style 'A1:B1', b: true
|
41
|
+
end
|
42
|
+
to_stream(filename)
|
43
|
+
assert_equal 1, @workbook.style_index.count
|
44
|
+
end
|
45
|
+
|
46
|
+
# Backwards compatibility with pre 0.1.5 (serialize)
|
47
|
+
def test_works_with_apply_styles_serialize
|
48
|
+
filename = 'with_apply_styles_serialize'
|
49
|
+
assert_equal nil, @workbook.styles_applied
|
50
|
+
@workbook.add_worksheet do |sheet|
|
51
|
+
sheet.add_row ['A1', 'B1']
|
52
|
+
sheet.add_style 'A1:B1', b: true
|
53
|
+
end
|
54
|
+
@workbook.apply_styles # important for backwards compatibility
|
55
|
+
assert_equal 1, @workbook.style_index.count
|
56
|
+
serialize(filename)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Backwards compatibility with pre 0.1.5 (to_stream)
|
60
|
+
def test_works_with_apply_styles_to_stream
|
61
|
+
filename = 'with_apply_styles_to_stream'
|
62
|
+
assert_equal nil, @workbook.styles_applied
|
63
|
+
@workbook.add_worksheet do |sheet|
|
64
|
+
sheet.add_row ['A1', 'B1']
|
65
|
+
sheet.add_style 'A1:B1', b: true
|
66
|
+
end
|
67
|
+
@workbook.apply_styles # important for backwards compatibility
|
68
|
+
assert_equal 1, @workbook.style_index.count
|
69
|
+
to_stream(filename)
|
13
70
|
end
|
14
71
|
|
15
72
|
def test_table_with_borders
|
16
|
-
|
73
|
+
filename = 'borders_test'
|
17
74
|
@workbook.add_worksheet do |sheet|
|
18
75
|
sheet.add_row
|
19
76
|
sheet.add_row ['', 'Product', 'Category', 'Price']
|
@@ -23,7 +80,6 @@ class IntegrationTest < MiniTest::Test
|
|
23
80
|
sheet.add_row ['', 'Pizza', 'Frozen Foods', 4.99]
|
24
81
|
sheet.column_widths 5, 20, 20, 20
|
25
82
|
|
26
|
-
# using AxlsxStyler DSL
|
27
83
|
sheet.add_style 'B2:D2', b: true
|
28
84
|
sheet.add_style 'B2:B6', b: true
|
29
85
|
sheet.add_style 'B2:D2', bg_color: '95AFBA'
|
@@ -34,13 +90,13 @@ class IntegrationTest < MiniTest::Test
|
|
34
90
|
sheet.add_border 'B3:D3', edges: [:bottom], style: :medium
|
35
91
|
sheet.add_border 'B3:D3', edges: [:bottom], style: :medium, color: '32f332'
|
36
92
|
end
|
37
|
-
|
93
|
+
serialize(filename)
|
38
94
|
assert_equal 12, @workbook.style_index.count
|
39
95
|
assert_equal 12 + 2, @workbook.style_index.keys.max
|
40
96
|
end
|
41
97
|
|
42
98
|
def test_duplicate_borders
|
43
|
-
|
99
|
+
filename = 'duplicate_borders_test'
|
44
100
|
@workbook.add_worksheet do |sheet|
|
45
101
|
sheet.add_row
|
46
102
|
sheet.add_row ['', 'B2', 'C2', 'D2']
|
@@ -50,13 +106,13 @@ class IntegrationTest < MiniTest::Test
|
|
50
106
|
sheet.add_border 'B2:D4'
|
51
107
|
sheet.add_border 'B2:D4'
|
52
108
|
end
|
53
|
-
|
109
|
+
serialize(filename)
|
54
110
|
assert_equal 8, @workbook.style_index.count
|
55
111
|
assert_equal 8, @workbook.styled_cells.count
|
56
112
|
end
|
57
113
|
|
58
114
|
def test_multiple_style_borders_on_same_sells
|
59
|
-
|
115
|
+
filename = 'multiple_style_borders'
|
60
116
|
@workbook.add_worksheet do |sheet|
|
61
117
|
sheet.add_row
|
62
118
|
sheet.add_row ['', 'B2', 'C2', 'D2']
|
@@ -65,7 +121,7 @@ class IntegrationTest < MiniTest::Test
|
|
65
121
|
sheet.add_border 'B2:D3', :all
|
66
122
|
sheet.add_border 'B2:D2', edges: [:bottom], style: :thick, color: 'ff0000'
|
67
123
|
end
|
68
|
-
|
124
|
+
serialize(filename)
|
69
125
|
assert_equal 6, @workbook.style_index.count
|
70
126
|
assert_equal 6, @workbook.styled_cells.count
|
71
127
|
|
@@ -73,25 +129,25 @@ class IntegrationTest < MiniTest::Test
|
|
73
129
|
border: {
|
74
130
|
style: :thick,
|
75
131
|
color: 'ff0000',
|
76
|
-
edges: [:
|
132
|
+
edges: [:bottom, :left, :top]
|
77
133
|
}
|
78
134
|
}
|
79
135
|
assert_equal b2_cell_style, @workbook.style_index
|
80
|
-
.find { |_, v| v[:border][:edges] == [:
|
136
|
+
.find { |_, v| v[:border][:edges] == [:bottom, :left, :top] }[1]
|
81
137
|
|
82
138
|
d3_cell_style = {
|
83
139
|
border: {
|
84
140
|
style: :thin,
|
85
141
|
color: '000000',
|
86
|
-
edges: [:
|
142
|
+
edges: [:bottom, :right]
|
87
143
|
}
|
88
144
|
}
|
89
145
|
assert_equal d3_cell_style, @workbook.style_index
|
90
|
-
.find { |_, v| v[:border][:edges] == [:
|
146
|
+
.find { |_, v| v[:border][:edges] == [:bottom, :right] }[1]
|
91
147
|
end
|
92
148
|
|
93
149
|
def test_table_with_num_fmt
|
94
|
-
|
150
|
+
filename = 'num_fmt_test'
|
95
151
|
t = Time.now
|
96
152
|
day = 24 * 60 * 60
|
97
153
|
@workbook.add_worksheet do |sheet|
|
@@ -103,14 +159,14 @@ class IntegrationTest < MiniTest::Test
|
|
103
159
|
sheet.add_style 'A1:B1', b: true
|
104
160
|
sheet.add_style 'A2:A4', format_code: 'YYYY-MM-DD hh:mm:ss'
|
105
161
|
end
|
106
|
-
|
162
|
+
serialize(filename)
|
107
163
|
assert_equal 2, @workbook.style_index.count
|
108
164
|
assert_equal 2 + 2, @workbook.style_index.keys.max
|
109
165
|
assert_equal 5, @workbook.styled_cells.count
|
110
166
|
end
|
111
167
|
|
112
168
|
def test_duplicate_styles
|
113
|
-
|
169
|
+
filename = 'duplicate_styles'
|
114
170
|
@workbook.add_worksheet do |sheet|
|
115
171
|
sheet.add_row %w(Index City)
|
116
172
|
sheet.add_row [1, 'Ottawa']
|
@@ -121,13 +177,13 @@ class IntegrationTest < MiniTest::Test
|
|
121
177
|
sheet.add_style 'A1:A3', b: true
|
122
178
|
sheet.add_style 'A1:A3', b: true
|
123
179
|
end
|
124
|
-
|
180
|
+
serialize(filename)
|
125
181
|
assert_equal 4, @workbook.styled_cells.count
|
126
182
|
assert_equal 3, @workbook.style_index.count
|
127
183
|
end
|
128
184
|
|
129
185
|
def test_multiple_named_styles
|
130
|
-
|
186
|
+
filename = 'multiple_named_styles'
|
131
187
|
bold_blue = { b: true, fg_color: '0000FF' }
|
132
188
|
large = { sz: 16 }
|
133
189
|
red = { fg_color: 'FF0000' }
|
@@ -139,8 +195,40 @@ class IntegrationTest < MiniTest::Test
|
|
139
195
|
sheet.add_style 'A1:B1', bold_blue, large
|
140
196
|
sheet.add_style 'A1:A3', red
|
141
197
|
end
|
142
|
-
|
198
|
+
serialize(filename)
|
143
199
|
assert_equal 4, @workbook.styled_cells.count
|
144
200
|
assert_equal 3, @workbook.style_index.count
|
145
201
|
end
|
202
|
+
|
203
|
+
# Overriding borders (part 1)
|
204
|
+
def test_mixed_borders_1
|
205
|
+
@filename = 'mixed_borders_1'
|
206
|
+
@workbook.add_worksheet do |sheet|
|
207
|
+
sheet.add_row
|
208
|
+
sheet.add_row ['', '1', '2', '3']
|
209
|
+
sheet.add_row ['', '4', '5', '6']
|
210
|
+
sheet.add_row ['', '7', '8', '9']
|
211
|
+
sheet.add_style 'B2:D4', border: { style: :thin, color: '000000' }
|
212
|
+
sheet.add_border 'C3:D4', style: :medium
|
213
|
+
end
|
214
|
+
@workbook.apply_styles
|
215
|
+
assert_equal 9, @workbook.styled_cells.count
|
216
|
+
assert_equal 2, @workbook.style_index.count
|
217
|
+
end
|
218
|
+
|
219
|
+
# Overriding borders (part 2)
|
220
|
+
def test_mixed_borders
|
221
|
+
@filename = 'mixed_borders_2'
|
222
|
+
@workbook.add_worksheet do |sheet|
|
223
|
+
sheet.add_row
|
224
|
+
sheet.add_row ['', '1', '2', '3']
|
225
|
+
sheet.add_row ['', '4', '5', '6']
|
226
|
+
sheet.add_row ['', '7', '8', '9']
|
227
|
+
sheet.add_border 'B2:D4', style: :medium
|
228
|
+
sheet.add_style 'D2:D4', border: { style: :thin, color: '000000' }
|
229
|
+
end
|
230
|
+
@workbook.apply_styles
|
231
|
+
assert_equal 8, @workbook.styled_cells.count
|
232
|
+
assert_equal 6, @workbook.style_index.count
|
233
|
+
end
|
146
234
|
end
|
data/test/workbook_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: axlsx_styler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sakovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- Rakefile
|
114
114
|
- axlsx_styler.gemspec
|
115
115
|
- examples/colors_and_borders.rb
|
116
|
+
- examples/vanilla_axlsx.md
|
116
117
|
- lib/axlsx_styler.rb
|
117
118
|
- lib/axlsx_styler/axlsx_cell.rb
|
118
119
|
- lib/axlsx_styler/axlsx_workbook.rb
|