axlsx 1.0.15 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -195,6 +195,7 @@ module Axlsx
195
195
  offset = options.delete(:row_offset) || 0
196
196
  @rows[(offset..-1)].each do |r|
197
197
  cells = r.cells[index]
198
+ next unless cells
198
199
  if cells.is_a?(Array)
199
200
  cells.each { |c| c.style = style }
200
201
  else
@@ -255,7 +256,7 @@ module Axlsx
255
256
  xml.drawing :"r:id"=>"rId1" if @drawing
256
257
  }
257
258
  end
258
- builder.to_xml
259
+ builder.to_xml(:save_with => 0)
259
260
  end
260
261
 
261
262
  # The worksheet relationships. This is managed automatically by the worksheet
@@ -0,0 +1,70 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestHyperlink < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ ws = @p.workbook.add_worksheet
9
+ @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
10
+ @image = ws.add_image :image_src => @test_img, :hyperlink => "http://axlsx.blogspot.com"
11
+ @hyperlink = @image.hyperlink
12
+ end
13
+
14
+ def teardown
15
+ end
16
+
17
+
18
+ def test_href
19
+ assert_nothing_raised { @hyperlink.href = "http://axlsx.blogspot.com" }
20
+ assert_equal(@hyperlink.href, "http://axlsx.blogspot.com")
21
+ end
22
+
23
+ def test_invalidUrl
24
+ assert_nothing_raised { @hyperlink.invalidUrl = "http://axlsx.blogspot.com" }
25
+ assert_equal(@hyperlink.invalidUrl, "http://axlsx.blogspot.com")
26
+ end
27
+
28
+ def test_tgtFrame
29
+ assert_nothing_raised { @hyperlink.tgtFrame = "http://axlsx.blogspot.com" }
30
+ assert_equal(@hyperlink.tgtFrame, "http://axlsx.blogspot.com")
31
+ end
32
+
33
+ def test_tooltip
34
+ assert_nothing_raised { @hyperlink.tooltip = "http://axlsx.blogspot.com" }
35
+ assert_equal(@hyperlink.tooltip, "http://axlsx.blogspot.com")
36
+ end
37
+
38
+ def test_invalidUrl
39
+ assert_nothing_raised { @hyperlink.invalidUrl = "http://axlsx.blogspot.com" }
40
+ assert_equal(@hyperlink.invalidUrl, "http://axlsx.blogspot.com")
41
+ end
42
+
43
+ def test_action
44
+ assert_nothing_raised { @hyperlink.action = "flee" }
45
+ assert_equal(@hyperlink.action, "flee")
46
+ end
47
+
48
+ def test_endSnd
49
+ assert_nothing_raised { @hyperlink.endSnd = "true" }
50
+ assert_raise(ArgumentError) {@hyperlink.endSnd = "bob"}
51
+ assert_equal(@hyperlink.endSnd, "true")
52
+ end
53
+
54
+ def test_highlightClick
55
+ assert_nothing_raised { @hyperlink.highlightClick = false }
56
+ assert_raise(ArgumentError) {@hyperlink.highlightClick = "bob"}
57
+ assert_equal(@hyperlink.highlightClick, false )
58
+ end
59
+
60
+ def test_id
61
+ assert_equal(@hyperlink.send(:id), 2)
62
+ end
63
+
64
+ def test_history
65
+ assert_nothing_raised { @hyperlink.history = false }
66
+ assert_raise(ArgumentError) {@hyperlink.history = "bob"}
67
+ assert_equal(@hyperlink.history, false )
68
+ end
69
+
70
+ end
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestPic < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ ws = @p.workbook.add_worksheet
9
+ @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
10
+ @image = ws.add_image :image_src => @test_img
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_initialization
17
+ assert_equal(@p.workbook.images.first, @image)
18
+ assert_equal(@image.image_src, @test_img)
19
+ end
20
+
21
+ def test_name
22
+ assert_raise(ArgumentError) { @image.name = 49 }
23
+ assert_nothing_raised { @image.name = "unknown" }
24
+ assert_equal(@image.name, "unknown")
25
+ end
26
+
27
+ def test_start_at
28
+ assert_raise(ArgumentError) { @image.start_at "a", 1 }
29
+ assert_nothing_raised { @image.start_at 6, 7 }
30
+ assert_equal(@image.anchor.from.col, 6)
31
+ assert_equal(@image.anchor.from.row, 7)
32
+ end
33
+
34
+ def test_width
35
+ assert_raise(ArgumentError) { @image.width = "a" }
36
+ assert_nothing_raised { @image.width = 600 }
37
+ assert_equal(@image.width, 600)
38
+ end
39
+
40
+ def test_height
41
+ assert_raise(ArgumentError) { @image.height = "a" }
42
+ assert_nothing_raised { @image.height = 600 }
43
+ assert_equal(600, @image.height)
44
+ end
45
+
46
+ def test_image_src
47
+ assert_raise(ArgumentError) { @image.image_src = 49 }
48
+ assert_raise(ArgumentError) { @image.image_src = 'Unknown' }
49
+ assert_raise(ArgumentError) { @image.image_src = __FILE__ }
50
+ assert_nothing_raised { @image.image_src = @test_img }
51
+ assert_equal(@image.image_src, @test_img)
52
+ end
53
+
54
+ def test_descr
55
+ assert_raise(ArgumentError) { @image.descr = 49 }
56
+ assert_nothing_raised { @image.descr = "test" }
57
+ assert_equal(@image.descr, "test")
58
+ end
59
+
60
+ def test_to_xml
61
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
62
+ doc = Nokogiri::XML(@image.anchor.drawing.to_xml)
63
+ errors = []
64
+ schema.validate(doc).each do |error|
65
+ errors.push error
66
+ puts error.message
67
+ end
68
+ assert(errors.empty?, "error free validation")
69
+ end
70
+
71
+ end
@@ -17,6 +17,12 @@ class TestPic < Test::Unit::TestCase
17
17
  assert_equal(@p.workbook.images.first, @image)
