caxlsx 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +41 -33
- data/Rakefile +9 -11
- data/examples/auto_filter.rb +10 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
- data/examples/data_validation.rb +57 -40
- data/examples/example.rb +115 -7
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/split.rb +16 -0
- data/lib/axlsx.rb +34 -15
- data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +5 -5
- data/lib/axlsx/drawing/area_chart.rb +99 -0
- data/lib/axlsx/drawing/area_series.rb +110 -0
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +12 -9
- data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
- data/lib/axlsx/drawing/bar_chart.rb +143 -0
- data/lib/axlsx/drawing/bar_series.rb +9 -9
- data/lib/axlsx/drawing/bubble_chart.rb +59 -0
- data/lib/axlsx/drawing/bubble_series.rb +63 -0
- data/lib/axlsx/drawing/cat_axis.rb +5 -5
- data/lib/axlsx/drawing/chart.rb +52 -8
- data/lib/axlsx/drawing/d_lbls.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +6 -1
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +1 -3
- data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
- data/lib/axlsx/drawing/line_chart.rb +10 -10
- data/lib/axlsx/drawing/line_series.rb +32 -3
- data/lib/axlsx/drawing/marker.rb +1 -1
- data/lib/axlsx/drawing/num_data.rb +4 -4
- data/lib/axlsx/drawing/num_data_source.rb +6 -6
- data/lib/axlsx/drawing/num_val.rb +3 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
- data/lib/axlsx/drawing/pic.rb +25 -19
- data/lib/axlsx/drawing/picture_locking.rb +1 -3
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
- data/lib/axlsx/drawing/pie_series.rb +6 -6
- data/lib/axlsx/drawing/scaling.rb +6 -6
- data/lib/axlsx/drawing/scatter_chart.rb +10 -10
- data/lib/axlsx/drawing/scatter_series.rb +40 -7
- data/lib/axlsx/drawing/ser_axis.rb +2 -2
- data/lib/axlsx/drawing/series.rb +3 -3
- data/lib/axlsx/drawing/series_title.rb +2 -2
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +3 -1
- data/lib/axlsx/drawing/title.rb +22 -4
- data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
- data/lib/axlsx/drawing/val_axis.rb +1 -1
- data/lib/axlsx/drawing/view_3D.rb +2 -2
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +33 -31
- data/lib/axlsx/rels/relationship.rb +1 -1
- data/lib/axlsx/rels/relationships.rb +7 -4
- data/lib/axlsx/stylesheet/border_pr.rb +2 -2
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
- data/lib/axlsx/stylesheet/cell_style.rb +1 -3
- data/lib/axlsx/stylesheet/color.rb +1 -3
- data/lib/axlsx/stylesheet/font.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
- data/lib/axlsx/stylesheet/styles.rb +7 -7
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/constants.rb +107 -99
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +2 -1
- data/lib/axlsx/util/parser.rb +4 -4
- data/lib/axlsx/util/serialized_attributes.rb +16 -6
- data/lib/axlsx/util/simple_typed_list.rb +28 -52
- data/lib/axlsx/util/storage.rb +4 -4
- data/lib/axlsx/util/validators.rb +29 -17
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +11 -12
- data/lib/axlsx/workbook/defined_names.rb +2 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
- data/lib/axlsx/workbook/workbook.rb +36 -11
- data/lib/axlsx/workbook/workbook_view.rb +80 -0
- data/lib/axlsx/workbook/workbook_views.rb +22 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
- data/lib/axlsx/workbook/worksheet/break.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
- data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
- data/lib/axlsx/workbook/worksheet/col.rb +7 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
- data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
- data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
- data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
- data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
- data/lib/axlsx/workbook/worksheet/row.rb +40 -51
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/table.rb +6 -6
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
- data/test/drawing/tc_area_chart.rb +39 -0
- data/test/drawing/tc_area_series.rb +71 -0
- data/test/drawing/tc_axis.rb +27 -0
- data/test/drawing/tc_bar_chart.rb +71 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_chart.rb +23 -10
- data/test/drawing/tc_data_source.rb +6 -0
- data/test/drawing/tc_drawing.rb +2 -2
- data/test/drawing/tc_line_chart.rb +5 -5
- data/test/drawing/tc_line_series.rb +47 -6
- data/test/drawing/tc_pic.rb +11 -15
- data/test/drawing/tc_scatter_series.rb +36 -1
- data/test/drawing/tc_str_val.rb +9 -0
- data/test/drawing/tc_title.rb +5 -0
- data/test/stylesheet/tc_styles.rb +2 -2
- data/test/tc_axlsx.rb +31 -0
- data/test/tc_helper.rb +2 -0
- data/test/tc_package.rb +19 -1
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_simple_typed_list.rb +2 -3
- data/test/util/tc_validators.rb +34 -10
- data/test/workbook/tc_defined_name.rb +12 -4
- data/test/workbook/tc_shared_strings_table.rb +16 -1
- data/test/workbook/tc_workbook.rb +38 -3
- data/test/workbook/tc_workbook_view.rb +50 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
- data/test/workbook/worksheet/tc_break.rb +1 -1
- data/test/workbook/worksheet/tc_cell.rb +76 -8
- data/test/workbook/worksheet/tc_col.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
- data/test/workbook/worksheet/tc_data_bar.rb +1 -1
- data/test/workbook/worksheet/tc_data_validation.rb +11 -11
- data/test/workbook/worksheet/tc_header_footer.rb +2 -2
- data/test/workbook/worksheet/tc_icon_set.rb +1 -1
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_page_setup.rb +3 -3
- data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
- data/test/workbook/worksheet/tc_print_options.rb +1 -1
- data/test/workbook/worksheet/tc_rich_text.rb +44 -0
- data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
- data/test/workbook/worksheet/tc_row.rb +7 -2
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
- data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
- data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
- data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
- data/test/workbook/worksheet/tc_table.rb +2 -3
- data/test/workbook/worksheet/tc_worksheet.rb +99 -45
- metadata +89 -16
data/test/drawing/tc_drawing.rb
CHANGED
@@ -59,9 +59,9 @@ class TestDrawing < Test::Unit::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_relationships
|
62
|
-
|
62
|
+
@ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
|
63
63
|
assert_equal(@ws.drawing.relationships.size, 1, "adding a chart adds a relationship")
|
64
|
-
|
64
|
+
@ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
|
65
65
|
assert_equal(@ws.drawing.relationships.size, 2, "adding a chart adds a relationship")
|
66
66
|
end
|
67
67
|
|
@@ -19,11 +19,11 @@ class TestLineChart < Test::Unit::TestCase
|
|
19
19
|
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def test_grouping
|
23
|
+
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
|
24
|
+
assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
|
25
|
+
assert(@chart.grouping == :stacked)
|
26
|
+
end
|
27
27
|
|
28
28
|
def test_to_xml
|
29
29
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
|
@@ -6,25 +6,66 @@ class TestLineSeries < Test::Unit::TestCase
|
|
6
6
|
p = Axlsx::Package.new
|
7
7
|
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
8
8
|
chart = @ws.add_chart Axlsx::Line3DChart, :title => "fishery"
|
9
|
-
@series = chart.add_series
|
9
|
+
@series = chart.add_series(
|
10
|
+
:data => [0,1,2],
|
11
|
+
:labels => ["zero", "one", "two"],
|
12
|
+
:title => "bob",
|
13
|
+
:color => "#FF0000",
|
14
|
+
:show_marker => true,
|
15
|
+
:smooth => true
|
16
|
+
)
|
10
17
|
end
|
11
18
|
|
12
19
|
def test_initialize
|
13
20
|
assert_equal(@series.title.text, "bob", "series title has been applied")
|
14
21
|
assert_equal(@series.labels.class, Axlsx::AxDataSource)
|
15
22
|
assert_equal(@series.data.class, Axlsx::NumDataSource)
|
16
|
-
|
17
23
|
end
|
18
24
|
|
19
25
|
def test_show_marker
|
20
26
|
assert_equal(true, @series.show_marker)
|
21
27
|
@series.show_marker = false
|
22
28
|
assert_equal(false, @series.show_marker)
|
23
|
-
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_smooth
|
32
|
+
assert_equal(true, @series.smooth)
|
33
|
+
@series.smooth = false
|
34
|
+
assert_equal(false, @series.smooth)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_marker_symbol
|
38
|
+
assert_equal(:default, @series.marker_symbol)
|
39
|
+
@series.marker_symbol = :circle
|
40
|
+
assert_equal(:circle, @series.marker_symbol)
|
41
|
+
end
|
42
|
+
|
24
43
|
def test_to_xml_string
|
25
|
-
doc = Nokogiri::XML(@series
|
44
|
+
doc = Nokogiri::XML(wrap_with_namespaces(@series))
|
26
45
|
assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
|
27
|
-
|
46
|
+
assert_equal(xpath_with_namespaces(doc, "//c:marker").size, 0)
|
47
|
+
assert(doc.xpath("//smooth"))
|
48
|
+
|
49
|
+
@series.marker_symbol = :diamond
|
50
|
+
doc = Nokogiri::XML(wrap_with_namespaces(@series))
|
51
|
+
assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size, 1)
|
52
|
+
|
53
|
+
@series.show_marker = false
|
54
|
+
doc = Nokogiri::XML(wrap_with_namespaces(@series))
|
55
|
+
assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size, 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
def wrap_with_namespaces(series)
|
59
|
+
'<c:chartSpace xmlns:c="' <<
|
60
|
+
Axlsx::XML_NS_C <<
|
61
|
+
'" xmlns:a="' <<
|
62
|
+
Axlsx::XML_NS_A <<
|
63
|
+
'">' <<
|
64
|
+
series.to_xml_string <<
|
65
|
+
'</c:chartSpace>'
|
66
|
+
end
|
67
|
+
|
68
|
+
def xpath_with_namespaces(doc, xpath)
|
69
|
+
doc.xpath(xpath, "a" => Axlsx::XML_NS_A, "c" => Axlsx::XML_NS_C)
|
28
70
|
end
|
29
|
-
#TODO serialization testing
|
30
71
|
end
|
data/test/drawing/tc_pic.rb
CHANGED
@@ -5,12 +5,11 @@ class TestPic < Test::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
@p = Axlsx::Package.new
|
7
7
|
ws = @p.workbook.add_worksheet
|
8
|
-
@test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
|
9
|
-
@
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
def teardown
|
8
|
+
@test_img = @test_img_jpg = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
|
9
|
+
@test_img_png = File.dirname(__FILE__) + "/../../examples/image1.png"
|
10
|
+
@test_img_gif = File.dirname(__FILE__) + "/../../examples/image1.gif"
|
11
|
+
@test_img_fake = File.dirname(__FILE__) + "/../../examples/image1_fake.jpg"
|
12
|
+
@image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_initialization
|
@@ -38,6 +37,7 @@ class TestPic < Test::Unit::TestCase
|
|
38
37
|
assert_equal(200, @image.width)
|
39
38
|
|
40
39
|
end
|
40
|
+
|
41
41
|
def test_hyperlink
|
42
42
|
assert_equal(@image.hyperlink.href, "https://github.com/randym")
|
43
43
|
@image.hyperlink = "http://axlsx.blogspot.com"
|
@@ -70,15 +70,12 @@ class TestPic < Test::Unit::TestCase
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_image_src
|
73
|
-
assert_raise(ArgumentError) { @image.image_src = 49 }
|
74
|
-
assert_raise(ArgumentError) { @image.image_src = 'Unknown' }
|
75
73
|
assert_raise(ArgumentError) { @image.image_src = __FILE__ }
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
assert_nothing_raised { @image.image_src = @test_img_up }
|
74
|
+
assert_raise(ArgumentError) { @image.image_src = @test_img_fake }
|
75
|
+
assert_nothing_raised { @image.image_src = @test_img_gif }
|
76
|
+
assert_nothing_raised { @image.image_src = @test_img_png }
|
77
|
+
assert_nothing_raised { @image.image_src = @test_img_jpg }
|
78
|
+
assert_equal(@image.image_src, @test_img_jpg)
|
82
79
|
end
|
83
80
|
|
84
81
|
def test_descr
|
@@ -103,5 +100,4 @@ class TestPic < Test::Unit::TestCase
|
|
103
100
|
doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string)
|
104
101
|
assert_equal r_id, doc.xpath("//a:blip").first["r:embed"]
|
105
102
|
end
|
106
|
-
|
107
103
|
end
|
@@ -6,16 +6,51 @@ class TestScatterSeries < Test::Unit::TestCase
|
|
6
6
|
p = Axlsx::Package.new
|
7
7
|
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
8
8
|
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Scatter Chart"
|
9
|
-
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000'
|
9
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000', :smooth => true
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_initialize
|
13
13
|
assert_equal(@series.title.text, "exponents", "series title has been applied")
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_smoothed_chart_default_smoothing
|
17
|
+
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart", :scatter_style => :smoothMarker
|
18
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents"
|
19
|
+
assert(@series.smooth, "series is smooth by default on smooth charts")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_unsmoothed_chart_default_smoothing
|
23
|
+
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart", :scatter_style => :line
|
24
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents"
|
25
|
+
assert(!@series.smooth, "series is not smooth by default on non-smooth charts")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_explicit_smoothing
|
29
|
+
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart, Smooth Series", :scatter_style => :line
|
30
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents", :smooth => true
|
31
|
+
assert(@series.smooth, "series is smooth when overriding chart default")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_explicit_unsmoothing
|
35
|
+
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart, Unsmooth Series", :scatter_style => :smoothMarker
|
36
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents", :smooth => false
|
37
|
+
assert(!@series.smooth, "series is not smooth when overriding chart default")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_ln_width
|
41
|
+
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "ln width", :scatter_style => :line
|
42
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"ln_width"
|
43
|
+
@series.ln_width = 12700
|
44
|
+
assert_equal(@series.ln_width, 12700, 'line width assigment is allowed')
|
45
|
+
end
|
46
|
+
|
16
47
|
def test_to_xml_string
|
48
|
+
@chart.scatter_style = :line
|
49
|
+
@series.ln_width = 12700
|
17
50
|
doc = Nokogiri::XML(@chart.to_xml_string)
|
51
|
+
assert_equal(12700, @series.ln_width)
|
18
52
|
assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,4)
|
53
|
+
assert_equal(doc.xpath("//a:ln[@w='#{@series.ln_width}']").length, 1)
|
19
54
|
end
|
20
55
|
|
21
56
|
end
|
data/test/drawing/tc_str_val.rb
CHANGED
@@ -4,6 +4,7 @@ class TestStrVal < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
@str_val = Axlsx::StrVal.new :v => "1"
|
7
|
+
@str_val_with_special_characters = Axlsx::StrVal.new :v => "a & b <c>"
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_initialize
|
@@ -18,4 +19,12 @@ class TestStrVal < Test::Unit::TestCase
|
|
18
19
|
assert_equal(doc.xpath("//c:pt/c:v[text()='1']").size, 1)
|
19
20
|
end
|
20
21
|
|
22
|
+
def test_to_xml_string_special_characters
|
23
|
+
str = '<?xml version="1.0" encoding="UTF-8"?>'
|
24
|
+
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
|
25
|
+
str << @str_val_with_special_characters.to_xml_string(0)
|
26
|
+
doc = Nokogiri::XML(str)
|
27
|
+
assert_equal(doc.xpath("//c:pt/c:v[text()='a & b <c>']").size, 1)
|
28
|
+
end
|
29
|
+
|
21
30
|
end
|
data/test/drawing/tc_title.rb
CHANGED
@@ -19,6 +19,11 @@ class TestTitle < Test::Unit::TestCase
|
|
19
19
|
assert(@title.cell == nil)
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_initialize_title_size
|
23
|
+
title = Axlsx::Title.new 'bob', 90
|
24
|
+
assert_equal "90", title.text_size
|
25
|
+
end
|
26
|
+
|
22
27
|
def test_text
|
23
28
|
assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
|
24
29
|
@title.cell = @row.cells.first
|
@@ -133,7 +133,7 @@ class TestStyles < Test::Unit::TestCase
|
|
133
133
|
:font_name => "woot font"
|
134
134
|
}
|
135
135
|
assert_equal(@styles.parse_font_options {}, nil, "noop if no font keys are set")
|
136
|
-
|
136
|
+
assert(@styles.parse_font_options(:b=>1).is_a?(Integer), "return index of font if not :dxf type")
|
137
137
|
assert_equal(@styles.parse_font_options(:b=>1, :type => :dxf).class, Axlsx::Font, "return font object if :dxf type")
|
138
138
|
|
139
139
|
f = @styles.parse_font_options(options.merge(:type => :dxf))
|
@@ -147,7 +147,7 @@ class TestStyles < Test::Unit::TestCase
|
|
147
147
|
|
148
148
|
def test_parse_fill_options
|
149
149
|
assert_equal(@styles.parse_fill_options {}, nil, "noop if no fill keys are set")
|
150
|
-
|
150
|
+
assert(@styles.parse_fill_options(:bg_color => "DE").is_a?(Integer), "return index of fill if not :dxf type")
|
151
151
|
assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type")
|
152
152
|
f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf)
|
153
153
|
assert(f.fill_type.bgColor.rgb == "FFDEDEDE")
|
data/test/tc_axlsx.rb
CHANGED
@@ -45,6 +45,16 @@ class TestAxlsx < Test::Unit::TestCase
|
|
45
45
|
assert_equal(Axlsx.cell_range([c2, c1], true), "'Sheet <''>" 1'!$A$1:$B$1")
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_cell_range_row
|
49
|
+
p = Axlsx::Package.new
|
50
|
+
ws = p.workbook.add_worksheet
|
51
|
+
row = ws.add_row
|
52
|
+
row.add_cell
|
53
|
+
row.add_cell
|
54
|
+
row.add_cell
|
55
|
+
assert_equal("A1:C1", Axlsx.cell_range(row, false))
|
56
|
+
end
|
57
|
+
|
48
58
|
def test_name_to_indices
|
49
59
|
setup_wide
|
50
60
|
@wide_test_points.each do |key, value|
|
@@ -69,4 +79,25 @@ class TestAxlsx < Test::Unit::TestCase
|
|
69
79
|
assert_equal([['Z5', 'AA5', 'AB5'], ['Z6', 'AA6', 'AB6']], Axlsx::range_to_a('Z5:AB6'))
|
70
80
|
end
|
71
81
|
|
82
|
+
def test_sanitize_frozen_control_strippped
|
83
|
+
needs_sanitize = "legit\x08".freeze # Backspace control char
|
84
|
+
|
85
|
+
assert_equal(Axlsx.sanitize(needs_sanitize), 'legit', 'should strip control chars')
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_sanitize_unfrozen_control_strippped
|
89
|
+
needs_sanitize = "legit\x08" # Backspace control char
|
90
|
+
sanitized_str = Axlsx.sanitize(needs_sanitize)
|
91
|
+
|
92
|
+
assert_equal(sanitized_str, 'legit', 'should strip control chars')
|
93
|
+
assert_equal(sanitized_str.object_id, sanitized_str.object_id, 'should preserve object')
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_sanitize_unfrozen_no_sanitize
|
97
|
+
legit_str = 'legit'
|
98
|
+
sanitized_str = Axlsx.sanitize(legit_str)
|
99
|
+
|
100
|
+
assert_equal(sanitized_str, legit_str, 'should preserve value')
|
101
|
+
assert_equal(sanitized_str.object_id, legit_str.object_id, 'should preserve object')
|
102
|
+
end
|
72
103
|
end
|
data/test/tc_helper.rb
CHANGED
data/test/tc_package.rb
CHANGED
@@ -7,10 +7,17 @@ class TestPackage < Test::Unit::TestCase
|
|
7
7
|
ws = @package.workbook.add_worksheet
|
8
8
|
ws.add_row ['Can', 'we', 'build it?']
|
9
9
|
ws.add_row ['Yes!', 'We', 'can!']
|
10
|
+
@rt = Axlsx::RichText.new
|
11
|
+
@rt.add_run "run 1", :b => true, :i => false
|
12
|
+
ws.add_row [@rt]
|
13
|
+
|
14
|
+
ws.rows.last.add_cell('b', :type => :text)
|
15
|
+
|
10
16
|
ws.outline_level_rows 0, 1
|
11
17
|
ws.outline_level_columns 0, 1
|
12
18
|
ws.add_hyperlink :ref => ws.rows.first.cells.last, :location => 'https://github.com/randym'
|
13
19
|
ws.workbook.add_defined_name("#{ws.name}!A1:C2", :name => '_xlnm.Print_Titles', :hidden => true)
|
20
|
+
ws.workbook.add_view active_tab: 1, first_sheet: 0
|
14
21
|
ws.protect_range('A1:C1')
|
15
22
|
ws.protect_range(ws.rows.last.cells)
|
16
23
|
ws.add_comment :author => 'alice', :text => 'Hi Bob', :ref => 'A12'
|
@@ -52,6 +59,11 @@ class TestPackage < Test::Unit::TestCase
|
|
52
59
|
chart.d_lbls.show_val = true
|
53
60
|
end
|
54
61
|
|
62
|
+
ws.add_chart(Axlsx::BubbleChart, :title => 'bubble chart') do |chart|
|
63
|
+
chart.add_series :xData => [1,2,3,4], :yData => [1,3,2,4]
|
64
|
+
chart.d_lbls.show_val = true
|
65
|
+
end
|
66
|
+
|
55
67
|
@fname = 'axlsx_test_serialization.xlsx'
|
56
68
|
img = File.expand_path('../../examples/image1.jpeg', __FILE__)
|
57
69
|
ws.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
|
@@ -148,6 +160,11 @@ class TestPackage < Test::Unit::TestCase
|
|
148
160
|
assert package_1.to_stream.string == package_2.to_stream.string, "zip files are not identical"
|
149
161
|
end
|
150
162
|
|
163
|
+
def test_serialization_creates_files_with_excel_mime_type
|
164
|
+
assert_equal(MimeMagic.by_magic(@package.to_stream).type,
|
165
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
166
|
+
end
|
167
|
+
|
151
168
|
def test_validation
|
152
169
|
assert_equal(@package.validate.size, 0, @package.validate)
|
153
170
|
Axlsx::Workbook.send(:class_variable_set, :@@date1904, 9900)
|
@@ -176,12 +193,13 @@ class TestPackage < Test::Unit::TestCase
|
|
176
193
|
|
177
194
|
|
178
195
|
#no mystery parts
|
179
|
-
assert_equal(
|
196
|
+
assert_equal(25, p.size)
|
180
197
|
|
181
198
|
end
|
182
199
|
|
183
200
|
def test_shared_strings_requires_part
|
184
201
|
@package.use_shared_strings = true
|
202
|
+
@package.to_stream #ensure all cell_serializer paths are hit
|
185
203
|
p = @package.send(:parts)
|
186
204
|
assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing")
|
187
205
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
class TestMimeTypeUtils < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
@test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mime_type_utils
|
11
|
+
assert_equal(Axlsx::MimeTypeUtils::get_mime_type(@test_img), 'image/jpeg')
|
12
|
+
end
|
13
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'tc_helper.rb'
|
2
2
|
class TestSimpleTypedList < Test::Unit::TestCase
|
3
3
|
def setup
|
4
|
-
@list = Axlsx::SimpleTypedList.new
|
4
|
+
@list = Axlsx::SimpleTypedList.new Integer
|
5
5
|
end
|
6
6
|
|
7
7
|
def teardown
|
@@ -72,7 +72,6 @@ class TestSimpleTypedList < Test::Unit::TestCase
|
|
72
72
|
def test_equality
|
73
73
|
@list.push 1
|
74
74
|
@list.push 2
|
75
|
-
assert_equal(@list, [1,2])
|
76
|
-
|
75
|
+
assert_equal(@list.to_ary, [1,2])
|
77
76
|
end
|
78
77
|
end
|
data/test/util/tc_validators.rb
CHANGED
@@ -91,7 +91,7 @@ class TestValidators < Test::Unit::TestCase
|
|
91
91
|
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 10.0 }
|
92
92
|
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 400.1 }
|
93
93
|
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 "99" }
|
94
|
-
|
94
|
+
|
95
95
|
#scale_0_10_400
|
96
96
|
assert_nothing_raised { Axlsx.validate_scale_0_10_400 0 }
|
97
97
|
assert_nothing_raised { Axlsx.validate_scale_0_10_400 10 }
|
@@ -101,7 +101,7 @@ class TestValidators < Test::Unit::TestCase
|
|
101
101
|
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 10.0 }
|
102
102
|
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 400.1 }
|
103
103
|
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 "99" }
|
104
|
-
|
104
|
+
|
105
105
|
#page_orientation
|
106
106
|
assert_nothing_raised { Axlsx.validate_page_orientation :default }
|
107
107
|
assert_nothing_raised { Axlsx.validate_page_orientation :landscape }
|
@@ -109,7 +109,7 @@ class TestValidators < Test::Unit::TestCase
|
|
109
109
|
assert_raise(ArgumentError) { Axlsx.validate_page_orientation nil }
|
110
110
|
assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 }
|
111
111
|
assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" }
|
112
|
-
|
112
|
+
|
113
113
|
#data_validation_error_style
|
114
114
|
[:information, :stop, :warning].each do |sym|
|
115
115
|
assert_nothing_raised { Axlsx.validate_data_validation_error_style sym }
|
@@ -117,7 +117,7 @@ class TestValidators < Test::Unit::TestCase
|
|
117
117
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
118
118
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'warning' }
|
119
119
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
120
|
-
|
120
|
+
|
121
121
|
#data_validation_operator
|
122
122
|
[:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].each do |sym|
|
123
123
|
assert_nothing_raised { Axlsx.validate_data_validation_operator sym }
|
@@ -125,7 +125,7 @@ class TestValidators < Test::Unit::TestCase
|
|
125
125
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
126
126
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'lessThan' }
|
127
127
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
128
|
-
|
128
|
+
|
129
129
|
#data_validation_type
|
130
130
|
[:custom, :data, :decimal, :list, :none, :textLength, :time, :whole].each do |sym|
|
131
131
|
assert_nothing_raised { Axlsx.validate_data_validation_type sym }
|
@@ -133,7 +133,7 @@ class TestValidators < Test::Unit::TestCase
|
|
133
133
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
134
134
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'decimal' }
|
135
135
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
136
|
-
|
136
|
+
|
137
137
|
#sheet_view_type
|
138
138
|
[:normal, :page_break_preview, :page_layout].each do |sym|
|
139
139
|
assert_nothing_raised { Axlsx.validate_sheet_view_type sym }
|
@@ -141,7 +141,7 @@ class TestValidators < Test::Unit::TestCase
|
|
141
141
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
|
142
142
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'page_layout' }
|
143
143
|
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
|
144
|
-
|
144
|
+
|
145
145
|
#active_pane_type
|
146
146
|
[:bottom_left, :bottom_right, :top_left, :top_right].each do |sym|
|
147
147
|
assert_nothing_raised { Axlsx.validate_pane_type sym }
|
@@ -149,7 +149,7 @@ class TestValidators < Test::Unit::TestCase
|
|
149
149
|
assert_raise(ArgumentError) { Axlsx.validate_pane_type :other_symbol }
|
150
150
|
assert_raise(ArgumentError) { Axlsx.validate_pane_type 'bottom_left' }
|
151
151
|
assert_raise(ArgumentError) { Axlsx.validate_pane_type 0 }
|
152
|
-
|
152
|
+
|
153
153
|
#split_state_type
|
154
154
|
[:frozen, :frozen_split, :split].each do |sym|
|
155
155
|
assert_nothing_raised { Axlsx.validate_split_state_type sym }
|
@@ -157,8 +157,32 @@ class TestValidators < Test::Unit::TestCase
|
|
157
157
|
assert_raise(ArgumentError) { Axlsx.validate_split_state_type :other_symbol }
|
158
158
|
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 'frozen_split' }
|
159
159
|
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 }
|
160
|
+
|
161
|
+
#display_blanks_as
|
162
|
+
[:gap, :span, :zero].each do |sym|
|
163
|
+
assert_nothing_raised { Axlsx.validate_display_blanks_as sym }
|
164
|
+
end
|
165
|
+
assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as :other_symbol }
|
166
|
+
assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 'other_blank' }
|
167
|
+
assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 0 }
|
168
|
+
|
169
|
+
#view_visibility
|
170
|
+
[:visible, :hidden, :very_hidden].each do |sym|
|
171
|
+
assert_nothing_raised { Axlsx.validate_view_visibility sym }
|
172
|
+
end
|
173
|
+
assert_raise(ArgumentError) { Axlsx.validate_view_visibility :other_symbol }
|
174
|
+
assert_raise(ArgumentError) { Axlsx.validate_view_visibility 'other_visibility' }
|
175
|
+
assert_raise(ArgumentError) { Axlsx.validate_view_visibility 0 }
|
176
|
+
|
177
|
+
#marker_symbol
|
178
|
+
[:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x].each do |sym|
|
179
|
+
assert_nothing_raised { Axlsx.validate_marker_symbol sym }
|
180
|
+
end
|
181
|
+
assert_raise(ArgumentError) { Axlsx.validate_marker_symbol :other_symbol }
|
182
|
+
assert_raise(ArgumentError) { Axlsx.validate_marker_symbol 'other_marker' }
|
183
|
+
assert_raise(ArgumentError) { Axlsx.validate_marker_symbol 0 }
|
160
184
|
end
|
161
|
-
|
185
|
+
|
162
186
|
def test_validate_integerish
|
163
187
|
assert_raise(ArgumentError) { Axlsx.validate_integerish Axlsx }
|
164
188
|
[1, 1.4, "a"].each { |test_value| assert_nothing_raised { Axlsx.validate_integerish test_value } }
|
@@ -179,7 +203,7 @@ class TestValidators < Test::Unit::TestCase
|
|
179
203
|
|
180
204
|
def test_range_validation
|
181
205
|
# exclusive
|
182
|
-
assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) }
|
206
|
+
assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) }
|
183
207
|
# inclusive by default
|
184
208
|
assert_nothing_raised { Axlsx::RangeValidator.validate('foo', 1, 10, 10) }
|
185
209
|
end
|