axlsx 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +13 -0
- data/lib/axlsx.rb +38 -0
- data/lib/axlsx/content_type/content_type.rb +23 -0
- data/lib/axlsx/content_type/default.rb +32 -0
- data/lib/axlsx/content_type/override.rb +30 -0
- data/lib/axlsx/doc_props/app.rb +148 -0
- data/lib/axlsx/doc_props/core.rb +34 -0
- data/lib/axlsx/drawing/axis.rb +78 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +138 -0
- data/lib/axlsx/drawing/bar_series.rb +91 -0
- data/lib/axlsx/drawing/cat_axis.rb +58 -0
- data/lib/axlsx/drawing/chart.rb +120 -0
- data/lib/axlsx/drawing/drawing.rb +121 -0
- data/lib/axlsx/drawing/graphic_frame.rb +55 -0
- data/lib/axlsx/drawing/marker.rb +57 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +59 -0
- data/lib/axlsx/drawing/pie_series.rb +88 -0
- data/lib/axlsx/drawing/scaling.rb +53 -0
- data/lib/axlsx/drawing/series.rb +70 -0
- data/lib/axlsx/drawing/title.rb +69 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +88 -0
- data/lib/axlsx/drawing/val_axis.rb +34 -0
- data/lib/axlsx/drawing/view_3D.rb +72 -0
- data/lib/axlsx/package.rb +181 -0
- data/lib/axlsx/rels/relationship.rb +43 -0
- data/lib/axlsx/rels/relationships.rb +25 -0
- data/lib/axlsx/stylesheet/border.rb +52 -0
- data/lib/axlsx/stylesheet/border_pr.rb +65 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +96 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +33 -0
- data/lib/axlsx/stylesheet/cell_style.rb +60 -0
- data/lib/axlsx/stylesheet/color.rb +57 -0
- data/lib/axlsx/stylesheet/fill.rb +31 -0
- data/lib/axlsx/stylesheet/font.rb +128 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +70 -0
- data/lib/axlsx/stylesheet/gradient_stop.rb +31 -0
- data/lib/axlsx/stylesheet/num_fmt.rb +61 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +64 -0
- data/lib/axlsx/stylesheet/styles.rb +296 -0
- data/lib/axlsx/stylesheet/table_style.rb +44 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +66 -0
- data/lib/axlsx/stylesheet/table_styles.rb +39 -0
- data/lib/axlsx/stylesheet/xf.rb +117 -0
- data/lib/axlsx/util/constants.rb +189 -0
- data/lib/axlsx/util/simple_typed_list.rb +150 -0
- data/lib/axlsx/util/validators.rb +132 -0
- data/lib/axlsx/workbook/workbook.rb +130 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +184 -0
- data/lib/axlsx/workbook/worksheet/row.rb +92 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +194 -0
- data/lib/schema/dc.xsd +118 -0
- data/lib/schema/dcmitype.xsd +50 -0
- data/lib/schema/dcterms.xsd +331 -0
- data/lib/schema/dml-chart.xsd +1499 -0
- data/lib/schema/dml-chartDrawing.xsd +146 -0
- data/lib/schema/dml-compatibility.xsd +14 -0
- data/lib/schema/dml-diagram.xsd +1091 -0
- data/lib/schema/dml-lockedCanvas.xsd +11 -0
- data/lib/schema/dml-main.xsd +3048 -0
- data/lib/schema/dml-picture.xsd +23 -0
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
- data/lib/schema/opc-contentTypes.xsd +42 -0
- data/lib/schema/opc-coreProperties.xsd +50 -0
- data/lib/schema/opc-digSig.xsd +49 -0
- data/lib/schema/opc-relationships.xsd +33 -0
- data/lib/schema/pml.xsd +1676 -0
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
- data/lib/schema/shared-bibliography.xsd +144 -0
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
- data/lib/schema/shared-math.xsd +582 -0
- data/lib/schema/shared-relationshipReference.xsd +25 -0
- data/lib/schema/sml.xsd +4430 -0
- data/lib/schema/vml-main.xsd +569 -0
- data/lib/schema/vml-officeDrawing.xsd +509 -0
- data/lib/schema/vml-presentationDrawing.xsd +12 -0
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
- data/lib/schema/wml.xsd +3644 -0
- data/lib/schema/xml.xsd +117 -0
- data/test/content_type/tc_content_type.rb +81 -0
- data/test/content_type/tc_content_type.rb~ +81 -0
- data/test/content_type/tc_default.rb +40 -0
- data/test/content_type/tc_default.rb~ +40 -0
- data/test/content_type/tc_override.rb +40 -0
- data/test/content_type/tc_override.rb~ +40 -0
- data/test/doc_props/tc_app.rb +19 -0
- data/test/doc_props/tc_app.rb~ +19 -0
- data/test/doc_props/tc_core.rb +34 -0
- data/test/drawing/tc_axis.rb +39 -0
- data/test/drawing/tc_axis.rb~ +0 -0
- data/test/drawing/tc_bar_3D_chart.rb +66 -0
- data/test/drawing/tc_bar_3D_chart.rb~ +4 -0
- data/test/drawing/tc_bar_series.rb +34 -0
- data/test/drawing/tc_bar_series.rb~ +31 -0
- data/test/drawing/tc_cat_axis.rb +32 -0
- data/test/drawing/tc_cat_axis.rb~ +39 -0
- data/test/drawing/tc_chart.rb +59 -0
- data/test/drawing/tc_chart.rb~ +58 -0
- data/test/drawing/tc_drawing.rb +71 -0
- data/test/drawing/tc_graphic_frame.rb +26 -0
- data/test/drawing/tc_graphic_frame.rb~ +21 -0
- data/test/drawing/tc_marker.rb +45 -0
- data/test/drawing/tc_marker.rb~ +26 -0
- data/test/drawing/tc_pie_3D_chart.rb +33 -0
- data/test/drawing/tc_pie_3D_chart.rb~ +58 -0
- data/test/drawing/tc_pie_series.rb +35 -0
- data/test/drawing/tc_pie_series.rb~ +26 -0
- data/test/drawing/tc_scaling.rb +37 -0
- data/test/drawing/tc_scaling.rb~ +45 -0
- data/test/drawing/tc_series.rb +24 -0
- data/test/drawing/tc_series.rb~ +31 -0
- data/test/drawing/tc_title.rb +34 -0
- data/test/drawing/tc_title.rb~ +37 -0
- data/test/drawing/tc_two_cell_anchor.rb +37 -0
- data/test/drawing/tc_two_cell_anchor.rb~ +35 -0
- data/test/drawing/tc_val_axis.rb +20 -0
- data/test/drawing/tc_val_axis.rb~ +32 -0
- data/test/drawing/tc_view_3D.rb +46 -0
- data/test/drawing/tc_view_3D.rb~ +37 -0
- data/test/rels/tc_relationship.rb +16 -0
- data/test/rels/tc_relationship.rb~ +39 -0
- data/test/rels/tc_relationships.rb +32 -0
- data/test/rels/tc_relationships.rb~ +37 -0
- data/test/stylesheet/tc_border.rb +38 -0
- data/test/stylesheet/tc_border.rb~ +31 -0
- data/test/stylesheet/tc_border_pr.rb +33 -0
- data/test/stylesheet/tc_border_pr.rb~ +31 -0
- data/test/stylesheet/tc_cell_alignment.rb +77 -0
- data/test/stylesheet/tc_cell_alignment.rb~ +38 -0
- data/test/stylesheet/tc_cell_protection.rb +30 -0
- data/test/stylesheet/tc_cell_protection.rb~ +77 -0
- data/test/stylesheet/tc_cell_style.rb +58 -0
- data/test/stylesheet/tc_cell_style.rb~ +30 -0
- data/test/stylesheet/tc_color.rb +38 -0
- data/test/stylesheet/tc_color.rb~ +38 -0
- data/test/stylesheet/tc_fill.rb +19 -0
- data/test/stylesheet/tc_fill.rb~ +19 -0
- data/test/stylesheet/tc_font.rb +114 -0
- data/test/stylesheet/tc_font.rb~ +19 -0
- data/test/stylesheet/tc_gradient_fill.rb +65 -0
- data/test/stylesheet/tc_gradient_fill.rb~ +114 -0
- data/test/stylesheet/tc_gradient_stop.rb +32 -0
- data/test/stylesheet/tc_gradient_stop.rb~ +65 -0
- data/test/stylesheet/tc_num_fmt.rb +31 -0
- data/test/stylesheet/tc_num_fmt.rb~ +32 -0
- data/test/stylesheet/tc_pattern_fill.rb +38 -0
- data/test/stylesheet/tc_pattern_fill.rb~ +31 -0
- data/test/stylesheet/tc_styles.rb +64 -0
- data/test/stylesheet/tc_table_style.rb +37 -0
- data/test/stylesheet/tc_table_style.rb~ +38 -0
- data/test/stylesheet/tc_table_style_element.rb +37 -0
- data/test/stylesheet/tc_table_style_element.rb~ +37 -0
- data/test/stylesheet/tc_table_styles.rb +30 -0
- data/test/stylesheet/tc_table_styles.rb~ +37 -0
- data/test/stylesheet/tc_xf.rb +121 -0
- data/test/stylesheet/tc_xf.rb~ +30 -0
- data/test/tc_app.rb~ +19 -0
- data/test/tc_border_pr.rb~ +21 -0
- data/test/tc_package.rb +70 -0
- data/test/tc_package.rb~ +64 -0
- data/test/tc_pie_3D_chart.rb~ +66 -0
- data/test/tc_relationships.rb~ +37 -0
- data/test/tc_series.rb~ +31 -0
- data/test/tc_styles.rb~ +64 -0
- data/test/tc_validators.rb~ +77 -0
- data/test/tc_worksheet.rb~ +85 -0
- data/test/util/tc_simple_typed_list.rb +66 -0
- data/test/util/tc_validators.rb +76 -0
- data/test/workbook/tc_workbook.rb +53 -0
- data/test/workbook/worksheet/tc_cell.rb +78 -0
- data/test/workbook/worksheet/tc_row.rb +30 -0
- data/test/workbook/worksheet/tc_worksheet.rb +85 -0
- metadata +378 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestWorksheet < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
@ws = p.workbook.add_worksheet
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_pn
|
11
|
+
assert_equal(@ws.pn, "worksheets/sheet1.xml")
|
12
|
+
ws = @ws.workbook.add_worksheet
|
13
|
+
assert_equal(ws.pn, "worksheets/sheet2.xml")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_rels_pn
|
17
|
+
assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels")
|
18
|
+
ws = @ws.workbook.add_worksheet
|
19
|
+
assert_equal(ws.rels_pn, "worksheets/_rels/sheet2.xml.rels")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_rId
|
23
|
+
assert_equal(@ws.rId, "rId1")
|
24
|
+
ws = @ws.workbook.add_worksheet
|
25
|
+
assert_equal(ws.rId, "rId2")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_index
|
29
|
+
assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_add_row
|
33
|
+
assert(@ws.rows.empty?, "sheet has no rows by default")
|
34
|
+
r = @ws.add_row([1,2,3])
|
35
|
+
assert_equal(@ws.rows.size, 1, "add_row adds a row")
|
36
|
+
assert_equal(@ws.rows.first, r, "the row returned is the row added")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_add_chart
|
40
|
+
assert(@ws.workbook.charts.empty?, "the sheet's workbook should not have any charts by default")
|
41
|
+
@ws.add_chart Axlsx::Pie3DChart
|
42
|
+
assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_drawing
|
46
|
+
assert @ws.drawing.is_a? Axlsx::Drawing
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_to_xml
|
51
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
52
|
+
doc = Nokogiri::XML(@ws.to_xml)
|
53
|
+
errors = []
|
54
|
+
schema.validate(doc).each do |error|
|
55
|
+
errors.push error
|
56
|
+
puts error.message
|
57
|
+
end
|
58
|
+
assert(errors.empty?, "error free validation")
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_relationships
|
62
|
+
assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
|
63
|
+
c = @ws.add_chart Axlsx::Pie3DChart
|
64
|
+
assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship")
|
65
|
+
c = @ws.add_chart Axlsx::Pie3DChart
|
66
|
+
assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_update_auto_with_data
|
71
|
+
small = @ws.workbook.styles.add_style(:sz=>2)
|
72
|
+
big = @ws.workbook.styles.add_style(:sz=>10)
|
73
|
+
@ws.add_row ["chasing windmills", "penut"], :style=>small
|
74
|
+
assert(@ws.auto_fit_data.size == 2, "a data item for each column")
|
75
|
+
assert_equal(@ws.auto_fit_data[0], {:sz=>2,:longest=>"chasing windmills"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
76
|
+
@ws.add_row ["mule"], :style=>big
|
77
|
+
assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_auto_width
|
81
|
+
assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size")
|
82
|
+
assert(@ws.send(:auto_width, {:sz=>12, :longest=>"fish"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "larger font size gets a longer auto_width using the same text")
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
class TestSimpleTypedList < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@list = Axlsx::SimpleTypedList.new Fixnum
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_type_is_a_class_or_array_of_class
|
12
|
+
assert_nothing_raised { Axlsx::SimpleTypedList.new Integer }
|
13
|
+
assert_nothing_raised { Axlsx::SimpleTypedList.new [Integer,String] }
|
14
|
+
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new }
|
15
|
+
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new "1" }
|
16
|
+
assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new [Integer, "Class"] }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_indexed_based_assignment
|
20
|
+
#should not allow nil assignment
|
21
|
+
assert_raise(ArgumentError) { @list[0] = nil }
|
22
|
+
assert_raise(ArgumentError) { @list[0] = "1" }
|
23
|
+
assert_nothing_raised { @list[0] = 1 }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_concat_assignment
|
27
|
+
assert_raise(ArgumentError) { @list << nil }
|
28
|
+
assert_raise(ArgumentError) { @list << "1" }
|
29
|
+
assert_nothing_raised { @list << 1 }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_concat_should_return_index
|
33
|
+
assert( @list.size == 0 )
|
34
|
+
assert( @list << 1 == 0 )
|
35
|
+
assert( @list << 2 == 1 )
|
36
|
+
@list.delete_at 0
|
37
|
+
assert( @list << 3 == 1 )
|
38
|
+
assert( @list.index(2) == 0 )
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_push_should_return_index
|
42
|
+
assert( @list.push(1) == 0 )
|
43
|
+
assert( @list.push(2) == 1 )
|
44
|
+
@list.delete_at 0
|
45
|
+
assert( @list.push(3) == 1 )
|
46
|
+
assert( @list.index(2) == 0 )
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_locking
|
50
|
+
@list.push 1
|
51
|
+
@list.push 2
|
52
|
+
@list.push 3
|
53
|
+
@list.lock
|
54
|
+
|
55
|
+
assert_raise(ArgumentError) { @list.delete 1 }
|
56
|
+
assert_raise(ArgumentError) { @list.delete_at 1 }
|
57
|
+
assert_raise(ArgumentError) { @list.delete_at 2 }
|
58
|
+
@list.push 4
|
59
|
+
assert_nothing_raised { @list.delete_at 3 }
|
60
|
+
@list.unlock
|
61
|
+
#ignore garbage
|
62
|
+
assert_nothing_raised { @list.delete 0 }
|
63
|
+
assert_nothing_raised { @list.delete 9 }
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
class TestValidators < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
def teardown
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_validators
|
10
|
+
#unsigned_int
|
11
|
+
assert_nothing_raised { Axlsx.validate_unsigned_int 1 }
|
12
|
+
assert_nothing_raised { Axlsx.validate_unsigned_int +1 }
|
13
|
+
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int -1 }
|
14
|
+
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int '1' }
|
15
|
+
|
16
|
+
#int
|
17
|
+
assert_nothing_raised { Axlsx.validate_int 1 }
|
18
|
+
assert_nothing_raised { Axlsx.validate_int -1 }
|
19
|
+
assert_raise(ArgumentError) { Axlsx.validate_int 'a' }
|
20
|
+
assert_raise(ArgumentError) { Axlsx.validate_int Array }
|
21
|
+
|
22
|
+
#boolean (as 0 or 1, :true, :false, true, false, or "true," "false")
|
23
|
+
[0,1,:true, :false, true, false, "true", "false"].each do |v|
|
24
|
+
assert_nothing_raised { Axlsx.validate_boolean 0 }
|
25
|
+
end
|
26
|
+
assert_raise(ArgumentError) { Axlsx.validate_boolean 2 }
|
27
|
+
|
28
|
+
#string
|
29
|
+
assert_nothing_raised { Axlsx.validate_string "1" }
|
30
|
+
assert_raise(ArgumentError) { Axlsx.validate_string 2 }
|
31
|
+
assert_raise(ArgumentError) { Axlsx.validate_string false }
|
32
|
+
|
33
|
+
#float
|
34
|
+
assert_nothing_raised { Axlsx.validate_float 1.0 }
|
35
|
+
assert_raise(ArgumentError) { Axlsx.validate_float 2 }
|
36
|
+
assert_raise(ArgumentError) { Axlsx.validate_float false }
|
37
|
+
|
38
|
+
#pattern_type
|
39
|
+
assert_nothing_raised { Axlsx.validate_pattern_type :none }
|
40
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type "none" }
|
41
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type "crazy_pattern" }
|
42
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type false }
|
43
|
+
|
44
|
+
#gradient_type
|
45
|
+
assert_nothing_raised { Axlsx.validate_gradient_type :path }
|
46
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type nil }
|
47
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type "fractal" }
|
48
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type false }
|
49
|
+
|
50
|
+
#horizontal alignment
|
51
|
+
assert_nothing_raised { Axlsx.validate_horizontal_alignment :general }
|
52
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment nil }
|
53
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment "wavy" }
|
54
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment false }
|
55
|
+
|
56
|
+
#vertical alignment
|
57
|
+
assert_nothing_raised { Axlsx.validate_vertical_alignment :top }
|
58
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment nil }
|
59
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment "dynamic" }
|
60
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment false }
|
61
|
+
|
62
|
+
#contentType
|
63
|
+
assert_nothing_raised { Axlsx.validate_content_type Axlsx::WORKBOOK_CT }
|
64
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type nil }
|
65
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type "http://some.url" }
|
66
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type false }
|
67
|
+
|
68
|
+
#relationshipType
|
69
|
+
assert_nothing_raised { Axlsx.validate_relationship_type Axlsx::WORKBOOK_R }
|
70
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type nil }
|
71
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type "http://some.url" }
|
72
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type false }
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestWorkbook < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
@wb = p.workbook
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_date1904
|
14
|
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
15
|
+
@wb.date1904 = :false
|
16
|
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
17
|
+
Axlsx::Workbook.date1904 = :true
|
18
|
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_add_worksheet
|
22
|
+
assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
|
23
|
+
ws = @wb.add_worksheet(:name=>"bob")
|
24
|
+
assert_equal(@wb.worksheets.size, 1, "add_worksheet adds a worksheet!")
|
25
|
+
assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
|
26
|
+
assert_equal(ws.name, "bob", "name option gets passed to worksheet")
|
27
|
+
end
|
28
|
+
def test_relationships
|
29
|
+
#current relationship size is 1 due to style relation
|
30
|
+
assert(@wb.relationships.size == 1)
|
31
|
+
@wb.add_worksheet
|
32
|
+
assert(@wb.relationships.size == 2)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_to_xml
|
36
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
37
|
+
doc = Nokogiri::XML(@wb.to_xml)
|
38
|
+
errors = []
|
39
|
+
schema.validate(doc).each do |error|
|
40
|
+
errors.push error
|
41
|
+
puts error.message
|
42
|
+
end
|
43
|
+
assert(errors.empty?, "error free validation")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_to_xml_adds_worksheet_when_worksheets_is_empty
|
47
|
+
assert(@wb.worksheets.empty?)
|
48
|
+
@wb.to_xml
|
49
|
+
assert(@wb.worksheets.size == 1)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestCell < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
p = Axlsx::Package.new
|
8
|
+
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
9
|
+
p.workbook.styles.add_style :sz=>20
|
10
|
+
@row = @ws.add_row
|
11
|
+
@c = @row.add_cell 1, :type=>:float, :style=>1
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialize
|
15
|
+
assert_equal(@row.cells.last, @c, "the cell was added to the row")
|
16
|
+
assert_equal(@c.type, :float, "type option is applied")
|
17
|
+
assert_equal(@c.style, 1, "style option is applied")
|
18
|
+
assert_equal(@c.value, 1.0, "type option is applied and value is casted")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_index
|
22
|
+
assert_equal(@c.index, @row.cells.index(@c))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_r
|
26
|
+
assert_equal(@c.r, "A1", "calculate cell reference")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_r_abs
|
30
|
+
assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_style
|
34
|
+
assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style=3 }
|
35
|
+
assert_nothing_raised("must allow valid style index changes") {@c.style=1}
|
36
|
+
assert_equal(@c.style, 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_type
|
40
|
+
assert_raise(ArgumentError, "type must be :string, :integer, :float, :time") { @c.type = :array }
|
41
|
+
assert_nothing_raised("type can be changed") { @c.type = :string }
|
42
|
+
assert_equal(@c.value, "1.0", "changing type casts the value")
|
43
|
+
|
44
|
+
assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_value
|
48
|
+
assert_raise(ArgumentError, "type must be :string, :integer, :float, :time") { @c.type = :array }
|
49
|
+
assert_nothing_raised("type can be changed") { @c.type = :string }
|
50
|
+
assert_equal(@c.value, "1.0", "changing type casts the value")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_col_ref
|
54
|
+
assert_equal(@c.send(:col_ref), "A")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_cell_type_from_value
|
58
|
+
assert_equal(@c.send(:cell_type_from_value, 1.0), :float)
|
59
|
+
assert_equal(@c.send(:cell_type_from_value, 1), :integer)
|
60
|
+
assert_equal(@c.send(:cell_type_from_value, Time.now), :time)
|
61
|
+
assert_equal(@c.send(:cell_type_from_value, []), :string)
|
62
|
+
assert_equal(@c.send(:cell_type_from_value, "d"), :string)
|
63
|
+
assert_equal(@c.send(:cell_type_from_value, nil), :string)
|
64
|
+
assert_equal(@c.send(:cell_type_from_value, -1), :integer)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_cast_value
|
68
|
+
@c.type = :string
|
69
|
+
assert_equal(@c.send(:cast_value, 1.0), "1.0")
|
70
|
+
@c.type = :integer
|
71
|
+
assert_equal(@c.send(:cast_value, 1.0), 1)
|
72
|
+
@c.type = :float
|
73
|
+
assert_equal(@c.send(:cast_value, "1.0"), 1.0)
|
74
|
+
@c.type = :string
|
75
|
+
assert_equal(@c.send(:cast_value, nil), "")
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestRow < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
p = Axlsx::Package.new
|
8
|
+
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
9
|
+
@row = @ws.add_row
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initialize
|
13
|
+
assert(@row.cells.empty?, "no cells by default")
|
14
|
+
assert_equal(@row.worksheet, @ws, "has a reference to the worksheet")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_index
|
18
|
+
assert_equal(@row.index, @row.worksheet.rows.index(@row))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_add_cell
|
22
|
+
c = @row.add_cell(1)
|
23
|
+
assert_equal(@row.cells.last, c)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_array_to_cells
|
27
|
+
r = @ws.add_row :values=>[1,2,3], :style=>0, :types=>:integer
|
28
|
+
assert_equal(r.cells.size, 3)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestWorksheet < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
@ws = p.workbook.add_worksheet
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_pn
|
11
|
+
assert_equal(@ws.pn, "worksheets/sheet1.xml")
|
12
|
+
ws = @ws.workbook.add_worksheet
|
13
|
+
assert_equal(ws.pn, "worksheets/sheet2.xml")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_rels_pn
|
17
|
+
assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels")
|
18
|
+
ws = @ws.workbook.add_worksheet
|
19
|
+
assert_equal(ws.rels_pn, "worksheets/_rels/sheet2.xml.rels")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_rId
|
23
|
+
assert_equal(@ws.rId, "rId1")
|
24
|
+
ws = @ws.workbook.add_worksheet
|
25
|
+
assert_equal(ws.rId, "rId2")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_index
|
29
|
+
assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_add_row
|
33
|
+
assert(@ws.rows.empty?, "sheet has no rows by default")
|
34
|
+
r = @ws.add_row(:values=>[1,2,3])
|
35
|
+
assert_equal(@ws.rows.size, 1, "add_row adds a row")
|
36
|
+
assert_equal(@ws.rows.first, r, "the row returned is the row added")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_add_chart
|
40
|
+
assert(@ws.workbook.charts.empty?, "the sheet's workbook should not have any charts by default")
|
41
|
+
@ws.add_chart Axlsx::Pie3DChart
|
42
|
+
assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_drawing
|
46
|
+
assert @ws.drawing.is_a? Axlsx::Drawing
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_to_xml
|
51
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
52
|
+
doc = Nokogiri::XML(@ws.to_xml)
|
53
|
+
errors = []
|
54
|
+
schema.validate(doc).each do |error|
|
55
|
+
errors.push error
|
56
|
+
puts error.message
|
57
|
+
end
|
58
|
+
assert(errors.empty?, "error free validation")
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_relationships
|
62
|
+
assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
|
63
|
+
c = @ws.add_chart Axlsx::Pie3DChart
|
64
|
+
assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship")
|
65
|
+
c = @ws.add_chart Axlsx::Pie3DChart
|
66
|
+
assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_update_auto_with_data
|
71
|
+
small = @ws.workbook.styles.add_style(:sz=>2)
|
72
|
+
big = @ws.workbook.styles.add_style(:sz=>10)
|
73
|
+
@ws.add_row :values=>["chasing windmills", "penut"], :style=>small
|
74
|
+
assert(@ws.auto_fit_data.size == 2, "a data item for each column")
|
75
|
+
assert_equal(@ws.auto_fit_data[0], {:sz=>2,:longest=>"chasing windmills"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
76
|
+
@ws.add_row :values=> ["mule"], :style=>big
|
77
|
+
assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_auto_width
|
81
|
+
assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size")
|
82
|
+
assert(@ws.send(:auto_width, {:sz=>12, :longest=>"fish"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "larger font size gets a longer auto_width using the same text")
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|