axlsx_styler 0.2.0 → 1.0.0
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 +5 -5
- data/CHANGELOG.md +20 -0
- data/README.md +39 -32
- data/Rakefile +18 -4
- data/lib/axlsx_styler.rb +4 -57
- data/lib/axlsx_styler/axlsx_cell.rb +30 -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 +27 -27
- data/lib/axlsx_styler/axlsx_worksheet.rb +26 -26
- data/lib/axlsx_styler/version.rb +1 -1
- data/test/custom_assertions.rb +21 -0
- data/test/dummy_app/Rakefile +7 -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 +63 -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 +730 -0
- data/test/helper_methods.rb +12 -0
- data/test/integration/application_test.rb +18 -0
- data/test/test_helper.rb +29 -5
- data/test/unit/borders_test.rb +127 -0
- data/test/unit/examples_test.rb +20 -0
- data/test/unit/general_test.rb +84 -0
- data/test/unit/merge_styles_test.rb +56 -0
- data/test/unit/serialize_test.rb +34 -0
- data/test/unit/to_stream_test.rb +34 -0
- metadata +136 -56
- data/.gitignore +0 -26
- data/.travis.yml +0 -7
- data/Appraisals +0 -7
- data/Gemfile +0 -4
- data/axlsx_styler.gemspec +0 -37
- data/examples/mixing_styles.rb +0 -22
- data/examples/vanilla_axlsx.md +0 -70
- data/gemfiles/axlsx_2.gemfile +0 -7
- data/gemfiles/axlsx_3.gemfile +0 -7
- data/spreadsheet.png +0 -0
- data/test/cell_test.rb +0 -14
- data/test/integration_test.rb +0 -288
- data/test/workbook_test.rb +0 -10
data/.gitignore
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
gemfiles/*.lock
|
8
|
-
InstalledFiles
|
9
|
-
_yardoc
|
10
|
-
coverage
|
11
|
-
doc/
|
12
|
-
lib/bundler/man
|
13
|
-
pkg
|
14
|
-
rdoc
|
15
|
-
spec/reports
|
16
|
-
test/tmp
|
17
|
-
test/version_tmp
|
18
|
-
tmp
|
19
|
-
*.bundle
|
20
|
-
*.so
|
21
|
-
*.o
|
22
|
-
*.a
|
23
|
-
mkmf.log
|
24
|
-
*.xlsx
|
25
|
-
*.xlsx#
|
26
|
-
.DS_Store
|
data/.travis.yml
DELETED
data/Appraisals
DELETED
data/Gemfile
DELETED
data/axlsx_styler.gemspec
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'axlsx_styler/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'axlsx_styler'
|
8
|
-
spec.version = AxlsxStyler::VERSION
|
9
|
-
spec.authors = ['Anton Sakovich']
|
10
|
-
spec.email = ['sakovias@gmail.com']
|
11
|
-
spec.summary = %q(This gem allows to separate data from styles when using Axlsx gem.)
|
12
|
-
spec.description = %q(
|
13
|
-
Axlsx gem is an excellent tool to build Excel worksheets. The sheets are
|
14
|
-
created row-by-row and styles are immediately added to each cell when a
|
15
|
-
row is created. This gem allows to follow an alternative route: fill out
|
16
|
-
a spreadsheet with data and apply styles later. Styles can be added
|
17
|
-
to individual cells as well as to ranges of cells. As a bonus, this gem
|
18
|
-
also simplifies drawing borders around groups of cells.
|
19
|
-
)
|
20
|
-
spec.homepage = 'https://github.com/sakovias/axlsx_styler'
|
21
|
-
spec.license = 'MIT'
|
22
|
-
|
23
|
-
spec.files = `git ls-files -z`.split("\x0")
|
24
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
-
spec.require_paths = ['lib']
|
27
|
-
spec.required_ruby_version = '>= 1.9.3'
|
28
|
-
|
29
|
-
spec.add_dependency 'axlsx', ['>= 2.0', '< 4']
|
30
|
-
spec.add_dependency 'activesupport', '>= 3.1'
|
31
|
-
|
32
|
-
spec.add_development_dependency 'bundler', '~> 1.6'
|
33
|
-
spec.add_development_dependency 'rake', '~> 0.9'
|
34
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
35
|
-
spec.add_development_dependency 'awesome_print', '~> 1.6'
|
36
|
-
spec.add_development_dependency 'appraisal'
|
37
|
-
end
|
data/examples/mixing_styles.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# As of v0.1.7 it is possible to add styles using vanilla axlsx approach
|
2
|
-
# as well as using add_style and add_border. This is something users have
|
3
|
-
# been asking for.
|
4
|
-
#
|
5
|
-
# The example below is superfluous and the same results are more easily achieved
|
6
|
-
# without workbook.styles.add_style. You've been warned!
|
7
|
-
require 'axlsx_styler'
|
8
|
-
|
9
|
-
axlsx = Axlsx::Package.new
|
10
|
-
workbook = axlsx.workbook
|
11
|
-
red = workbook.styles.add_style fg_color: 'FF0000'
|
12
|
-
workbook.add_worksheet do |sheet|
|
13
|
-
sheet.add_row
|
14
|
-
sheet.add_row ['', 'B2', 'C2', 'D2'], style: [nil, red, nil, nil]
|
15
|
-
sheet.add_row ['', 'B3', 'C3', 'D3'], style: [nil, red, nil, nil]
|
16
|
-
sheet.add_row ['', 'B4', 'C4', 'D4'], style: [nil, red, nil, nil]
|
17
|
-
|
18
|
-
sheet.add_style 'B2:D2', b: true
|
19
|
-
sheet.add_border 'B2:D4'
|
20
|
-
end
|
21
|
-
workbook.apply_styles
|
22
|
-
axlsx.serialize File.expand_path('../../tmp/mixing_styles.xlsx', __FILE__)
|
data/examples/vanilla_axlsx.md
DELETED
@@ -1,70 +0,0 @@
|
|
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/gemfiles/axlsx_2.gemfile
DELETED
data/gemfiles/axlsx_3.gemfile
DELETED
data/spreadsheet.png
DELETED
Binary file
|
data/test/cell_test.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CellTest < MiniTest::Test
|
4
|
-
def test_can_add_style
|
5
|
-
p = Axlsx::Package.new
|
6
|
-
wb = p.workbook
|
7
|
-
sheet = wb.add_worksheet
|
8
|
-
row = sheet.add_row ["x", "y"]
|
9
|
-
cell = row.cells.first
|
10
|
-
|
11
|
-
cell.add_style b: true
|
12
|
-
assert_equal({b: true}, cell.raw_style)
|
13
|
-
end
|
14
|
-
end
|
data/test/integration_test.rb
DELETED
@@ -1,288 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class IntegrationTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
@axlsx = Axlsx::Package.new
|
6
|
-
@workbook = @axlsx.workbook
|
7
|
-
end
|
8
|
-
|
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_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.styles.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_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.styles.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_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.styles.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_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.styles.style_index.count
|
69
|
-
to_stream(filename)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_table_with_borders
|
73
|
-
filename = 'borders_test'
|
74
|
-
@workbook.add_worksheet do |sheet|
|
75
|
-
sheet.add_row
|
76
|
-
sheet.add_row ['', 'Product', 'Category', 'Price']
|
77
|
-
sheet.add_row ['', 'Butter', 'Dairy', 4.99]
|
78
|
-
sheet.add_row ['', 'Bread', 'Baked Goods', 3.45]
|
79
|
-
sheet.add_row ['', 'Broccoli', 'Produce', 2.99]
|
80
|
-
sheet.add_row ['', 'Pizza', 'Frozen Foods', 4.99]
|
81
|
-
sheet.column_widths 5, 20, 20, 20
|
82
|
-
|
83
|
-
sheet.add_style 'B2:D2', b: true
|
84
|
-
sheet.add_style 'B2:B6', b: true
|
85
|
-
sheet.add_style 'B2:D2', bg_color: '95AFBA'
|
86
|
-
sheet.add_style 'B3:D6', bg_color: 'E2F89C'
|
87
|
-
sheet.add_style 'D3:D6', alignment: { horizontal: :left }
|
88
|
-
sheet.add_border 'B2:D6'
|
89
|
-
sheet.add_border 'B3:D3', [:top]
|
90
|
-
sheet.add_border 'B3:D3', edges: [:bottom], style: :medium
|
91
|
-
sheet.add_border 'B3:D3', edges: [:bottom], style: :medium, color: '32f332'
|
92
|
-
end
|
93
|
-
serialize(filename)
|
94
|
-
assert_equal 12, @workbook.styles.style_index.count
|
95
|
-
assert_equal 12 + 2, @workbook.styles.style_index.keys.max
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_duplicate_borders
|
99
|
-
filename = 'duplicate_borders_test'
|
100
|
-
@workbook.add_worksheet do |sheet|
|
101
|
-
sheet.add_row
|
102
|
-
sheet.add_row ['', 'B2', 'C2', 'D2']
|
103
|
-
sheet.add_row ['', 'B3', 'C3', 'D3']
|
104
|
-
sheet.add_row ['', 'B4', 'C4', 'D4']
|
105
|
-
|
106
|
-
sheet.add_border 'B2:D4'
|
107
|
-
sheet.add_border 'B2:D4'
|
108
|
-
end
|
109
|
-
serialize(filename)
|
110
|
-
assert_equal 8, @workbook.styles.style_index.count
|
111
|
-
assert_equal 8, @workbook.styled_cells.count
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_multiple_style_borders_on_same_cells
|
115
|
-
filename = 'multiple_style_borders'
|
116
|
-
@workbook.add_worksheet do |sheet|
|
117
|
-
sheet.add_row
|
118
|
-
sheet.add_row ['', 'B2', 'C2', 'D2']
|
119
|
-
sheet.add_row ['', 'B3', 'C3', 'D3']
|
120
|
-
|
121
|
-
sheet.add_border 'B2:D3', :all
|
122
|
-
sheet.add_border 'B2:D2', edges: [:bottom], style: :thick, color: 'ff0000'
|
123
|
-
end
|
124
|
-
serialize(filename)
|
125
|
-
assert_equal 6, @workbook.styles.style_index.count
|
126
|
-
assert_equal 6, @workbook.styled_cells.count
|
127
|
-
|
128
|
-
b2_cell_style = {
|
129
|
-
border: {
|
130
|
-
style: :thick,
|
131
|
-
color: 'ff0000',
|
132
|
-
edges: [:bottom, :left, :top]
|
133
|
-
},
|
134
|
-
type: :xf,
|
135
|
-
name: 'Arial',
|
136
|
-
sz: 11,
|
137
|
-
family: 1
|
138
|
-
}
|
139
|
-
assert_equal b2_cell_style, @workbook.styles.style_index.values.find{|x| x == b2_cell_style}
|
140
|
-
|
141
|
-
d3_cell_style = {
|
142
|
-
border: {
|
143
|
-
style: :thin,
|
144
|
-
color: '000000',
|
145
|
-
edges: [:bottom, :right]
|
146
|
-
},
|
147
|
-
type: :xf,
|
148
|
-
name: 'Arial',
|
149
|
-
sz: 11,
|
150
|
-
family: 1
|
151
|
-
}
|
152
|
-
assert_equal d3_cell_style, @workbook.styles.style_index.values.find{|x| x == d3_cell_style}
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_table_with_num_fmt
|
156
|
-
filename = 'num_fmt_test'
|
157
|
-
t = Time.now
|
158
|
-
day = 24 * 60 * 60
|
159
|
-
@workbook.add_worksheet do |sheet|
|
160
|
-
sheet.add_row %w(Date Count Percent)
|
161
|
-
sheet.add_row [t - 2 * day, 2, 2.to_f.round(2) / 11]
|
162
|
-
sheet.add_row [t - 1 * day, 3, 3.to_f.round(2) / 11]
|
163
|
-
sheet.add_row [t, 6, 6.to_f.round(2) / 11]
|
164
|
-
|
165
|
-
sheet.add_style 'A1:B1', b: true
|
166
|
-
sheet.add_style 'A2:A4', format_code: 'YYYY-MM-DD hh:mm:ss'
|
167
|
-
end
|
168
|
-
serialize(filename)
|
169
|
-
assert_equal 2, @workbook.styles.style_index.count
|
170
|
-
assert_equal 2 + 2, @workbook.styles.style_index.keys.max
|
171
|
-
assert_equal 5, @workbook.styled_cells.count
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_duplicate_styles
|
175
|
-
filename = 'duplicate_styles'
|
176
|
-
@workbook.add_worksheet do |sheet|
|
177
|
-
sheet.add_row %w(Index City)
|
178
|
-
sheet.add_row [1, 'Ottawa']
|
179
|
-
sheet.add_row [2, 'Boston']
|
180
|
-
|
181
|
-
sheet.add_border 'A1:B1', [:bottom]
|
182
|
-
sheet.add_border 'A1:B1', [:bottom]
|
183
|
-
sheet.add_style 'A1:A3', b: true
|
184
|
-
sheet.add_style 'A1:A3', b: true
|
185
|
-
end
|
186
|
-
serialize(filename)
|
187
|
-
assert_equal 4, @workbook.styled_cells.count
|
188
|
-
assert_equal 3, @workbook.styles.style_index.count
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_multiple_named_styles
|
192
|
-
filename = 'multiple_named_styles'
|
193
|
-
bold_blue = { b: true, fg_color: '0000FF' }
|
194
|
-
large = { sz: 16 }
|
195
|
-
red = { fg_color: 'FF0000' }
|
196
|
-
@workbook.add_worksheet do |sheet|
|
197
|
-
sheet.add_row %w(Index City)
|
198
|
-
sheet.add_row [1, 'Ottawa']
|
199
|
-
sheet.add_row [2, 'Boston']
|
200
|
-
|
201
|
-
sheet.add_style 'A1:B1', bold_blue, large
|
202
|
-
sheet.add_style 'A1:A3', red
|
203
|
-
end
|
204
|
-
serialize(filename)
|
205
|
-
assert_equal 4, @workbook.styled_cells.count
|
206
|
-
assert_equal 3, @workbook.styles.style_index.count
|
207
|
-
end
|
208
|
-
|
209
|
-
# Overriding borders (part 1)
|
210
|
-
def test_mixed_borders_1
|
211
|
-
filename = 'mixed_borders_1'
|
212
|
-
@workbook.add_worksheet do |sheet|
|
213
|
-
sheet.add_row
|
214
|
-
sheet.add_row ['', '1', '2', '3']
|
215
|
-
sheet.add_row ['', '4', '5', '6']
|
216
|
-
sheet.add_row ['', '7', '8', '9']
|
217
|
-
sheet.add_style 'B2:D4', border: { style: :thin, color: '000000' }
|
218
|
-
sheet.add_border 'C3:D4', style: :medium
|
219
|
-
end
|
220
|
-
@workbook.apply_styles
|
221
|
-
assert_equal 9, @workbook.styled_cells.count
|
222
|
-
assert_equal 2, @workbook.styles.style_index.count
|
223
|
-
serialize(filename)
|
224
|
-
end
|
225
|
-
|
226
|
-
# Overriding borders (part 2)
|
227
|
-
def test_mixed_borders
|
228
|
-
filename = 'mixed_borders_2'
|
229
|
-
@workbook.add_worksheet do |sheet|
|
230
|
-
sheet.add_row
|
231
|
-
sheet.add_row ['', '1', '2', '3']
|
232
|
-
sheet.add_row ['', '4', '5', '6']
|
233
|
-
sheet.add_row ['', '7', '8', '9']
|
234
|
-
sheet.add_border 'B2:D4', style: :medium
|
235
|
-
sheet.add_style 'D2:D4', border: { style: :thin, color: '000000' }
|
236
|
-
end
|
237
|
-
@workbook.apply_styles
|
238
|
-
assert_equal 8, @workbook.styled_cells.count
|
239
|
-
assert_equal 6, @workbook.styles.style_index.count
|
240
|
-
serialize(filename)
|
241
|
-
end
|
242
|
-
|
243
|
-
def test_merge_styles_1
|
244
|
-
filename = 'merge_styles_1'
|
245
|
-
bold = @workbook.styles.add_style b: true
|
246
|
-
|
247
|
-
@workbook.add_worksheet do |sheet|
|
248
|
-
sheet.add_row
|
249
|
-
sheet.add_row ['', '1', '2', '3'], style: [nil, bold]
|
250
|
-
sheet.add_row ['', '4', '5', '6'], style: bold
|
251
|
-
sheet.add_row ['', '7', '8', '9']
|
252
|
-
sheet.add_style 'B2:D4', b: true
|
253
|
-
sheet.add_border 'B2:D4', { style: :thin, color: '000000' }
|
254
|
-
end
|
255
|
-
@workbook.apply_styles
|
256
|
-
assert_equal 9, @workbook.styles.style_index.count
|
257
|
-
serialize(filename)
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_merge_styles_2
|
261
|
-
filename = 'merge_styles_2'
|
262
|
-
bold = @workbook.styles.add_style b: true
|
263
|
-
|
264
|
-
@workbook.add_worksheet do |sheet|
|
265
|
-
sheet.add_row ['A1', 'B1'], style: [nil, bold]
|
266
|
-
sheet.add_row ['A2', 'B2'], style: bold
|
267
|
-
sheet.add_row ['A3', 'B3']
|
268
|
-
sheet.add_style 'A1:A2', i: true
|
269
|
-
end
|
270
|
-
@workbook.apply_styles
|
271
|
-
assert_equal 3, @workbook.styles.style_index.count
|
272
|
-
serialize(filename)
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_merge_styles_3
|
276
|
-
filename = 'merge_styles_3'
|
277
|
-
bold = @workbook.styles.add_style b: true
|
278
|
-
|
279
|
-
@workbook.add_worksheet do |sheet|
|
280
|
-
sheet.add_row ['A1', 'B1'], style: [nil, bold]
|
281
|
-
sheet.add_row ['A2', 'B2']
|
282
|
-
sheet.add_style 'B1:B2', bg_color: 'FF0000'
|
283
|
-
end
|
284
|
-
@workbook.apply_styles
|
285
|
-
assert_equal 3, @workbook.styles.style_index.count
|
286
|
-
serialize(filename)
|
287
|
-
end
|
288
|
-
end
|