18
18
  assert_equal(@image.image_src, @test_img)
19
19
  end
20
+
21
+ def test_hyperlink
22
+ assert_equal(@image.hyperlink, nil)
23
+ @image.hyperlink = "http://axlsx.blogspot.com"
24
+ assert_equal(@image.hyperlink.href, "http://axlsx.blogspot.com")
25
+ end
20
26
 
21
27
  def test_name
22
28
  assert_raise(ArgumentError) { @image.name = 49 }
@@ -13,4 +13,9 @@ class TestRelationships < Test::Unit::TestCase
13
13
  assert_nothing_raised { Axlsx::Relationship.new Axlsx::WORKSHEET_R, 'target' }
14
14
  end
15
15
 
16
+ def test_target_mode
17
+ assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target', :target_mode => "FISH" }
18
+ assert_nothing_raised { Axlsx::Relationship.new( Axlsx::WORKSHEET_R, 'target', :target_mode => :External) }
19
+ end
20
+
16
21
  end
@@ -69,6 +69,13 @@ class TestWorksheet < Test::Unit::TestCase
69
69
  assert_equal(@ws.rows.first.cells[0].style, 0)
70
70
  end
71
71
 
72
+ def test_col_style_with_empty_column
73
+ @ws.add_row [1,2,3,4]
74
+ @ws.add_row [1]
75
+ @ws.add_row [1,2,3,4]
76
+ assert_nothing_raised {@ws.col_style(1, 1)}
77
+ end
78
+
72
79
  def test_cols
73
80
  @ws.add_row [1,2,3,4]
74
81
  @ws.add_row [1,2,3,4]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-06 00:00:00.000000000 Z
