axlsx 1.0.18 → 1.1.0
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/CHANGELOG.md +11 -3
- data/README.md +93 -18
- data/examples/example.csv +1000 -0
- data/examples/example.rb +97 -5
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx.rb +30 -9
- data/lib/axlsx/content_type/content_type.rb +9 -9
- data/lib/axlsx/content_type/default.rb +9 -6
- data/lib/axlsx/content_type/override.rb +12 -8
- data/lib/axlsx/doc_props/app.rb +37 -40
- data/lib/axlsx/doc_props/core.rb +12 -17
- data/lib/axlsx/drawing/axis.rb +38 -19
- data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
- data/lib/axlsx/drawing/bar_series.rb +13 -14
- data/lib/axlsx/drawing/cat_axis.rb +15 -14
- data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
- data/lib/axlsx/drawing/chart.rb +37 -38
- data/lib/axlsx/drawing/drawing.rb +15 -12
- data/lib/axlsx/drawing/graphic_frame.rb +21 -21
- data/lib/axlsx/drawing/hyperlink.rb +12 -11
- data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
- data/lib/axlsx/drawing/line_series.rb +11 -11
- data/lib/axlsx/drawing/marker.rb +10 -8
- data/lib/axlsx/drawing/named_axis_data.rb +36 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
- data/lib/axlsx/drawing/pic.rb +24 -37
- data/lib/axlsx/drawing/picture_locking.rb +21 -18
- data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
- data/lib/axlsx/drawing/pie_series.rb +15 -12
- data/lib/axlsx/drawing/scaling.rb +10 -10
- data/lib/axlsx/drawing/scatter_chart.rb +69 -0
- data/lib/axlsx/drawing/scatter_series.rb +39 -0
- data/lib/axlsx/drawing/ser_axis.rb +10 -10
- data/lib/axlsx/drawing/series.rb +15 -15
- data/lib/axlsx/drawing/series_title.rb +14 -14
- data/lib/axlsx/drawing/title.rb +26 -26
- data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
- data/lib/axlsx/drawing/val_axis.rb +8 -7
- data/lib/axlsx/drawing/val_axis_data.rb +17 -17
- data/lib/axlsx/drawing/view_3D.rb +22 -20
- data/lib/axlsx/package.rb +32 -15
- data/lib/axlsx/rels/relationship.rb +9 -6
- data/lib/axlsx/rels/relationships.rb +7 -1
- data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
- data/lib/axlsx/stylesheet/border.rb +27 -23
- data/lib/axlsx/stylesheet/border_pr.rb +16 -15
- data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
- data/lib/axlsx/stylesheet/cell_style.rb +8 -5
- data/lib/axlsx/stylesheet/color.rb +20 -14
- data/lib/axlsx/stylesheet/fill.rb +7 -5
- data/lib/axlsx/stylesheet/font.rb +14 -14
- data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
- data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
- data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
- data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
- data/lib/axlsx/stylesheet/styles.rb +41 -32
- data/lib/axlsx/stylesheet/table_style.rb +9 -4
- data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
- data/lib/axlsx/stylesheet/table_styles.rb +11 -8
- data/lib/axlsx/stylesheet/xf.rb +29 -25
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +18 -9
- data/lib/axlsx/util/validators.rb +13 -6
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
- data/lib/axlsx/workbook/workbook.rb +43 -19
- data/lib/axlsx/workbook/worksheet/cell.rb +93 -91
- data/lib/axlsx/workbook/worksheet/col.rb +114 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table.rb +96 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +152 -118
- data/lib/schema/dc.xsd +5 -5
- data/lib/schema/dcmitype.xsd +5 -3
- data/lib/schema/dcterms.xsd +15 -15
- data/lib/schema/opc-coreProperties.xsd +6 -2
- data/lib/schema/xml.xsd +7 -8
- data/test/#benchmark.txt# +7 -0
- data/test/#tc_helper.rb# +3 -0
- data/test/benchmark.rb +81 -0
- data/test/benchmark.rb~ +0 -0
- data/test/benchmark.txt +6 -0
- data/test/benchmark.txt~ +6 -0
- data/test/content_type/tc_content_type.rb +30 -32
- data/test/content_type/tc_default.rb +8 -23
- data/test/content_type/tc_override.rb +7 -21
- data/test/doc_props/tc_app.rb +2 -8
- data/test/doc_props/tc_core.rb +6 -7
- data/test/drawing/tc_axis.rb +7 -3
- data/test/drawing/tc_bar_3D_chart.rb +6 -7
- data/test/drawing/tc_bar_series.rb +4 -5
- data/test/drawing/tc_cat_axis.rb +2 -3
- data/test/drawing/tc_cat_axis_data.rb +2 -3
- data/test/drawing/tc_chart.rb +11 -12
- data/test/drawing/tc_drawing.rb +7 -8
- data/test/drawing/tc_graphic_frame.rb +3 -4
- data/test/drawing/tc_hyperlink.rb +2 -3
- data/test/drawing/tc_line_3d_chart.rb +5 -6
- data/test/drawing/tc_line_series.rb +3 -4
- data/test/drawing/tc_marker.rb +3 -4
- data/test/drawing/tc_one_cell_anchor.rb +6 -7
- data/test/drawing/tc_pic.rb +8 -9
- data/test/drawing/tc_picture_locking.rb +2 -3
- data/test/drawing/tc_pie_3D_chart.rb +5 -6
- data/test/drawing/tc_pie_series.rb +4 -5
- data/test/drawing/tc_scaling.rb +3 -4
- data/test/drawing/tc_scatter_chart.rb +43 -0
- data/test/drawing/tc_scatter_series.rb +20 -0
- data/test/drawing/tc_ser_axis.rb +2 -3
- data/test/drawing/tc_series.rb +4 -5
- data/test/drawing/tc_series_title.rb +4 -5
- data/test/drawing/tc_title.rb +4 -5
- data/test/drawing/tc_two_cell_anchor.rb +4 -5
- data/test/drawing/tc_val_axis.rb +2 -3
- data/test/drawing/tc_val_axis_data.rb +2 -3
- data/test/drawing/tc_view_3D.rb +6 -7
- data/test/example.csv +1000 -0
- data/test/example.xlsx +0 -0
- data/test/example_streamed.xlsx +0 -0
- data/test/profile.rb +33 -0
- data/test/rels/tc_relationship.rb +5 -6
- data/test/rels/tc_relationships.rb +4 -5
- data/test/stylesheet/tc_border.rb +3 -4
- data/test/stylesheet/tc_border_pr.rb +3 -4
- data/test/stylesheet/tc_cell_alignment.rb +4 -5
- data/test/stylesheet/tc_cell_protection.rb +2 -3
- data/test/stylesheet/tc_cell_style.rb +2 -3
- data/test/stylesheet/tc_color.rb +2 -3
- data/test/stylesheet/tc_fill.rb +1 -2
- data/test/stylesheet/tc_font.rb +5 -6
- data/test/stylesheet/tc_gradient_fill.rb +1 -2
- data/test/stylesheet/tc_gradient_stop.rb +1 -2
- data/test/stylesheet/tc_num_fmt.rb +1 -2
- data/test/stylesheet/tc_pattern_fill.rb +3 -4
- data/test/stylesheet/tc_styles.rb +15 -9
- data/test/stylesheet/tc_table_style.rb +2 -3
- data/test/stylesheet/tc_table_style_element.rb +2 -3
- data/test/stylesheet/tc_table_styles.rb +3 -4
- data/test/stylesheet/tc_xf.rb +16 -17
- data/test/tc_axlsx.rb +39 -0
- data/test/tc_axlsx.rb~ +0 -0
- data/test/tc_helper.rb +3 -0
- data/test/tc_helper.rb~ +3 -0
- data/test/tc_package.rb +13 -10
- data/test/util/tc_simple_typed_list.rb +8 -9
- data/test/util/tc_validators.rb +7 -8
- data/test/workbook/tc_shared_strings_table.rb +5 -6
- data/test/workbook/tc_workbook.rb +24 -6
- data/test/workbook/worksheet/table/tc_table.rb +71 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
- data/test/workbook/worksheet/tc_cell.rb +24 -10
- data/test/workbook/worksheet/tc_col.rb +59 -0
- data/test/workbook/worksheet/tc_col.rb~ +10 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +1 -2
- data/test/workbook/worksheet/tc_page_margins.rb +6 -9
- data/test/workbook/worksheet/tc_row.rb +26 -12
- data/test/workbook/worksheet/tc_worksheet.rb +134 -68
- metadata +150 -90
- data/test/drawing/tc_hyperlink.rb~ +0 -71
- data/test/workbook/tc_shared_strings_table.rb~ +0 -8
- data/test/workbook/worksheet/tc_date_time_converter.rb~ +0 -69
data/test/tc_axlsx.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestAxlsx < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup_wide
|
|
6
|
+
@wide_test_points = { "A3" => 0,
|
|
7
|
+
"Z3" => 25,
|
|
8
|
+
"B3" => 1,
|
|
9
|
+
"AA3" => 1 * 26 + 0,
|
|
10
|
+
"AAA3" => 1 * 26**2 + 1 * 26 + 0,
|
|
11
|
+
"AAZ3" => 1 * 26**2 + 1 * 26 + 25,
|
|
12
|
+
"ABA3" => 1 * 26**2 + 2 * 26 + 0,
|
|
13
|
+
"BZU3" => 2 * 26**2 + 26 * 26 + 20
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_cell_range
|
|
18
|
+
#To do
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_name_to_indices
|
|
22
|
+
setup_wide
|
|
23
|
+
@wide_test_points.each do |key, value|
|
|
24
|
+
assert_equal(Axlsx.name_to_indices(key), [value,2])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_col_ref
|
|
29
|
+
setup_wide
|
|
30
|
+
@wide_test_points.each do |key, value|
|
|
31
|
+
assert_equal(Axlsx.col_ref(value), key.gsub(/\d+/, ''))
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_cell_r
|
|
36
|
+
# todo
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
data/test/tc_axlsx.rb~
ADDED
|
File without changes
|
data/test/tc_helper.rb
ADDED
data/test/tc_helper.rb~
ADDED
data/test/tc_package.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
|
|
4
3
|
class TestPackage < Test::Unit::TestCase
|
|
5
|
-
def setup
|
|
4
|
+
def setup
|
|
6
5
|
@package = Axlsx::Package.new
|
|
7
6
|
ws = @package.workbook.add_worksheet
|
|
8
7
|
chart = ws.add_chart Axlsx::Pie3DChart
|
|
@@ -39,16 +38,16 @@ class TestPackage < Test::Unit::TestCase
|
|
|
39
38
|
fname = 'axlsx_test_serialization.xlsx'
|
|
40
39
|
assert_nothing_raised do
|
|
41
40
|
begin
|
|
42
|
-
z= @package.serialize(@fname)
|
|
41
|
+
z= @package.serialize(@fname)
|
|
43
42
|
zf = Zip::ZipFile.open(@fname)
|
|
44
43
|
@package.send(:parts).each{ |part| zf.get_entry(part[:entry]) }
|
|
45
|
-
File.delete(@fname)
|
|
44
|
+
File.delete(@fname)
|
|
46
45
|
rescue Errno::EACCES
|
|
47
46
|
puts "WARNING:: test_serialization requires write access."
|
|
48
47
|
end
|
|
49
|
-
end
|
|
48
|
+
end
|
|
50
49
|
end
|
|
51
|
-
|
|
50
|
+
|
|
52
51
|
def test_validation
|
|
53
52
|
assert_equal(@package.validate.size, 0, @package.validate)
|
|
54
53
|
#how to test for failure? the internal validations on the models are so strict I cant break anthing.....
|
|
@@ -58,7 +57,7 @@ class TestPackage < Test::Unit::TestCase
|
|
|
58
57
|
p = @package.send(:parts)
|
|
59
58
|
p.each do |part|
|
|
60
59
|
#all parts must have :doc, :entry, :schema
|
|
61
|
-
assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
|
|
60
|
+
assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
|
|
62
61
|
end
|
|
63
62
|
#all parts have an entry
|
|
64
63
|
assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing")
|
|
@@ -76,7 +75,7 @@ class TestPackage < Test::Unit::TestCase
|
|
|
76
75
|
|
|
77
76
|
#no mystery parts
|
|
78
77
|
assert_equal(p.size, 12)
|
|
79
|
-
|
|
78
|
+
|
|
80
79
|
end
|
|
81
80
|
|
|
82
81
|
def test_shared_strings_requires_part
|
|
@@ -84,7 +83,7 @@ class TestPackage < Test::Unit::TestCase
|
|
|
84
83
|
p = @package.send(:parts)
|
|
85
84
|
assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing")
|
|
86
85
|
end
|
|
87
|
-
|
|
86
|
+
|
|
88
87
|
def test_workbook_is_a_workbook
|
|
89
88
|
assert @package.workbook.is_a? Axlsx::Workbook
|
|
90
89
|
end
|
|
@@ -106,4 +105,8 @@ class TestPackage < Test::Unit::TestCase
|
|
|
106
105
|
assert(ct.select { |ct| ct.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1)
|
|
107
106
|
end
|
|
108
107
|
|
|
108
|
+
def test_name_to_indices
|
|
109
|
+
assert(Axlsx::name_to_indices('A1') == [0,0])
|
|
110
|
+
assert(Axlsx::name_to_indices('A100') == [0,99], 'needs to axcept rows that contain 0')
|
|
111
|
+
end
|
|
109
112
|
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
class TestSimpleTypedList < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
3
|
+
def setup
|
|
5
4
|
@list = Axlsx::SimpleTypedList.new Fixnum
|
|
6
5
|
end
|
|
7
6
|
|
|
8
|
-
def teardown
|
|
7
|
+
def teardown
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
def test_type_is_a_class_or_array_of_class
|
|
@@ -15,18 +14,18 @@ class TestSimpleTypedList < Test::Unit::TestCase
|
|
|
15
14
|
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new "1" }
|
|
16
15
|
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new [Integer, "Class"] }
|
|
17
16
|
end
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
def test_indexed_based_assignment
|
|
20
19
|
#should not allow nil assignment
|
|
21
20
|
assert_raise(ArgumentError) { @list[0] = nil }
|
|
22
21
|
assert_raise(ArgumentError) { @list[0] = "1" }
|
|
23
22
|
assert_nothing_raised { @list[0] = 1 }
|
|
24
23
|
end
|
|
25
|
-
|
|
24
|
+
|
|
26
25
|
def test_concat_assignment
|
|
27
26
|
assert_raise(ArgumentError) { @list << nil }
|
|
28
27
|
assert_raise(ArgumentError) { @list << "1" }
|
|
29
|
-
assert_nothing_raised { @list << 1 }
|
|
28
|
+
assert_nothing_raised { @list << 1 }
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
def test_concat_should_return_index
|
|
@@ -59,8 +58,8 @@ class TestSimpleTypedList < Test::Unit::TestCase
|
|
|
59
58
|
assert_nothing_raised { @list.delete_at 3 }
|
|
60
59
|
@list.unlock
|
|
61
60
|
#ignore garbage
|
|
62
|
-
assert_nothing_raised { @list.delete 0 }
|
|
63
|
-
assert_nothing_raised { @list.delete 9 }
|
|
61
|
+
assert_nothing_raised { @list.delete 0 }
|
|
62
|
+
assert_nothing_raised { @list.delete 9 }
|
|
64
63
|
end
|
|
65
64
|
|
|
66
65
|
end
|
data/test/util/tc_validators.rb
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
class TestValidators < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
3
|
+
def setup
|
|
5
4
|
end
|
|
6
5
|
def teardown
|
|
7
6
|
end
|
|
8
|
-
|
|
7
|
+
|
|
9
8
|
def test_validators
|
|
10
9
|
#unsigned_int
|
|
11
10
|
assert_nothing_raised { Axlsx.validate_unsigned_int 1 }
|
|
12
11
|
assert_nothing_raised { Axlsx.validate_unsigned_int +1 }
|
|
13
12
|
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int -1 }
|
|
14
13
|
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int '1' }
|
|
15
|
-
|
|
14
|
+
|
|
16
15
|
#int
|
|
17
16
|
assert_nothing_raised { Axlsx.validate_int 1 }
|
|
18
17
|
assert_nothing_raised { Axlsx.validate_int -1 }
|
|
19
18
|
assert_raise(ArgumentError) { Axlsx.validate_int 'a' }
|
|
20
19
|
assert_raise(ArgumentError) { Axlsx.validate_int Array }
|
|
21
|
-
|
|
20
|
+
|
|
22
21
|
#boolean (as 0 or 1, :true, :false, true, false, or "true," "false")
|
|
23
22
|
[0,1,:true, :false, true, false, "true", "false"].each do |v|
|
|
24
23
|
assert_nothing_raised { Axlsx.validate_boolean 0 }
|
|
25
24
|
end
|
|
26
25
|
assert_raise(ArgumentError) { Axlsx.validate_boolean 2 }
|
|
27
|
-
|
|
26
|
+
|
|
28
27
|
#string
|
|
29
28
|
assert_nothing_raised { Axlsx.validate_string "1" }
|
|
30
29
|
assert_raise(ArgumentError) { Axlsx.validate_string 2 }
|
|
@@ -64,7 +63,7 @@ class TestValidators < Test::Unit::TestCase
|
|
|
64
63
|
assert_raise(ArgumentError) { Axlsx.validate_content_type nil }
|
|
65
64
|
assert_raise(ArgumentError) { Axlsx.validate_content_type "http://some.url" }
|
|
66
65
|
assert_raise(ArgumentError) { Axlsx.validate_content_type false }
|
|
67
|
-
|
|
66
|
+
|
|
68
67
|
#relationshipType
|
|
69
68
|
assert_nothing_raised { Axlsx.validate_relationship_type Axlsx::WORKBOOK_R }
|
|
70
69
|
assert_raise(ArgumentError) { Axlsx.validate_relationship_type nil }
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
|
|
4
3
|
class TestSharedStringsTable < Test::Unit::TestCase
|
|
5
4
|
|
|
6
|
-
def setup
|
|
5
|
+
def setup
|
|
7
6
|
@p = Axlsx::Package.new :use_shared_strings=>true
|
|
8
7
|
ws = @p.workbook.add_worksheet
|
|
9
8
|
ws.add_row ['a', 1, 'b']
|
|
10
9
|
ws.add_row ['b', 1, 'c']
|
|
11
|
-
ws.add_row ['c', 1, 'd']
|
|
10
|
+
ws.add_row ['c', 1, 'd']
|
|
12
11
|
end
|
|
13
12
|
|
|
14
13
|
def test_workbook_has_shared_strings
|
|
@@ -25,9 +24,9 @@ class TestSharedStringsTable < Test::Unit::TestCase
|
|
|
25
24
|
assert_equal(sst.unique_count, 4)
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
def test_valid_document
|
|
27
|
+
def test_valid_document
|
|
29
28
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
30
|
-
doc = Nokogiri::XML(@p.workbook.shared_strings.
|
|
29
|
+
doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml_string)
|
|
31
30
|
errors = []
|
|
32
31
|
schema.validate(doc).each do |error|
|
|
33
32
|
puts error.message
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
|
|
4
3
|
class TestWorkbook < Test::Unit::TestCase
|
|
5
|
-
def setup
|
|
4
|
+
def setup
|
|
6
5
|
p = Axlsx::Package.new
|
|
7
|
-
@wb = p.workbook
|
|
6
|
+
@wb = p.workbook
|
|
8
7
|
end
|
|
9
8
|
|
|
10
9
|
def teardown
|
|
11
10
|
end
|
|
12
11
|
|
|
12
|
+
def test_no_autowidth
|
|
13
|
+
assert_equal(@wb.use_autowidth, true)
|
|
14
|
+
assert_raise(ArgumentError) {@wb.use_autowidth = 0.1}
|
|
15
|
+
assert_nothing_raised {@wb.use_autowidth = false}
|
|
16
|
+
assert_equal(@wb.use_autowidth, false)
|
|
17
|
+
end
|
|
18
|
+
|
|
13
19
|
def test_date1904
|
|
14
20
|
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
|
15
21
|
@wb.date1904 = :false
|
|
@@ -18,6 +24,8 @@ class TestWorkbook < Test::Unit::TestCase
|
|
|
18
24
|
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
|
19
25
|
end
|
|
20
26
|
|
|
27
|
+
|
|
28
|
+
|
|
21
29
|
def test_shared_strings
|
|
22
30
|
assert_equal(@wb.use_shared_strings, nil)
|
|
23
31
|
assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'}
|
|
@@ -42,7 +50,7 @@ class TestWorkbook < Test::Unit::TestCase
|
|
|
42
50
|
|
|
43
51
|
def test_to_xml
|
|
44
52
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
45
|
-
doc = Nokogiri::XML(@wb.
|
|
53
|
+
doc = Nokogiri::XML(@wb.to_xml_string)
|
|
46
54
|
errors = []
|
|
47
55
|
schema.validate(doc).each do |error|
|
|
48
56
|
errors.push error
|
|
@@ -60,9 +68,19 @@ class TestWorkbook < Test::Unit::TestCase
|
|
|
60
68
|
|
|
61
69
|
def test_to_xml_adds_worksheet_when_worksheets_is_empty
|
|
62
70
|
assert(@wb.worksheets.empty?)
|
|
63
|
-
@wb.
|
|
71
|
+
@wb.to_xml_string
|
|
64
72
|
assert(@wb.worksheets.size == 1)
|
|
65
73
|
end
|
|
66
74
|
|
|
67
75
|
|
|
76
|
+
def test_to_xml_string_defined_names
|
|
77
|
+
@wb.add_worksheet do |sheet|
|
|
78
|
+
sheet.add_row [1, "two"]
|
|
79
|
+
sheet.auto_filter = "A1:B1"
|
|
80
|
+
end
|
|
81
|
+
doc = Nokogiri::XML(@wb.to_xml_string)
|
|
82
|
+
assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].abs_auto_filter)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
|
|
68
86
|
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestTable < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
p = Axlsx::Package.new
|
|
6
|
+
@ws = p.workbook.add_worksheet
|
|
7
|
+
40.times do
|
|
8
|
+
@ws << ["aa","aa","aa","aa","aa","aa"]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_initialization
|
|
13
|
+
assert(@ws.workbook.tables.empty?)
|
|
14
|
+
assert(@ws.tables.empty?)
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_add_table
|
|
19
|
+
name = "test"
|
|
20
|
+
table = @ws.add_table("A1:D5", :name => name)
|
|
21
|
+
assert(table.is_a?(Axlsx::Table), "must create a table")
|
|
22
|
+
assert_equal(@ws.workbook.tables.last, table, "must be added to workbook table collection")
|
|
23
|
+
assert_equal(@ws.tables.last, table, "must be added to worksheet table collection")
|
|
24
|
+
assert_equal(table.name, name, "options for name are applied")
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_charts
|
|
29
|
+
assert(@ws.drawing.charts.empty?)
|
|
30
|
+
chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
|
|
31
|
+
assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
|
|
32
|
+
chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
|
|
33
|
+
assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_pn
|
|
37
|
+
table = @ws.add_table("A1:D5")
|
|
38
|
+
assert_equal(@ws.tables.first.pn, "tables/table1.xml")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_rId
|
|
42
|
+
table = @ws.add_table("A1:D5")
|
|
43
|
+
assert_equal(@ws.tables.first.rId, "rId1")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_index
|
|
47
|
+
table = @ws.add_table("A1:D5")
|
|
48
|
+
assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_relationships
|
|
52
|
+
assert(@ws.relationships.empty?)
|
|
53
|
+
table = @ws.add_table("A1:D5")
|
|
54
|
+
assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship")
|
|
55
|
+
table = @ws.add_table("F1:J5")
|
|
56
|
+
assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_to_xml_string
|
|
60
|
+
table = @ws.add_table("A1:D5")
|
|
61
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
62
|
+
doc = Nokogiri::XML(table.to_xml_string)
|
|
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
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'tc_helper.rb'
|
|
3
|
+
|
|
4
|
+
class TestTable < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
p = Axlsx::Package.new
|
|
7
|
+
@ws = p.workbook.add_worksheet
|
|
8
|
+
40.times do
|
|
9
|
+
@ws << ["aa","aa","aa","aa","aa","aa"]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_initialization
|
|
14
|
+
assert(@ws.workbook.tables.empty?)
|
|
15
|
+
assert(@ws.tables.empty?)
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_add_table
|
|
20
|
+
name = "test"
|
|
21
|
+
table = @ws.add_table("A1:D5", :name => name)
|
|
22
|
+
assert(table.is_a?(Axlsx::Table), "must create a table")
|
|
23
|
+
assert_equal(@ws.workbook.tables.last, table, "must be added to workbook table collection")
|
|
24
|
+
assert_equal(@ws.tables.last, table, "must be added to worksheet table collection")
|
|
25
|
+
assert_equal(table.name, name, "options for name are applied")
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_charts
|
|
30
|
+
assert(@ws.drawing.charts.empty?)
|
|
31
|
+
chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
|
|
32
|
+
assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
|
|
33
|
+
chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
|
|
34
|
+
assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_pn
|
|
38
|
+
table = @ws.add_table("A1:D5")
|
|
39
|
+
assert_equal(@ws.tables.first.pn, "tables/table1.xml")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_rId
|
|
43
|
+
table = @ws.add_table("A1:D5")
|
|
44
|
+
assert_equal(@ws.tables.first.rId, "rId1")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_index
|
|
48
|
+
table = @ws.add_table("A1:D5")
|
|
49
|
+
assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_relationships
|
|
53
|
+
assert(@ws.relationships.empty?)
|
|
54
|
+
table = @ws.add_table("A1:D5")
|
|
55
|
+
assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship")
|
|
56
|
+
table = @ws.add_table("F1:J5")
|
|
57
|
+
assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_to_xml
|
|
61
|
+
table = @ws.add_table("A1:D5")
|
|
62
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
63
|
+
doc = Nokogiri::XML(table.to_xml)
|
|
64
|
+
errors = []
|
|
65
|
+
schema.validate(doc).each do |error|
|
|
66
|
+
errors.push error
|
|
67
|
+
puts error.message
|
|
68
|
+
end
|
|
69
|
+
assert(errors.empty?, "error free validation")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|