axlsx 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/README.md +7 -3
  2. data/lib/axlsx.rb +57 -0
  3. data/lib/axlsx/content_type/content_type.rb +23 -0
  4. data/lib/axlsx/content_type/default.rb +37 -0
  5. data/lib/axlsx/content_type/override.rb +37 -0
  6. data/lib/axlsx/doc_props/app.rb +178 -0
  7. data/lib/axlsx/doc_props/core.rb +34 -0
  8. data/lib/axlsx/drawing/axis.rb +90 -0
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +128 -0
  10. data/lib/axlsx/drawing/bar_series.rb +64 -0
  11. data/lib/axlsx/drawing/cat_axis.rb +63 -0
  12. data/lib/axlsx/drawing/cat_axis_data.rb +35 -0
  13. data/lib/axlsx/drawing/chart.rb +179 -0
  14. data/lib/axlsx/drawing/drawing.rb +137 -0
  15. data/lib/axlsx/drawing/graphic_frame.rb +52 -0
  16. data/lib/axlsx/drawing/line_3D_chart.rb +106 -0
  17. data/lib/axlsx/drawing/line_series.rb +46 -0
  18. data/lib/axlsx/drawing/marker.rb +61 -0
  19. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  20. data/lib/axlsx/drawing/pic.rb +153 -0
  21. data/lib/axlsx/drawing/picture_locking.rb +72 -0
  22. data/lib/axlsx/drawing/picture_locking.rb~ +36 -0
  23. data/lib/axlsx/drawing/pie_3D_chart.rb +41 -0
  24. data/lib/axlsx/drawing/pie_series.rb +56 -0
  25. data/lib/axlsx/drawing/scaling.rb +59 -0
  26. data/lib/axlsx/drawing/ser_axis.rb +45 -0
  27. data/lib/axlsx/drawing/series.rb +71 -0
  28. data/lib/axlsx/drawing/series_title.rb +22 -0
  29. data/lib/axlsx/drawing/title.rb +61 -0
  30. data/lib/axlsx/drawing/two_cell_anchor.rb +76 -0
  31. data/lib/axlsx/drawing/val_axis.rb +34 -0
  32. data/lib/axlsx/drawing/val_axis_data.rb +28 -0
  33. data/lib/axlsx/drawing/view_3D.rb +85 -0
  34. data/lib/axlsx/package.rb +215 -0
  35. data/lib/axlsx/rels/relationship.rb +44 -0
  36. data/lib/axlsx/rels/relationships.rb +25 -0
  37. data/lib/axlsx/stylesheet/border.rb +57 -0
  38. data/lib/axlsx/stylesheet/border_pr.rb +68 -0
  39. data/lib/axlsx/stylesheet/cell_alignment.rb +105 -0
  40. data/lib/axlsx/stylesheet/cell_protection.rb +36 -0
  41. data/lib/axlsx/stylesheet/cell_style.rb +65 -0
  42. data/lib/axlsx/stylesheet/color.rb +69 -0
  43. data/lib/axlsx/stylesheet/fill.rb +32 -0
  44. data/lib/axlsx/stylesheet/font.rb +139 -0
  45. data/lib/axlsx/stylesheet/gradient_fill.rb +76 -0
  46. data/lib/axlsx/stylesheet/gradient_stop.rb +33 -0
  47. data/lib/axlsx/stylesheet/num_fmt.rb +63 -0
  48. data/lib/axlsx/stylesheet/pattern_fill.rb +66 -0
  49. data/lib/axlsx/stylesheet/styles.rb +298 -0
  50. data/lib/axlsx/stylesheet/table_style.rb +47 -0
  51. data/lib/axlsx/stylesheet/table_style_element.rb +71 -0
  52. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  53. data/lib/axlsx/stylesheet/xf.rb +138 -0
  54. data/lib/axlsx/util/constants.rb +220 -0
  55. data/lib/axlsx/util/parser.rb +43 -0
  56. data/lib/axlsx/util/parser.rb~ +6 -0
  57. data/lib/axlsx/util/simple_typed_list.rb +160 -0
  58. data/lib/axlsx/util/validators.rb +132 -0
  59. data/lib/axlsx/version.rb +4 -0
  60. data/lib/axlsx/workbook/#workbook.rb# +165 -0
  61. data/lib/axlsx/workbook/workbook.rb +160 -0
  62. data/lib/axlsx/workbook/worksheet/cell.rb +337 -0
  63. data/lib/axlsx/workbook/worksheet/row.rb +107 -0
  64. data/lib/axlsx/workbook/worksheet/worksheet.rb +279 -0
  65. metadata +93 -141
  66. data/examples/follow_20111202.xlsx +0 -0
  67. data/test/content_type/tc_content_type.rb +0 -81
  68. data/test/content_type/tc_default.rb +0 -40
  69. data/test/content_type/tc_override.rb +0 -40
  70. data/test/doc_props/tc_app.rb +0 -19
  71. data/test/doc_props/tc_core.rb +0 -34
  72. data/test/drawing/tc_axis.rb +0 -40
  73. data/test/drawing/tc_bar_3D_chart.rb +0 -66
  74. data/test/drawing/tc_bar_series.rb +0 -34
  75. data/test/drawing/tc_cat_axis.rb +0 -32
  76. data/test/drawing/tc_cat_axis_data.rb +0 -18
  77. data/test/drawing/tc_chart.rb +0 -73
  78. data/test/drawing/tc_drawing.rb +0 -80
  79. data/test/drawing/tc_graphic_frame.rb +0 -26
  80. data/test/drawing/tc_line_3d_chart.rb +0 -48
  81. data/test/drawing/tc_line_series.rb +0 -27
  82. data/test/drawing/tc_marker.rb +0 -45
  83. data/test/drawing/tc_one_cell_anchor.rb +0 -67
  84. data/test/drawing/tc_pic.rb +0 -71
  85. data/test/drawing/tc_picture_locking.rb +0 -73
  86. data/test/drawing/tc_pie_3D_chart.rb +0 -33
  87. data/test/drawing/tc_pie_series.rb +0 -35
  88. data/test/drawing/tc_scaling.rb +0 -37
  89. data/test/drawing/tc_ser_axis.rb +0 -31
  90. data/test/drawing/tc_series.rb +0 -24
  91. data/test/drawing/tc_series_title.rb +0 -34
  92. data/test/drawing/tc_title.rb +0 -34
  93. data/test/drawing/tc_two_cell_anchor.rb +0 -38
  94. data/test/drawing/tc_val_axis.rb +0 -25
  95. data/test/drawing/tc_val_axis_data.rb +0 -18
  96. data/test/drawing/tc_view_3D.rb +0 -55
  97. data/test/rels/tc_relationship.rb +0 -16
  98. data/test/rels/tc_relationships.rb +0 -27
  99. data/test/stylesheet/tc_border.rb +0 -38
  100. data/test/stylesheet/tc_border_pr.rb +0 -33
  101. data/test/stylesheet/tc_cell_alignment.rb +0 -77
  102. data/test/stylesheet/tc_cell_protection.rb +0 -30
  103. data/test/stylesheet/tc_cell_style.rb +0 -58
  104. data/test/stylesheet/tc_color.rb +0 -38
  105. data/test/stylesheet/tc_fill.rb +0 -19
  106. data/test/stylesheet/tc_font.rb +0 -114
  107. data/test/stylesheet/tc_gradient_fill.rb +0 -65
  108. data/test/stylesheet/tc_gradient_stop.rb +0 -32
  109. data/test/stylesheet/tc_num_fmt.rb +0 -31
  110. data/test/stylesheet/tc_pattern_fill.rb +0 -38
  111. data/test/stylesheet/tc_styles.rb +0 -52
  112. data/test/stylesheet/tc_table_style.rb +0 -37
  113. data/test/stylesheet/tc_table_style_element.rb +0 -37
  114. data/test/stylesheet/tc_table_styles.rb +0 -30
  115. data/test/stylesheet/tc_xf.rb +0 -121
  116. data/test/tc_package.rb +0 -68
  117. data/test/util/tc_simple_typed_list.rb +0 -66
  118. data/test/util/tc_validators.rb +0 -76
  119. data/test/workbook/tc_workbook.rb +0 -60
  120. data/test/workbook/worksheet/tc_cell.rb +0 -179
  121. data/test/workbook/worksheet/tc_row.rb +0 -36
  122. data/test/workbook/worksheet/tc_worksheet.rb +0 -138
