axlsx_styler 0.1.2 → 0.1.3
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 +6 -3
- data/examples/colors_and_borders.rb +1 -1
- data/lib/axlsx_styler/axlsx_worksheet.rb +5 -4
- data/lib/axlsx_styler/border_creator.rb +14 -7
- data/lib/axlsx_styler/version.rb +1 -1
- data/test/integration_test.rb +53 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a78ec129205b19cc466a29461787fcdd8e4d6113
|
4
|
+
data.tar.gz: 0c04a30a6c48799392eb765e7fbd67c6236ef294
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c280bc771e8bda4131834f6a68502e5ade34ed808b61a996327806927d1467485fd226cebbba347940e97754f894053d15d02cd11b11e0292028197ebe868fdb
|
7
|
+
data.tar.gz: 6aca119eb6c65299047e927836c972dcc5252f02bed720bc4a9d7fc6da0bce77e78a560ad74d6efe617076db2881d0627a1217ccd51462e4d9288dc95144f09f
|
data/README.md
CHANGED
@@ -38,10 +38,13 @@ You can also add borders to ranges of cells:
|
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
sheet.add_border 'B2:D5'
|
41
|
-
sheet.add_border 'B2:D5', [:right]
|
41
|
+
sheet.add_border 'B2:D5', [:bottom, :right]
|
42
|
+
sheet.add_border 'B2:D5', { edges: [:bottom, :right], style: :thick, color: 'FF0000' }
|
42
43
|
```
|
43
44
|
|
44
|
-
|
45
|
+
Border parameters are optional. The default is to draw a thin black border on all four edges of the selected cell range.
|
46
|
+
|
47
|
+
The styles are applied with a simple call:
|
45
48
|
|
46
49
|
```ruby
|
47
50
|
workbook.apply_styles
|
@@ -106,7 +109,7 @@ wb.add_worksheet do |sheet|
|
|
106
109
|
border: { style: :thin, color: border_color, edges: [:top, :right, :bottom] }
|
107
110
|
})
|
108
111
|
sheet.add_row
|
109
|
-
sheet.add_row(["", "Product", "Category", "Price"],
|
112
|
+
sheet.add_row(["", "Product", "Category", "Price"],
|
110
113
|
style: [ nil, top_left_corner, top_edge, top_right_corner ]
|
111
114
|
)
|
112
115
|
|
@@ -17,7 +17,7 @@ workbook.add_worksheet do |sheet|
|
|
17
17
|
sheet.add_style 'B3:D5', bg_color: 'E2F89C'
|
18
18
|
sheet.add_style 'D3:D5', alignment: { horizontal: :left }
|
19
19
|
sheet.add_border 'B2:D5'
|
20
|
-
sheet.add_border 'B3:D3', [:top]
|
20
|
+
sheet.add_border 'B3:D3', [:top], :thick
|
21
21
|
end
|
22
22
|
workbook.apply_styles
|
23
23
|
axlsx.serialize File.expand_path('../../tmp/grocery.xlsx', __FILE__)
|
@@ -21,13 +21,14 @@ module AxlsxStyler
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Examples:
|
24
|
-
# add_border 'B2:F8', [:left, :top]
|
24
|
+
# add_border 'B2:F8', [:left, :top], :medium, '00330f'
|
25
|
+
# add_border 'B2:F8', [:left, :top], :medium
|
25
26
|
# add_border 'C2:G10', [:top]
|
26
27
|
# add_border 'C2:G10'
|
27
|
-
#
|
28
|
-
def add_border(cell_ref,
|
28
|
+
# add_border 'B2:D5', { style: :thick, color: '00330f', edges: [:left, :right] }
|
29
|
+
def add_border(cell_ref, args = :all)
|
29
30
|
cells = self[cell_ref]
|
30
|
-
BorderCreator.new(self, cells,
|
31
|
+
BorderCreator.new(self, cells, args).draw
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -1,14 +1,22 @@
|
|
1
1
|
class BorderCreator
|
2
|
-
attr_reader :worksheet, :cells, :edges
|
2
|
+
attr_reader :worksheet, :cells, :edges, :width, :color
|
3
3
|
|
4
|
-
def initialize(worksheet, cells,
|
4
|
+
def initialize(worksheet, cells, args)
|
5
5
|
@worksheet = worksheet
|
6
6
|
@cells = cells
|
7
|
-
|
7
|
+
if args.is_a?(Hash)
|
8
|
+
@edges = args[:edges] || :all
|
9
|
+
@width = args[:style] || :thin
|
10
|
+
@color = args[:color] || '000000'
|
11
|
+
else
|
12
|
+
@edges = args || :all
|
13
|
+
@width = :thin
|
14
|
+
@color = '000000'
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
18
|
def draw
|
11
|
-
selected_edges(edges).each { |edge| add_border(edge) }
|
19
|
+
selected_edges(edges).each { |edge| add_border(edge, width, color) }
|
12
20
|
end
|
13
21
|
|
14
22
|
private
|
@@ -24,14 +32,13 @@ class BorderCreator
|
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
27
|
-
def add_border(position)
|
35
|
+
def add_border(position, width, color)
|
28
36
|
style = {
|
29
37
|
border: {
|
30
|
-
style:
|
38
|
+
style: width, color: color, edges: [position.to_sym]
|
31
39
|
}
|
32
40
|
}
|
33
41
|
worksheet.add_style border_cells[position.to_sym], style
|
34
|
-
# add_style border_cells(cell_ref)[position.to_sym], style
|
35
42
|
end
|
36
43
|
|
37
44
|
def border_cells
|
data/lib/axlsx_styler/version.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -31,12 +31,65 @@ class IntegrationTest < MiniTest::Test
|
|
31
31
|
sheet.add_style 'D3:D6', alignment: { horizontal: :left }
|
32
32
|
sheet.add_border 'B2:D6'
|
33
33
|
sheet.add_border 'B3:D3', [:top]
|
34
|
+
sheet.add_border 'B3:D3', edges: [:bottom], style: :medium
|
35
|
+
sheet.add_border 'B3:D3', edges: [:bottom], style: :medium, color: '32f332'
|
34
36
|
end
|
35
37
|
@workbook.apply_styles
|
36
38
|
assert_equal 12, @workbook.style_index.count
|
37
39
|
assert_equal 12 + 2, @workbook.style_index.keys.max
|
38
40
|
end
|
39
41
|
|
42
|
+
def test_duplicate_borders
|
43
|
+
@filename = 'duplicate_borders_test'
|
44
|
+
@workbook.add_worksheet do |sheet|
|
45
|
+
sheet.add_row
|
46
|
+
sheet.add_row ['', 'B2', 'C2', 'D2']
|
47
|
+
sheet.add_row ['', 'B3', 'C3', 'D3']
|
48
|
+
sheet.add_row ['', 'B4', 'C4', 'D4']
|
49
|
+
|
50
|
+
sheet.add_border 'B2:D4'
|
51
|
+
sheet.add_border 'B2:D4'
|
52
|
+
end
|
53
|
+
@workbook.apply_styles
|
54
|
+
assert_equal 8, @workbook.style_index.count
|
55
|
+
assert_equal 8, @workbook.styled_cells.count
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_multiple_style_borders_on_same_sells
|
59
|
+
@filename = 'multiple_style_borders'
|
60
|
+
@workbook.add_worksheet do |sheet|
|
61
|
+
sheet.add_row
|
62
|
+
sheet.add_row ['', 'B2', 'C2', 'D2']
|
63
|
+
sheet.add_row ['', 'B3', 'C3', 'D3']
|
64
|
+
|
65
|
+
sheet.add_border 'B2:D3', :all
|
66
|
+
sheet.add_border 'B2:D2', edges: [:bottom], style: :thick, color: 'ff0000'
|
67
|
+
end
|
68
|
+
@workbook.apply_styles
|
69
|
+
assert_equal 6, @workbook.style_index.count
|
70
|
+
assert_equal 6, @workbook.styled_cells.count
|
71
|
+
|
72
|
+
b2_cell_style = {
|
73
|
+
border: {
|
74
|
+
style: :thick,
|
75
|
+
color: 'ff0000',
|
76
|
+
edges: [:top, :left, :bottom]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
assert_equal b2_cell_style, @workbook.style_index
|
80
|
+
.find { |_, v| v[:border][:edges] == [:top, :left, :bottom] }[1]
|
81
|
+
|
82
|
+
d3_cell_style = {
|
83
|
+
border: {
|
84
|
+
style: :thin,
|
85
|
+
color: '000000',
|
86
|
+
edges: [:right, :bottom]
|
87
|
+
}
|
88
|
+
}
|
89
|
+
assert_equal d3_cell_style, @workbook.style_index
|
90
|
+
.find { |_, v| v[:border][:edges] == [:right, :bottom] }[1]
|
91
|
+
end
|
92
|
+
|
40
93
|
def test_table_with_num_fmt
|
41
94
|
@filename = 'num_fmt_test'
|
42
95
|
t = Time.now
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sakovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|