12
+ date: 2012-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2155999180 !ruby/object:Gem::Requirement
16
+ requirement: &2152839280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2155999180
24
+ version_requirements: *2152839280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2155993560 !ruby/object:Gem::Requirement
27
+ requirement: &2152838780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.9
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2155993560
35
+ version_requirements: *2152838780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &2153146240 !ruby/object:Gem::Requirement
38
+ requirement: &2152838320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.6.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153146240
46
+ version_requirements: *2152838320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rmagick
49
- requirement: &2153145780 !ruby/object:Gem::Requirement
49
+ requirement: &2152837860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.12.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2153145780
57
+ version_requirements: *2152837860
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rubyzip
60
- requirement: &2153145320 !ruby/object:Gem::Requirement
60
+ requirement: &2152837400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0.9'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2153145320
68
+ version_requirements: *2152837400
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &2153144780 !ruby/object:Gem::Requirement
71
+ requirement: &2152836860 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.9'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153144780
79
+ version_requirements: *2152836860
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &2153144400 !ruby/object:Gem::Requirement
82
+ requirement: &2152836480 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153144400
90
+ version_requirements: *2152836480
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: yard
93
- requirement: &2153143940 !ruby/object:Gem::Requirement
93
+ requirement: &2152836020 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153143940
101
+ version_requirements: *2152836020
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rdiscount
104
- requirement: &2153143520 !ruby/object:Gem::Requirement
104
+ requirement: &2152835600 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2153143520
112
+ version_requirements: *2152835600
113
113
  description: ! ' xlsx generation with charts, images, automated column width, customizable
114
114
  styles and full schema validation. Axlsx excels at helping you generate beautiful
115
115
  Office Open XML Spreadsheet documents without having to understand the entire ECMA
@@ -136,6 +136,9 @@ files:
136
136
  - lib/axlsx/drawing/chart.rb
137
137
  - lib/axlsx/drawing/drawing.rb
138
138
  - lib/axlsx/drawing/graphic_frame.rb
139
+ - lib/axlsx/drawing/hlink_click.rb~
140
+ - lib/axlsx/drawing/hyperlink.rb
141
+ - lib/axlsx/drawing/hyperlink.rb~
139
142
  - lib/axlsx/drawing/line_3D_chart.rb
140
143
  - lib/axlsx/drawing/line_series.rb
141
144
  - lib/axlsx/drawing/marker.rb
@@ -254,14 +257,14 @@ files:
254
257
  - test/drawing/tc_chart.rb
255
258
  - test/drawing/tc_drawing.rb
256
259
  - test/drawing/tc_graphic_frame.rb
260
+ - test/drawing/tc_hyperlink.rb
261
+ - test/drawing/tc_hyperlink.rb~
257
262
  - test/drawing/tc_line_3d_chart.rb
258
263
  - test/drawing/tc_line_series.rb
259
- - test/drawing/tc_line_series.tc~
260
264
  - test/drawing/tc_marker.rb
261
265
  - test/drawing/tc_one_cell_anchor.rb
262
266
  - test/drawing/tc_pic.rb
263
267
  - test/drawing/tc_picture_locking.rb
264
- - test/drawing/tc_picture_locking.rb~
265
268
  - test/drawing/tc_pie_3D_chart.rb
266
269
  - test/drawing/tc_pie_series.rb
267
270
  - test/drawing/tc_scaling.rb
@@ -337,14 +340,14 @@ test_files:
337
340
  - test/drawing/tc_chart.rb
338
341
  - test/drawing/tc_drawing.rb
339
342
  - test/drawing/tc_graphic_frame.rb
343
+ - test/drawing/tc_hyperlink.rb
344
+ - test/drawing/tc_hyperlink.rb~
340
345
  - test/drawing/tc_line_3d_chart.rb
341
346
  - test/drawing/tc_line_series.rb
342
- - test/drawing/tc_line_series.tc~
343
347
  - test/drawing/tc_marker.rb
344
348
  - test/drawing/tc_one_cell_anchor.rb
345
349
  - test/drawing/tc_pic.rb
346
350
  - test/drawing/tc_picture_locking.rb
347
- - test/drawing/tc_picture_locking.rb~
348
351
  - test/drawing/tc_pie_3D_chart.rb
349
352
  - test/drawing/tc_pie_series.rb
350
353
  - test/drawing/tc_scaling.rb