@@ -1,35 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestPieSeries < 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::Pie3DChart, :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.text, "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.explosion, nil, "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
-
27
- end
28
-
29
- def test_explosion
30
- assert_raise(ArgumentError, "require valid explosion") { @series.explosion = :lots }
31
- assert_nothing_raised("allow valid explosion") { @series.explosion = 20 }
32
- assert(@series.explosion == 20)
33
- end
34
-
35
- end
@@ -1,37 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestScaling < Test::Unit::TestCase
5
- def setup
6
- @scaling = Axlsx::Scaling.new
7
- end
8
-
9
- def teardown
10
- end
11
-
12
- def test_initialization
13
- assert(@scaling.orientation == :minMax)
14
- end
15
-
16
- def test_logBase
17
- assert_raise(ArgumentError) { @scaling.logBase = 1}
18
- assert_nothing_raised {@scaling.logBase = 10}
19
- end
20
-
21
- def test_orientation
22
- assert_raise(ArgumentError) { @scaling.orientation = "1"}
23
- assert_nothing_raised {@scaling.orientation = :maxMin}
24
- end
25
-
26
-
27
- def test_max
28
- assert_raise(ArgumentError) { @scaling.max = 1}
29
- assert_nothing_raised {@scaling.max = 10.5}
30
- end
31
-
32
- def test_min
33
- assert_raise(ArgumentError) { @scaling.min = 1}
34
- assert_nothing_raised {@scaling.min = 10.5}
35
- end
36
-
37
- end
@@ -1,31 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestSerAxis < Test::Unit::TestCase
5
- def setup
6
- @axis = Axlsx::SerAxis.new 12345, 54321
7
- end
8
- def teardown
9
- end
10
-
11
- def test_options
12
- a = Axlsx::SerAxis.new 12345, 54321, :tickLblSkip => 9, :tickMarkSkip => 7
13
- assert_equal(a.tickLblSkip, 9)
14
- assert_equal(a.tickMarkSkip, 7)
15
- end
16
-
17
-
18
- def test_tickLblSkip
19
- assert_raise(ArgumentError, "requires valid tickLblSkip") { @axis.tickLblSkip = -1 }
20
- assert_nothing_raised("accepts valid tickLblSkip") { @axis.tickLblSkip = 1 }
21
- assert_equal(@axis.tickLblSkip, 1)
22
- end
23
-
24
-
25
- def test_tickMarkSkip
26
- assert_raise(ArgumentError, "requires valid tickMarkSkip") { @axis.tickMarkSkip = :my_eyes }
27
- assert_nothing_raised("accepts valid tickMarkSkip") { @axis.tickMarkSkip = 2 }
28
- assert_equal(@axis.tickMarkSkip, 2)
29
- end
30
-
31
- end
@@ -1,24 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestSeries < 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::Chart, :title => "fishery"
10
- @series = chart.add_series :title=>"bob"
11
- end
12
-
13
- def test_initialize
14
- assert_equal(@series.title.text, "bob", "series title has been applied")
15
- assert_equal(@series.order, @series.index, "order is index by default")
16
- assert_equal(@series.index, @series.chart.series.index(@series), "index is applied")
17
- end
18
-
19
- def test_order
20
- @series.order = 2
21
- assert_equal(@series.order, 2)
22
- end
23
-
24
- end
@@ -1,34 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestSeriesTitle < Test::Unit::TestCase
5
- def setup
6
- @p = Axlsx::Package.new
7
- ws = @p.workbook.add_worksheet
8
- @row = ws.add_row ["one", 1, Time.now]
9
- @title = Axlsx::SeriesTitle.new
10
- @chart = ws.add_chart Axlsx::Bar3DChart
11
- end
12
-
13
- def teardown
14
- end
15
-
16
- def test_initialization
17
- assert(@title.text == "")
18
- assert(@title.cell == nil)
19
- end
20
-
21
- def test_text
22
- assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
23
- @title.cell = @row.cells.first
24
- @title.text = "bob"
25
- assert(@title.cell == nil, "setting title with text clears the cell")
26
- end
27
-
28
- def test_cell
29
- assert_raise(ArgumentError, "cell must be a Cell") { @title.cell = "123" }
30
- @title.cell = @row.cells.first
31
- assert(@title.text == "one")
32
- end
33
-
34
- end
@@ -1,34 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestTitle < Test::Unit::TestCase
5
- def setup
6
- @p = Axlsx::Package.new
7
- ws = @p.workbook.add_worksheet
8
- @row = ws.add_row ["one", 1, Time.now]
9
- @title = Axlsx::Title.new
10
- @chart = ws.add_chart Axlsx::Bar3DChart
11
- end
12
-
13
- def teardown
14
- end
15
-
16
- def test_initialization
17
- assert(@title.text == "")
18
- assert(@title.cell == nil)
19
- end
20
-
21
- def test_text
22
- assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
23
- @title.cell = @row.cells.first
24
- @title.text = "bob"
25
- assert(@title.cell == nil, "setting title with text clears the cell")
26
- end
27
-
28
- def test_cell
29
- assert_raise(ArgumentError, "cell must be a Cell") { @title.cell = "123" }
30
- @title.cell = @row.cells.first
31
- assert(@title.text == "one")
32
- end
33
-
34
- end
@@ -1,38 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestTwoCellAnchor < Test::Unit::TestCase
5
-
6
- def setup
7
- p = Axlsx::Package.new
8
- @ws = p.workbook.add_worksheet
9
- row = @ws.add_row ["one", 1, Time.now]
10
- title = Axlsx::Title.new
11
- chart = @ws.add_chart Axlsx::Bar3DChart
12
- @anchor = chart.graphic_frame.anchor
13
- end
14
-
15
- def teardown
16
- end
17
-
18
- def test_initialization
19
- assert(@anchor.from.col == 0)
20
- assert(@anchor.from.row == 0)
21
- assert(@anchor.to.col == 5)
22
- assert(@anchor.to.row == 10)
23
- end
24
-
25
-
26
- def test_options
27
- assert_raise(ArgumentError, 'invalid start_at') { @ws.add_chart Axlsx::Chart, :start_at=>[1] }
28
- assert_raise(ArgumentError, 'invalid end_at') { @ws.add_chart Axlsx::Chart, :start_at=>[1,2], :end_at => ["a", 4] }
29
- # this is actually raised in the graphic frame
30
- assert_raise(ArgumentError, 'invalid Chart') { @ws.add_chart Axlsx::TwoCellAnchor }
31
- a = @ws.add_chart Axlsx::Chart, :start_at => [15, 35], :end_at => [90, 45]
32
- assert_equal(a.graphic_frame.anchor.from.col, 15)
33
- assert_equal(a.graphic_frame.anchor.from.row, 35)
34
- assert_equal(a.graphic_frame.anchor.to.col, 90)
35
- assert_equal(a.graphic_frame.anchor.to.row, 45)
36
- end
37
-
38
- end
@@ -1,25 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestValAxis < Test::Unit::TestCase
5
- def setup
6
- @axis = Axlsx::ValAxis.new 12345, 54321
7
- end
8
- def teardown
9
- end
10
-
11
- def test_initialization
12
- assert_equal(@axis.crossBetween, :between, "axis crossBetween default incorrect")
13
- end
14
-
15
- def test_options
16
- a = Axlsx::ValAxis.new 2345, 4321, :crossBetween => :midCat
17
- assert_equal(a.crossBetween, :midCat)
18
- end
19
-
20
- def test_crossBetween
21
- assert_raise(ArgumentError, "requires valid crossBetween") { @axis.crossBetween = :my_eyes }
22
- assert_nothing_raised("accepts valid crossBetween") { @axis.crossBetween = :midCat }
23
- end
24
-
25
- end
@@ -1,18 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestValAxisData < Test::Unit::TestCase
5
-
6
- def setup
7
- p = Axlsx::Package.new
8
- @ws = p.workbook.add_worksheet
9
- chart = @ws.drawing.add_chart Axlsx::Line3DChart
10
- @series = chart.add_series :data=>[0,1,2]
11
- end
12
-
13
- def test_initialize
14
- assert(@series.data.is_a?Axlsx::SimpleTypedList)
15
- assert_equal(@series.data, [0,1,2])
16
- end
17
-
18
- end
@@ -1,55 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestView3D < Test::Unit::TestCase
5
- def setup
6
- @view = Axlsx::View3D.new
7
- end
8
-
9
- def teardown
10
- end
11
-
12
- def test_options
13
- v = Axlsx::View3D.new :rotX => 10, :rotY => 5, :hPercent => "30%", :depthPercent => "45%", :rAngAx => false, :perspective => 10
14
- assert_equal(v.rotX, 10)
15
- assert_equal(v.rotY, 5)
16
- assert_equal(v.hPercent, "30%")
17
- assert_equal(v.depthPercent, "45%")
18
- assert_equal(v.rAngAx, false)
19
- assert_equal(v.perspective, 10)
20
- end
21
-
22
- def test_rotX
23
- assert_raise(ArgumentError) {@view.rotX = "bob"}
24
- assert_nothing_raised {@view.rotX = -90}
25
- end
26
-
27
- def test_rotY
28
- assert_raise(ArgumentError) {@view.rotY = "bob"}
29
- assert_nothing_raised {@view.rotY = 90}
30
- end
31
-
32
- def test_hPercent
33
- assert_raise(ArgumentError) {@view.hPercent = "bob"}
34
- assert_nothing_raised {@view.hPercent = "500%"}
35
- end
36
-
37
- def test_depthPercent
38
- assert_raise(ArgumentError) {@view.depthPercent = "bob"}
39
- assert_nothing_raised {@view.depthPercent = "20%"}
40
- end
41
-
42
-
43
- def test_rAngAx
44
- assert_raise(ArgumentError) {@view.rAngAx = "bob"}
45
- assert_nothing_raised {@view.rAngAx = true}
46
- end
47
-
48
- def test_perspective
49
- assert_raise(ArgumentError) {@view.perspective = "bob"}
50
- assert_nothing_raised {@view.perspective = 30}
51
- end
52
-
53
-
54
-
55
- end
@@ -1,16 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestRelationships < Test::Unit::TestCase
5
- def setup
6
- end
7
-
8
- def teardown
9
- end
10
-
11
- def test_type
12
- assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target' }
13
- assert_nothing_raised { Axlsx::Relationship.new Axlsx::WORKSHEET_R, 'target' }
14
- end
15
-
16
- end
@@ -1,27 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestRelationships < Test::Unit::TestCase
5
-
6
- def test_valid_document
7
- @rels = Axlsx::Relationships.new
8
- schema = Nokogiri::XML::Schema(File.open(Axlsx::RELS_XSD))
9
- doc = Nokogiri::XML(@rels.to_xml)
10
- errors = []
11
- schema.validate(doc).each do |error|
12
- puts error.message
13
- errors << error
14
- end
15
-
16
- @rels << Axlsx::Relationship.new(Axlsx::WORKSHEET_R, "bar")
17
- doc = Nokogiri::XML(@rels.to_xml)
18
- errors = []
19
- schema.validate(doc).each do |error|
20
- puts error.message
21
- errors << error
22
- end
23
-
24
- assert(errors.size == 0)
25
- end
26
-
27
- end
@@ -1,38 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestBorder < Test::Unit::TestCase
5
- def setup
6
- @b = Axlsx::Border.new
7
- end
8
- def teardown
9
- end
10
- def test_initialiation
11
- assert_equal(@b.diagonalUp, nil)
12
- assert_equal(@b.diagonalDown, nil)
13
- assert_equal(@b.outline, nil)
14
- assert(@b.prs.is_a?(Axlsx::SimpleTypedList))
15
- end
16
-
17
- def test_diagonalUp
18
- assert_raise(ArgumentError) { @b.diagonalUp = :red }
19
- assert_nothing_raised { @b.diagonalUp = true }
20
- assert_equal(@b.diagonalUp, true )
21
- end
22
-
23
- def test_diagonalDown
24
- assert_raise(ArgumentError) { @b.diagonalDown = :red }
25
- assert_nothing_raised { @b.diagonalDown = true }
26
- assert_equal(@b.diagonalDown, true )
27
- end
28
-
29
- def test_outline
30
- assert_raise(ArgumentError) { @b.outline = :red }
31
- assert_nothing_raised { @b.outline = true }
32
- assert_equal(@b.outline, true )
33
- end
34
-
35
- def test_prs
36
- assert_nothing_raised { @b.prs << Axlsx::BorderPr.new(:name=>:top, :style=>:thin, :color => Axlsx::Color.new(:rgb=>"FF0000FF")) }
37
- end
38
- end
@@ -1,33 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestBorderPr < Test::Unit::TestCase
5
- def setup
6
- @bpr = Axlsx::BorderPr.new
7
- end
8
- def teardown
9
- end
10
- def test_initialiation
11
- assert_equal(@bpr.color, nil)
12
- assert_equal(@bpr.style, nil)
13
- assert_equal(@bpr.name, nil)
14
- end
15
-
16
- def test_color
17
- assert_raise(ArgumentError) { @bpr.color = :red }
18
- assert_nothing_raised { @bpr.color = Axlsx::Color.new :rgb=>"FF000000" }
19
- assert(@bpr.color.is_a?(Axlsx::Color))
20
- end
21
-
22
- def test_style
23
- assert_raise(ArgumentError) { @bpr.style = :red }
24
- assert_nothing_raised { @bpr.style = :thin }
25
- assert_equal(@bpr.style, :thin)
26
- end
27
-
28
- def test_name
29
- assert_raise(ArgumentError) { @bpr.name = :red }
30
- assert_nothing_raised { @bpr.name = :top }
31
- assert_equal(@bpr.name, :top)
32
- end
33
- end