axlsx 1.1.6 → 1.1.7
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.
- data/README.md +19 -6
- data/examples/axis-titles.xlsx +0 -0
- data/examples/basic_charts.rb +46 -0
- data/examples/basic_charts.xlsx +0 -0
- data/examples/charts.xlsx +0 -0
- data/examples/example.rb +17 -1
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/pie_chart_excel.xlsx +0 -0
- data/examples/pie_chart_saved.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/sheet_view.rb +34 -0
- data/examples/sheet_view.xlsx +0 -0
- data/examples/~$example.xlsx +0 -0
- data/lib/axlsx.rb +3 -2
- data/lib/axlsx/drawing/axis.rb +18 -0
- data/lib/axlsx/drawing/cat_axis.rb +3 -3
- data/lib/axlsx/drawing/chart.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +0 -1
- data/lib/axlsx/drawing/graphic_frame.rb +2 -2
- data/lib/axlsx/drawing/num_data.rb +2 -2
- data/lib/axlsx/drawing/title.rb +21 -9
- data/lib/axlsx/package.rb +9 -5
- data/lib/axlsx/util/validators.rb +28 -4
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +7 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +4 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +1 -1
- data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
- data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +27 -10
- data/test/drawing/tc_axis.rb +19 -2
- data/test/drawing/tc_cat_axis.rb +3 -3
- data/test/drawing/tc_num_data.rb +5 -1
- data/test/drawing/tc_title.rb +16 -0
- data/test/tc_package.rb +24 -4
- data/test/util/tc_validators.rb +68 -11
- data/test/workbook/worksheet/tc_pane.rb +94 -0
- data/test/workbook/worksheet/tc_selection.rb +94 -0
- data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
- data/test/workbook/worksheet/tc_worksheet.rb +0 -7
- metadata +28 -13
- data/examples/pie_chart.rb +0 -16
- data/examples/pie_chart.xlsx +0 -0
- data/examples/~$pie_chart_saved.xlsx +0 -0
@@ -16,6 +16,15 @@ module Axlsx
|
|
16
16
|
yield @sheet_protection if block_given?
|
17
17
|
@sheet_protection
|
18
18
|
end
|
19
|
+
|
20
|
+
# The sheet view object for this worksheet
|
21
|
+
# @return [SheetView]
|
22
|
+
# @see [SheetView]
|
23
|
+
def sheet_view
|
24
|
+
@sheet_view ||= SheetView.new
|
25
|
+
yield @sheet_view if block_given?
|
26
|
+
@sheet_view
|
27
|
+
end
|
19
28
|
|
20
29
|
# The workbook that owns this worksheet
|
21
30
|
# @return [Workbook]
|
@@ -51,14 +60,21 @@ module Axlsx
|
|
51
60
|
|
52
61
|
# Indicates if the worksheet should show gridlines or not
|
53
62
|
# @return Boolean
|
54
|
-
|
55
|
-
|
63
|
+
# @deprecated Use {SheetView#show_grid_lines} instead.
|
64
|
+
def show_gridlines
|
65
|
+
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
|
66
|
+
sheet_view.show_grid_lines
|
67
|
+
end
|
56
68
|
|
57
69
|
# Indicates if the worksheet is selected in the workbook
|
58
70
|
# It is possible to have more than one worksheet selected, however it might cause issues
|
59
71
|
# in some older versions of excel when using copy and paste.
|
60
72
|
# @return Boolean
|
61
|
-
|
73
|
+
# @deprecated Use {SheetView#tab_selected} instead.
|
74
|
+
def selected
|
75
|
+
warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
|
76
|
+
sheet_view.tab_selected
|
77
|
+
end
|
62
78
|
|
63
79
|
# Indicates if the worksheet will be fit by witdh or height to a specific number of pages.
|
64
80
|
# To alter the width or height for page fitting, please use page_setup.fit_to_widht or page_setup.fit_to_height.
|
@@ -160,14 +176,12 @@ module Axlsx
|
|
160
176
|
self.workbook = wb
|
161
177
|
@workbook.worksheets << self
|
162
178
|
@page_marging = @page_setup = @print_options = nil
|
163
|
-
@drawing = @page_margins = @auto_filter = @sheet_protection = nil
|
179
|
+
@drawing = @page_margins = @auto_filter = @sheet_protection = @sheet_view = nil
|
164
180
|
@merged_cells = []
|
165
181
|
@auto_fit_data = []
|
166
182
|
@conditional_formattings = []
|
167
183
|
@data_validations = []
|
168
184
|
@comments = Comments.new(self)
|
169
|
-
@selected = false
|
170
|
-
@show_gridlines = true
|
171
185
|
self.name = "Sheet" + (index+1).to_s
|
172
186
|
@page_margins = PageMargins.new options[:page_margins] if options[:page_margins]
|
173
187
|
@page_setup = PageSetup.new options[:page_setup] if options[:page_setup]
|
@@ -246,16 +260,20 @@ module Axlsx
|
|
246
260
|
# Indicates if gridlines should be shown in the sheet.
|
247
261
|
# This is true by default.
|
248
262
|
# @return [Boolean]
|
263
|
+
# @deprecated Use {SheetView#show_grid_lines=} instead.
|
249
264
|
def show_gridlines=(v)
|
265
|
+
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
|
250
266
|
Axlsx::validate_boolean v
|
251
|
-
|
267
|
+
sheet_view.show_grid_lines = v
|
252
268
|
end
|
253
269
|
|
254
270
|
# @see selected
|
255
271
|
# @return [Boolean]
|
272
|
+
# @deprecated Use {SheetView#tab_selected=} instead.
|
256
273
|
def selected=(v)
|
274
|
+
warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
|
257
275
|
Axlsx::validate_boolean v
|
258
|
-
|
276
|
+
sheet_view.tab_selected = v
|
259
277
|
end
|
260
278
|
|
261
279
|
|
@@ -492,8 +510,7 @@ module Axlsx
|
|
492
510
|
str.concat "<worksheet xmlns=\"%s\" xmlns:r=\"%s\">" % [XML_NS, XML_NS_R]
|
493
511
|
str.concat "<sheetPr><pageSetUpPr fitToPage=\"%s\"></pageSetUpPr></sheetPr>" % fit_to_page if fit_to_page
|
494
512
|
str.concat "<dimension ref=\"%s\"></dimension>" % dimension unless rows.size == 0
|
495
|
-
str
|
496
|
-
|
513
|
+
@sheet_view.to_xml_string(str) if @sheet_view
|
497
514
|
if @column_info.size > 0
|
498
515
|
str << "<cols>"
|
499
516
|
@column_info.each { |col| col.to_xml_string(str) }
|
data/test/drawing/tc_axis.rb
CHANGED
@@ -2,8 +2,10 @@ require 'tc_helper.rb'
|
|
2
2
|
|
3
3
|
class TestAxis < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
|
6
|
+
@axis = Axlsx::Axis.new 12345, 54321, :gridlines => false, :title => 'Foo'
|
6
7
|
end
|
8
|
+
|
7
9
|
def teardown
|
8
10
|
end
|
9
11
|
|
@@ -14,6 +16,21 @@ class TestAxis < Test::Unit::TestCase
|
|
14
16
|
assert_equal(@axis.crosses, :autoZero, "tick label position default incorrect")
|
15
17
|
assert(@axis.scaling.is_a?(Axlsx::Scaling) && @axis.scaling.orientation == :minMax, "scaling default incorrect")
|
16
18
|
assert_raise(ArgumentError) { Axlsx::Axis.new( -1234, 'abcd') }
|
19
|
+
assert_equal('Foo', @axis.title.text)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_cell_based_axis_title
|
23
|
+
p = Axlsx::Package.new
|
24
|
+
p.workbook.add_worksheet(:name=>'foosheet') do |sheet|
|
25
|
+
sheet.add_row ['battle victories']
|
26
|
+
sheet.add_row ['bird', 1, 2, 1]
|
27
|
+
sheet.add_row ['cat', 7, 9, 10]
|
28
|
+
sheet.add_chart(Axlsx::Line3DChart) do |chart|
|
29
|
+
chart.add_series :data => sheet['B2:D2'], :labels => sheet['B1']
|
30
|
+
chart.valAxis.title = sheet['A1']
|
31
|
+
assert_equal('battle victories', chart.valAxis.title.text)
|
32
|
+
end
|
33
|
+
end
|
17
34
|
end
|
18
35
|
|
19
36
|
def test_axis_position
|
@@ -57,6 +74,6 @@ class TestAxis < Test::Unit::TestCase
|
|
57
74
|
assert(doc.xpath("//c:crosses[@val='#{@axis.crosses.to_s}']"))
|
58
75
|
assert(doc.xpath("//c:crossAx[@val='#{@axis.crossAx.to_s}']"))
|
59
76
|
assert(doc.xpath("//a:bodyPr[@rot='#{@axis.label_rotation.to_s}']"))
|
60
|
-
|
77
|
+
assert(doc.xpath("//a:t[text()='Foo']"))
|
61
78
|
end
|
62
79
|
end
|
data/test/drawing/tc_cat_axis.rb
CHANGED
@@ -10,7 +10,7 @@ class TestCatAxis < Test::Unit::TestCase
|
|
10
10
|
def test_initialization
|
11
11
|
assert_equal(@axis.auto, 1, "axis auto default incorrect")
|
12
12
|
assert_equal(@axis.lblAlgn, :ctr, "label align default incorrect")
|
13
|
-
assert_equal(@axis.lblOffset, "100
|
13
|
+
assert_equal(@axis.lblOffset, "100", "label offset default incorrect")
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_auto
|
@@ -24,8 +24,8 @@ class TestCatAxis < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_lblOffset
|
27
|
-
assert_raise(ArgumentError, "requires valid label offset") { @axis.lblOffset =
|
28
|
-
assert_nothing_raised("accepts valid label offset") { @axis.lblOffset = "20
|
27
|
+
assert_raise(ArgumentError, "requires valid label offset") { @axis.lblOffset = 'foo' }
|
28
|
+
assert_nothing_raised("accepts valid label offset") { @axis.lblOffset = "20" }
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
data/test/drawing/tc_num_data.rb
CHANGED
@@ -9,7 +9,11 @@ class TestNumData < Test::Unit::TestCase
|
|
9
9
|
def test_initialize
|
10
10
|
assert_equal(@num_data.format_code, "General")
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
def test_formula_based_cell
|
14
|
+
|
15
|
+
end
|
16
|
+
|
13
17
|
def test_format_code
|
14
18
|
assert_raise(ArgumentError) {@num_data.format_code = 7}
|
15
19
|
assert_nothing_raised {@num_data.format_code = 'foo_bar'}
|
data/test/drawing/tc_title.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../"
|
2
|
+
|
1
3
|
require 'tc_helper.rb'
|
2
4
|
|
3
5
|
class TestTitle < Test::Unit::TestCase
|
@@ -30,4 +32,18 @@ class TestTitle < Test::Unit::TestCase
|
|
30
32
|
assert(@title.text == "one")
|
31
33
|
end
|
32
34
|
|
35
|
+
def test_to_xml_string_text
|
36
|
+
@chart.title.text = 'foo'
|
37
|
+
doc = Nokogiri::XML(@chart.to_xml_string)
|
38
|
+
assert_equal(1, doc.xpath('//c:rich').size)
|
39
|
+
assert_equal(1, doc.xpath("//a:t[text()='foo']").size)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_to_xml_string_cell
|
43
|
+
@chart.title.cell = @row.cells.first
|
44
|
+
doc = Nokogiri::XML(@chart.to_xml_string)
|
45
|
+
assert_equal(1, doc.xpath('//c:strCache').size)
|
46
|
+
assert_equal(1, doc.xpath('//c:v[text()="one"]').size)
|
47
|
+
end
|
48
|
+
|
33
49
|
end
|
data/test/tc_package.rb
CHANGED
@@ -9,9 +9,29 @@ class TestPackage < Test::Unit::TestCase
|
|
9
9
|
ws.add_row ['Yes!', 'We', 'can!']
|
10
10
|
ws.add_comment :author => 'alice', :text => 'Hi Bob', :ref => 'A12'
|
11
11
|
ws.add_comment :author => 'bob', :text => 'Hi Alice', :ref => 'F19'
|
12
|
+
ws.sheet_view do |vs|
|
13
|
+
vs.pane do |p|
|
14
|
+
p.active_pane = :top_right
|
15
|
+
p.state = :split
|
16
|
+
p.x_split = 11080
|
17
|
+
p.y_split = 5000
|
18
|
+
p.top_left_cell = 'C44'
|
19
|
+
end
|
20
|
+
|
21
|
+
vs.add_selection(:top_left, { :active_cell => 'A2', :sqref => 'A2' })
|
22
|
+
vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
|
23
|
+
vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
|
24
|
+
vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
|
25
|
+
end
|
26
|
+
|
27
|
+
ws.add_chart(Axlsx::Pie3DChart, :title => "これは?", :start_at => [0,3]) do |chart|
|
28
|
+
chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"]
|
29
|
+
end
|
30
|
+
|
31
|
+
ws.add_chart(Axlsx::Line3DChart, :title => "axis labels") do |chart|
|
32
|
+
chart.valAxis.title = 'bob'
|
33
|
+
end
|
12
34
|
|
13
|
-
chart = ws.add_chart Axlsx::Pie3DChart, :title => "これは?", :start_at => [0,3]
|
14
|
-
chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"]
|
15
35
|
@fname = 'axlsx_test_serialization.xlsx'
|
16
36
|
img = File.expand_path('../../examples/image1.jpeg', __FILE__)
|
17
37
|
ws.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
|
@@ -100,7 +120,7 @@ class TestPackage < Test::Unit::TestCase
|
|
100
120
|
|
101
121
|
|
102
122
|
#no mystery parts
|
103
|
-
assert_equal(p.size,
|
123
|
+
assert_equal(p.size, 19)
|
104
124
|
|
105
125
|
end
|
106
126
|
|
@@ -143,7 +163,7 @@ class TestPackage < Test::Unit::TestCase
|
|
143
163
|
# in testing.
|
144
164
|
assert(stream.size > 80000)
|
145
165
|
end
|
146
|
-
|
166
|
+
|
147
167
|
def test_encrypt
|
148
168
|
# this is no where near close to ready yet
|
149
169
|
assert(@package.encrypt('your_mom.xlsxl', 'has a password') == false)
|
data/test/util/tc_validators.rb
CHANGED
@@ -83,15 +83,25 @@ class TestValidators < Test::Unit::TestCase
|
|
83
83
|
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "mm" }
|
84
84
|
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "-29cm" }
|
85
85
|
|
86
|
-
#
|
87
|
-
assert_nothing_raised { Axlsx.
|
88
|
-
assert_nothing_raised { Axlsx.
|
89
|
-
assert_nothing_raised { Axlsx.
|
90
|
-
assert_raise(ArgumentError) { Axlsx.
|
91
|
-
assert_raise(ArgumentError) { Axlsx.
|
92
|
-
assert_raise(ArgumentError) { Axlsx.
|
93
|
-
assert_raise(ArgumentError) { Axlsx.
|
94
|
-
|
86
|
+
#scale_10_400
|
87
|
+
assert_nothing_raised { Axlsx.validate_scale_10_400 10 }
|
88
|
+
assert_nothing_raised { Axlsx.validate_scale_10_400 100 }
|
89
|
+
assert_nothing_raised { Axlsx.validate_scale_10_400 400 }
|
90
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 9 }
|
91
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 10.0 }
|
92
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 400.1 }
|
93
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 "99" }
|
94
|
+
|
95
|
+
#scale_0_10_400
|
96
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 0 }
|
97
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 10 }
|
98
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 100 }
|
99
|
+
assert_nothing_raised { Axlsx.validate_scale_0_10_400 400 }
|
100
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 9 }
|
101
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 10.0 }
|
102
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 400.1 }
|
103
|
+
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 "99" }
|
104
|
+
|
95
105
|
#page_orientation
|
96
106
|
assert_nothing_raised { Axlsx.validate_page_orientation :default }
|
97
107
|
assert_nothing_raised { Axlsx.validate_page_orientation :landscape }
|
@@ -99,6 +109,53 @@ class TestValidators < Test::Unit::TestCase
|
|
99
109
|
assert_raise(ArgumentError) { Axlsx.validate_page_orientation nil }
|
100
110
|
assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 }
|
101
111
|
assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" }
|
112
|
+
|
113
|
+
#data_validation_error_style
|
114
|
+
[:information, :stop, :warning].each do |sym|
|
115
|
+
assert_nothing_raised { Axlsx.validate_data_validation_error_style sym }
|
116
|
+
end
|
117
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
118
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'warning' }
|
119
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
120
|
+
|
121
|
+
#data_validation_operator
|
122
|
+
[:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].each do |sym|
|
123
|
+
assert_nothing_raised { Axlsx.validate_data_validation_operator sym }
|
124
|
+
end
|
125
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
126
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'lessThan' }
|
127
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
128
|
+
|
129
|
+
#data_validation_type
|
130
|
+
[:custom, :data, :decimal, :list, :none, :textLength, :time, :whole].each do |sym|
|
131
|
+
assert_nothing_raised { Axlsx.validate_data_validation_type sym }
|
132
|
+
end
|
133
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
134
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'decimal' }
|
135
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
136
|
+
|
137
|
+
#sheet_view_type
|
138
|
+
[:normal, :page_break_preview, :page_layout].each do |sym|
|
139
|
+
assert_nothing_raised { Axlsx.validate_sheet_view_type sym }
|
140
|
+
end
|
141
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
142
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'page_layout' }
|
143
|
+
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
144
|
+
|
145
|
+
#active_pane_type
|
146
|
+
[:bottom_left, :bottom_right, :top_left, :top_right].each do |sym|
|
147
|
+
assert_nothing_raised { Axlsx.validate_pane_type sym }
|
148
|
+
end
|
149
|
+
assert_raise(ArgumentError) { Axlsx.validate_pane_type :other_symbol }
|
150
|
+
assert_raise(ArgumentError) { Axlsx.validate_pane_type 'bottom_left' }
|
151
|
+
assert_raise(ArgumentError) { Axlsx.validate_pane_type 0 }
|
152
|
+
|
153
|
+
#split_state_type
|
154
|
+
[:frozen, :frozen_split, :split].each do |sym|
|
155
|
+
assert_nothing_raised { Axlsx.validate_split_state_type sym }
|
156
|
+
end
|
157
|
+
assert_raise(ArgumentError) { Axlsx.validate_split_state_type :other_symbol }
|
158
|
+
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 'frozen_split' }
|
159
|
+
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 }
|
102
160
|
end
|
103
|
-
end
|
104
|
-
|
161
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../"
|
3
|
+
require 'tc_helper.rb'
|
4
|
+
|
5
|
+
class TestPane < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
#inverse defaults for booleans
|
8
|
+
@nil_options = { :active_pane => :bottom_left, :state => :frozen, :top_left_cell => 'A2' }
|
9
|
+
@int_0_options = { :x_split => 2, :y_split => 2 }
|
10
|
+
|
11
|
+
@string_options = { :top_left_cell => 'A2' }
|
12
|
+
@integer_options = { :x_split => 2, :y_split => 2 }
|
13
|
+
@symbol_options = { :active_pane => :bottom_left, :state => :frozen }
|
14
|
+
|
15
|
+
@options = @nil_options.merge(@int_0_options)
|
16
|
+
|
17
|
+
@pane = Axlsx::Pane.new(@options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize
|
21
|
+
pane = Axlsx::Pane.new
|
22
|
+
|
23
|
+
@nil_options.each do |key, value|
|
24
|
+
assert_equal(nil, pane.send(key.to_sym), "initialized default #{key} should be nil")
|
25
|
+
assert_equal(value, @pane.send(key.to_sym), "initialized options #{key} should be #{value}")
|
26
|
+
end
|
27
|
+
|
28
|
+
@int_0_options.each do |key, value|
|
29
|
+
assert_equal(0, pane.send(key.to_sym), "initialized default #{key} should be 0")
|
30
|
+
assert_equal(value, @pane.send(key.to_sym), "initialized options #{key} should be #{value}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_string_attribute_validation
|
35
|
+
@string_options.each do |key, value|
|
36
|
+
assert_raise(ArgumentError, "#{key} must be string") { @pane.send("#{key}=".to_sym, :symbol) }
|
37
|
+
assert_nothing_raised { @pane.send("#{key}=".to_sym, "foo") }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_symbol_attribute_validation
|
42
|
+
@symbol_options.each do |key, value|
|
43
|
+
assert_raise(ArgumentError, "#{key} must be symbol") { @pane.send("#{key}=".to_sym, "foo") }
|
44
|
+
assert_nothing_raised { @pane.send("#{key}=".to_sym, value) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_integer_attribute_validation
|
49
|
+
@integer_options.each do |key, value|
|
50
|
+
assert_raise(ArgumentError, "#{key} must be integer") { @pane.send("#{key}=".to_sym, "foo") }
|
51
|
+
assert_nothing_raised { @pane.send("#{key}=".to_sym, value) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_active_pane
|
56
|
+
assert_raise(ArgumentError) { @pane.active_pane = "10" }
|
57
|
+
assert_nothing_raised { @pane.active_pane = :top_left }
|
58
|
+
assert_equal(@pane.active_pane, :top_left)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_state
|
62
|
+
assert_raise(ArgumentError) { @pane.state = "foo" }
|
63
|
+
assert_nothing_raised { @pane.state = :frozen_split }
|
64
|
+
assert_equal(@pane.state, :frozen_split)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_x_split
|
68
|
+
assert_raise(ArgumentError) { @pane.x_split = "foo´" }
|
69
|
+
assert_nothing_raised { @pane.x_split = 200 }
|
70
|
+
assert_equal(@pane.x_split, 200)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_y_split
|
74
|
+
assert_raise(ArgumentError) { @pane.y_split = 'foo' }
|
75
|
+
assert_nothing_raised { @pane.y_split = 300 }
|
76
|
+
assert_equal(@pane.y_split, 300)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_top_left_cell
|
80
|
+
assert_raise(ArgumentError) { @pane.top_left_cell = :cell }
|
81
|
+
assert_nothing_raised { @pane.top_left_cell = "A2" }
|
82
|
+
assert_equal(@pane.top_left_cell, "A2")
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_to_xml
|
86
|
+
doc = Nokogiri::XML.parse(@pane.to_xml_string)
|
87
|
+
assert_equal(1, doc.xpath("//pane[@ySplit=2][@xSplit='2'][@topLeftCell='A2'][@state='frozen'][@activePane='bottomLeft']").size)
|
88
|
+
end
|
89
|
+
def test_to_xml_frozen
|
90
|
+
pane = Axlsx::Pane.new :state => :frozen, :y_split => 2
|
91
|
+
doc = Nokogiri::XML(pane.to_xml_string)
|
92
|
+
assert_equal(1, doc.xpath("//pane[@topLeftCell='A3']").size)
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'tc_helper.rb'
|
3
|
+
|
4
|
+
class TestSelection < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@nil_options = { :active_cell => 'A2', :active_cell_id => 1, :pane => :top_left, :sqref => 'A2' }
|
7
|
+
@options = @nil_options
|
8
|
+
|
9
|
+
@string_options = { :active_cell => 'A2', :sqref => 'A2' }
|
10
|
+
@integer_options = { :active_cell_id => 1 }
|
11
|
+
@symbol_options = { :pane => :top_left }
|
12
|
+
|
13
|
+
@selection = Axlsx::Selection.new(@options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
selection = Axlsx::Selection.new
|
18
|
+
|
19
|
+
@nil_options.each do |key, value|
|
20
|
+
assert_equal(nil, selection.send(key.to_sym), "initialized default #{key} should be nil")
|
21
|
+
assert_equal(value, @selection.send(key.to_sym), "initialized options #{key} should be #{value}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_string_attribute_validation
|
26
|
+
@string_options.each do |key, value|
|
27
|
+
assert_raise(ArgumentError, "#{key} must be string") { @selection.send("#{key}=".to_sym, :symbol) }
|
28
|
+
assert_nothing_raised { @selection.send("#{key}=".to_sym, "foo") }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_symbol_attribute_validation
|
33
|
+
@symbol_options.each do |key, value|
|
34
|
+
assert_raise(ArgumentError, "#{key} must be symbol") { @selection.send("#{key}=".to_sym, "foo") }
|
35
|
+
assert_nothing_raised { @selection.send("#{key}=".to_sym, value) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_integer_attribute_validation
|
40
|
+
@integer_options.each do |key, value|
|
41
|
+
assert_raise(ArgumentError, "#{key} must be integer") { @selection.send("#{key}=".to_sym, "foo") }
|
42
|
+
assert_nothing_raised { @selection.send("#{key}=".to_sym, value) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_active_cell
|
47
|
+
assert_raise(ArgumentError) { @selection.active_cell = :active_cell }
|
48
|
+
assert_nothing_raised { @selection.active_cell = "F5" }
|
49
|
+
assert_equal(@selection.active_cell, "F5")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_active_cell_id
|
53
|
+
assert_raise(ArgumentError) { @selection.active_cell_id = "foo" }
|
54
|
+
assert_nothing_raised { @selection.active_cell_id = 11 }
|
55
|
+
assert_equal(@selection.active_cell_id, 11)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_pane
|
59
|
+
assert_raise(ArgumentError) { @selection.pane = "foo´" }
|
60
|
+
assert_nothing_raised { @selection.pane = :bottom_right }
|
61
|
+
assert_equal(@selection.pane, :bottom_right)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_sqref
|
65
|
+
assert_raise(ArgumentError) { @selection.sqref = :sqref }
|
66
|
+
assert_nothing_raised { @selection.sqref = "G32" }
|
67
|
+
assert_equal(@selection.sqref, "G32")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_to_xml
|
71
|
+
p = Axlsx::Package.new
|
72
|
+
@ws = p.workbook.add_worksheet :name => "sheetview"
|
73
|
+
@ws.sheet_view do |vs|
|
74
|
+
vs.add_selection(:top_left, { :active_cell => 'B2', :sqref => 'B2' })
|
75
|
+
vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
|
76
|
+
vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
|
77
|
+
vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
|
78
|
+
end
|
79
|
+
|
80
|
+
doc = Nokogiri::XML.parse(@ws.to_xml_string)
|
81
|
+
|
82
|
+
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='B2'][@pane='topLeft'][@activeCell='B2']").size)
|
83
|
+
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='B2'][@pane='topLeft'][@activeCell='B2']")
|
84
|
+
|
85
|
+
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I10'][@pane='topRight'][@activeCell='I10']").size)
|
86
|
+
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I10'][@pane='topRight'][@activeCell='I10']")
|
87
|
+
|
88
|
+
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='E55'][@pane='bottomLeft'][@activeCell='E55']").size)
|
89
|
+
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='E55'][@pane='bottomLeft'][@activeCell='E55']")
|
90
|
+
|
91
|
+
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I57'][@pane='bottomRight'][@activeCell='I57']").size)
|
92
|
+
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I57'][@pane='bottomRight'][@activeCell='I57']")
|
93
|
+
end
|
94
|
+
end
|