@@ -1,34 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestLineSeries < Test::Unit::TestCase
5
-
6
- def setup
7
- p = Axlsx::Package.new
8
- @ws = p.workbook.add_worksheet :name=>"hmmm"
9
- chart = @ws.drawing.add_chart Axlsx::Bar3DChart, :title => "fishery"
10
- @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
11
- end
12
-
13
- def test_initialize
14
- assert_equal(@series.title, "bob", "series title has been applied")
15
- assert_equal(@series.data, [0,1,2], "data option applied")
16
- assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
17
- assert_equal(@series.shape, :box, "series shape has been applied")
18
- end
19
-
20
- def test_data
21
- assert_equal(@series.data, [0,1,2])
22
- end
23
-
24
- def test_labels
25
- assert_equal(@series.labels, ["zero", "one", "two"])
26
- end
27
-
28
- def test_shape
29
- assert_raise(ArgumentError, "require valid shape") { @series.shape = :teardropt }
30
- assert_nothing_raised("allow valid shape") { @series.shape = :cone }
31
- assert(@series.shape == :cone)
32
- end
33
-
34
- end
@@ -1,77 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestPictureLocking < Test::Unit::TestCase
5
- def setup
6
- @item = Axlsx::CellAlignment.new
7
- end
8
- def teardown
9
- end
10
- def test_initialiation
11
- assert_equal(@item.horizontal, nil)
12
- assert_equal(@item.vertical, nil)
13
- assert_equal(@item.textRotation, nil)
14
- assert_equal(@item.wrapText, nil)
15
- assert_equal(@item.indent, nil)
16
- assert_equal(@item.relativeIndent, nil)
17
- assert_equal(@item.justifyLastLine, nil)
18
- assert_equal(@item.shrinkToFit, nil)
19
- assert_equal(@item.readingOrder, nil)
20
-
21
- end
22
-
23
- def test_horizontal
24
- assert_raise(ArgumentError) { @item.horizontal = :red }
25
- assert_nothing_raised { @item.horizontal = :left }
26
- assert_equal(@item.horizontal, :left )
27
- end
28
-
29
- def test_vertical
30
- assert_raise(ArgumentError) { @item.vertical = :red }
31
- assert_nothing_raised { @item.vertical = :top }
32
- assert_equal(@item.vertical, :top )
33
- end
34
-
35
- def test_textRotation
36
- assert_raise(ArgumentError) { @item.textRotation = -1 }
37
- assert_nothing_raised { @item.textRotation = 5 }
38
- assert_equal(@item.textRotation, 5 )
39
- end
40
-
41
- def test_wrapText
42
- assert_raise(ArgumentError) { @item.wrapText = -1 }
43
- assert_nothing_raised { @item.wrapText = false }
44
- assert_equal(@item.wrapText, false )
45
- end
46
-
47
- def test_indent
48
- assert_raise(ArgumentError) { @item.indent = -1 }
49
- assert_nothing_raised { @item.indent = 5 }
50
- assert_equal(@item.indent, 5 )
51
- end
52
-
53
- def test_relativeIndent
54
- assert_raise(ArgumentError) { @item.relativeIndent = :symbol }
55
- assert_nothing_raised { @item.relativeIndent = 5 }
56
- assert_equal(@item.relativeIndent, 5 )
57
- end
58
-
59
- def test_justifyLastLine
60
- assert_raise(ArgumentError) { @item.justifyLastLine = -1 }
61
- assert_nothing_raised { @item.justifyLastLine = true }
62
- assert_equal(@item.justifyLastLine, true )
63
- end
64
-
65
- def test_shrinkToFit
66
- assert_raise(ArgumentError) { @item.shrinkToFit = -1 }
67
- assert_nothing_raised { @item.shrinkToFit = true }
68
- assert_equal(@item.shrinkToFit, true )
69
- end
70
-
71
- def test_readingOrder
72
- assert_raise(ArgumentError) { @item.readingOrder = -1 }
73
- assert_nothing_raised { @item.readingOrder = 2 }
74
- assert_equal(@item.readingOrder, 2 )
75
- end
76
-
77
- end