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,30 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestXf < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@item = Axlsx::Xf.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialiation
|
14
|
+
assert_equal(@item.defaultTableStyle, "TableStyleMedium9")
|
15
|
+
assert_equal(@item.defaultPivotStyle, "PivotStyleLight16")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_defaultTableStyle
|
19
|
+
assert_raise(ArgumentError) { @item.defaultTableStyle = -1.1 }
|
20
|
+
assert_nothing_raised { @item.defaultTableStyle = "anyones guess" }
|
21
|
+
assert_equal(@item.defaultTableStyle, "anyones guess")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_defaultPivotStyle
|
25
|
+
assert_raise(ArgumentError) { @item.defaultPivotStyle = -1.1 }
|
26
|
+
assert_nothing_raised { @item.defaultPivotStyle = "anyones guess" }
|
27
|
+
assert_equal(@item.defaultPivotStyle, "anyones guess")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/tc_app.rb~
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestApp < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
def teardown
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_valid_document
|
11
|
+
schema = Nokogiri::XML::Schema(File.open("schema/shared-documentPropertiesExtended.xsd"))
|
12
|
+
doc = Nokogiri::XML(Axlsx::App.new.to_xml)
|
13
|
+
errors = []
|
14
|
+
schema.validate(doc).each do |error|
|
15
|
+
errors << error
|
16
|
+
end
|
17
|
+
assert_equal(errors.size, 0, "app.xml invalid" + errors.map{ |e| e.message }.to_s)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
|
11
|
+
def test_valid_document
|
12
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
13
|
+
doc = Nokogiri::XML(@styles.to_xml)
|
14
|
+
errors = []
|
15
|
+
schema.validate(doc).each do |error|
|
16
|
+
errors.push error
|
17
|
+
puts error.message
|
18
|
+
end
|
19
|
+
assert(errors.size == 0)
|
20
|
+
end
|
21
|
+
|
data/test/tc_package.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestPackage < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@package = Axlsx::Package.new
|
7
|
+
ws = @package.workbook.add_worksheet
|
8
|
+
chart = ws.add_chart Axlsx::Pie3DChart
|
9
|
+
chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_default_objects_are_created
|
13
|
+
assert(@package.instance_values["app"].is_a?(Axlsx::App), 'App object not created')
|
14
|
+
assert(@package.instance_values["core"].is_a?(Axlsx::Core), 'Core object not created')
|
15
|
+
assert(@package.workbook.is_a?(Axlsx::Workbook), 'Workbook object not created')
|
16
|
+
assert(Axlsx::Package.new.workbook.worksheets.size == 0, 'Workbook should not have sheets by default')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_serialization
|
20
|
+
fname = 'test_serialization.xlsx'
|
21
|
+
assert_nothing_raised do
|
22
|
+
if File.writable? fname
|
23
|
+
f = File.open(fname, 'w')
|
24
|
+
z= @package.serialize(f)
|
25
|
+
|
26
|
+
zf = Zip::ZipFile.open(f.path)
|
27
|
+
@package.send(:parts).each{ |part| zf.get_entry(part[:entry]) }
|
28
|
+
File.delete(f.path)
|
29
|
+
|
30
|
+
else
|
31
|
+
puts "Skipping serialization to disk as write permission is not granted to this use in this directory"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_validation
|
38
|
+
assert_equal(@package.validate.size, 0, @package.validate)
|
39
|
+
#how to test for failure? the internal validations on the models are so strict I cant break anthing.....
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_parts
|
43
|
+
p = @package.send(:parts)
|
44
|
+
p.each do |part|
|
45
|
+
#all parts must have :doc, :entry, :schema
|
46
|
+
assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
|
47
|
+
end
|
48
|
+
#all parts have an entry
|
49
|
+
assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing")
|
50
|
+
assert_equal(p.select{ |part| part[:entry] =~ /docProps\/core\.xml/ }.size, 1, "core missing")
|
51
|
+
assert_equal(p.select{ |part| part[:entry] =~ /docProps\/app\.xml/ }.size, 1, "app missing")
|
52
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/_rels\/workbook\.xml\.rels/ }.size, 1, "workbook rels missing")
|
53
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/workbook\.xml/ }.size, 1, "workbook missing")
|
54
|
+
assert_equal(p.select{ |part| part[:entry] =~ /\[Content_Types\]\.xml/ }.size, 1, "content types missing")
|
55
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/styles\.xml/ }.size, 1, "styles missin")
|
56
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/drawings\/_rels\/drawing\d\.xml\.rels/ }.size, @package.workbook.drawings.size, "one or more drawing rels missing")
|
57
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/drawings\/drawing\d\.xml/ }.size, @package.workbook.drawings.size, "one or more drawings missing")
|
58
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/charts\/chart\d\.xml/ }.size, @package.workbook.charts.size, "one or more charts missing")
|
59
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/sheet\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet missing")
|
60
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/_rels\/sheet\d\.xml\.rels/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing")
|
61
|
+
|
62
|
+
#no mystery parts
|
63
|
+
assert_equal(p.size, 12)
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_workbook_is_a_workbook
|
68
|
+
assert @package.workbook.is_a? Axlsx::Workbook
|
69
|
+
end
|
70
|
+
end
|
data/test/tc_package.rb~
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestPackage < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@package = Axlsx::Package.new
|
7
|
+
ws = @package.workbook.add_worksheet
|
8
|
+
chart = ws.add_chart Axlsx::Pie3DChart
|
9
|
+
chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_default_objects_are_created
|
13
|
+
assert(@package.instance_values["app"].is_a?(Axlsx::App), 'App object not created')
|
14
|
+
assert(@package.instance_values["core"].is_a?(Axlsx::Core), 'Core object not created')
|
15
|
+
assert(@package.workbook.is_a?(Axlsx::Workbook), 'Workbook object not created')
|
16
|
+
assert(Axlsx::Package.new.workbook.worksheets.size == 0, 'Workbook should not have sheets by default')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_serialization
|
20
|
+
fname = 'test_serialization.xlsx'
|
21
|
+
assert_nothing_raised do
|
22
|
+
f = File.open(fname, 'w')
|
23
|
+
z= @package.serialize(f)
|
24
|
+
|
25
|
+
zf = Zip::ZipFile.open(f.path)
|
26
|
+
@package.send(:parts).each{ |part| zf.get_entry(part[:entry]) }
|
27
|
+
File.delete(f.path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_validation
|
32
|
+
assert_equal(@package.validate.size, 0, @package.validate)
|
33
|
+
#how to test for failure? the internal validations on the models are so strict I cant break anthing.....
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_parts
|
37
|
+
p = @package.send(:parts)
|
38
|
+
p.each do |part|
|
39
|
+
#all parts must have :doc, :entry, :schema
|
40
|
+
assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
|
41
|
+
end
|
42
|
+
#all parts have an entry
|
43
|
+
assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing")
|
44
|
+
assert_equal(p.select{ |part| part[:entry] =~ /docProps\/core\.xml/ }.size, 1, "core missing")
|
45
|
+
assert_equal(p.select{ |part| part[:entry] =~ /docProps\/app\.xml/ }.size, 1, "app missing")
|
46
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/_rels\/workbook\.xml\.rels/ }.size, 1, "workbook rels missing")
|
47
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/workbook\.xml/ }.size, 1, "workbook missing")
|
48
|
+
assert_equal(p.select{ |part| part[:entry] =~ /\[Content_Types\]\.xml/ }.size, 1, "content types missing")
|
49
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/styles\.xml/ }.size, 1, "styles missin")
|
50
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/drawings\/_rels\/drawing\d\.xml\.rels/ }.size, @package.workbook.drawings.size, "one or more drawing rels missing")
|
51
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/drawings\/drawing\d\.xml/ }.size, @package.workbook.drawings.size, "one or more drawings missing")
|
52
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/charts\/chart\d\.xml/ }.size, @package.workbook.charts.size, "one or more charts missing")
|
53
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/sheet\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet missing")
|
54
|
+
assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/_rels\/sheet\d\.xml\.rels/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing")
|
55
|
+
|
56
|
+
#no mystery parts
|
57
|
+
assert_equal(p.size, 12)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_workbook_is_a_workbook
|
62
|
+
assert @package.workbook.is_a? Axlsx::Workbook
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestPie3DChart < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
p = Axlsx::Package.new
|
8
|
+
ws = p.workbook.add_worksheet
|
9
|
+
@row = ws.add_row :values=>["one", 1, Time.now]
|
10
|
+
@chart = ws.drawing.add_chart Axlsx::Pie3DChart, :title => "fishery"
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialization
|
17
|
+
assert_equal(@chart.workbook.charts.last,@chart, "the chart is in the workbook")
|
18
|
+
assert_equal(@chart.title.text, "fishery", "the title option has been applied")
|
19
|
+
assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_title
|
23
|
+
@chart.title.text = 'wowzer'
|
24
|
+
assert_equal(@chart.title.text, "wowzer", "the title text via a string")
|
25
|
+
assert_equal(@chart.title.cell, nil, "the title cell is nil as we set the title with text.")
|
26
|
+
@chart.title.cell = @row.cells.first
|
27
|
+
assert_equal(@chart.title.text, "one", "the title text was set via cell reference")
|
28
|
+
assert_equal(@chart.title.cell, @row.cells.first)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_series
|
32
|
+
s = @chart.add_series :data=>[0,1,2,3], :labels => ["one", 1, "anything"], :title=>"bob"
|
33
|
+
assert_equal(@chart.series.last, s, "series has been added to chart series collection")
|
34
|
+
assert_equal(s.title, "bob", "series title has been applied")
|
35
|
+
assert_equal(s.data, [0,1,2,3], "data option applied")
|
36
|
+
assert_equal(s.labels, ["one",1,"anything"], "labels option applied")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_create_range
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_pn
|
44
|
+
assert_equal(@chart.pn, "charts/chart1.xml")
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_rId
|
48
|
+
assert_equal(@chart.rId, "rId1")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_index
|
52
|
+
assert_equal(@chart.index, @chart.workbook.charts.index(@chart))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_xml
|
56
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
|
57
|
+
doc = Nokogiri::XML(@chart.to_xml)
|
58
|
+
errors = []
|
59
|
+
schema.validate(doc).each do |error|
|
60
|
+
errors.push error
|
61
|
+
puts error.message
|
62
|
+
end
|
63
|
+
assert(errors.empty?, "error free validation")
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestRelationships < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@rels = Axlsx::Relationships.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_valid_document
|
13
|
+
schema = Nokogiri::XML::Schema(File.open("schema/opc-relationships.xsd"))
|
14
|
+
doc = Nokogiri::XML(@rels.to_xml)
|
15
|
+
errors = []
|
16
|
+
schema.validate(doc).each do |error|
|
17
|
+
puts error.message
|
18
|
+
errors << error
|
19
|
+
end
|
20
|
+
|
21
|
+
@rels << Axlsx::Relationship.new(Axlsx::WORKSHEET_R, "bar")
|
22
|
+
doc = Nokogiri::XML(@rels.to_xml)
|
23
|
+
errors = []
|
24
|
+
schema.validate(doc).each do |error|
|
25
|
+
puts error.message
|
26
|
+
errors << error
|
27
|
+
end
|
28
|
+
|
29
|
+
assert(errors.size == 0)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_require_valid_relationship_type
|
33
|
+
assert_raise(ArgumentError) { Axlsx::Relationship.new("Unknown", "bar" ) }
|
34
|
+
assert_nothing_raised { Axlsx::Relationship.new(Axlsx::CHART_R, "bar") }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/test/tc_series.rb~
ADDED
@@ -0,0 +1,31 @@
|
|
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::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, "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
|
+
end
|
18
|
+
|
19
|
+
def test_range
|
20
|
+
labels = @ws.add_row :values=>["one", "two", "three"]
|
21
|
+
data = @ws.add_row :values=>[1,2,3]
|
22
|
+
s = @series.chart.add_series :data=>data.cells, :labels=>labels.cells
|
23
|
+
assert_equal(s.send(:range, s.data), "#{@ws.name}!$A$2:$C$2", "range is created created from cells")
|
24
|
+
assert_equal(s.send(:range, s.labels), "#{@ws.name}!$A$1:$C$1", "range is created from cells")
|
25
|
+
assert_equal(@series.send(:range, @series.data), "", "no range if the data is a simple array")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_index
|
29
|
+
assert_equal(@series.index, @series.chart.series.index(@series))
|
30
|
+
end
|
31
|
+
end
|
data/test/tc_styles.rb~
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestStyles < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@styles = Axlsx::Styles.new
|
7
|
+
end
|
8
|
+
def teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_valid_document
|
12
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
13
|
+
doc = Nokogiri::XML(@styles.to_xml)
|
14
|
+
errors = []
|
15
|
+
schema.validate(doc).each do |error|
|
16
|
+
errors.push error
|
17
|
+
puts error.message
|
18
|
+
end
|
19
|
+
assert(errors.size == 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def test_add_style
|
24
|
+
fill_count = @styles.fills.size
|
25
|
+
font_count = @styles.fonts.size
|
26
|
+
xf_count = @styles.cellXfs.size
|
27
|
+
|
28
|
+
@styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :numFmt=>Axlsx::NUM_FMT_PERCENT, :alignment=>{:horizontal=>:left}, :borderId=>Axlsx::BORDER_ID_ALL, :hidden=>true, :locked=>true
|
29
|
+
assert_equal(@styles.fills.size, fill_count+1)
|
30
|
+
assert_equal(@styles.fonts.size, font_count+1)
|
31
|
+
assert_equal(@styles.cellXfs.size, xf_count+1)
|
32
|
+
xf = @styles.cellXfs.last
|
33
|
+
assert_equal(xf.fillId, (@styles.fills.size-1), "points to the last created fill")
|
34
|
+
assert_equal(@styles.fills.last.fill_type.fgColor.rgb, "FF000000", "fill created with color")
|
35
|
+
|
36
|
+
assert_equal(xf.fontId, (@styles.fonts.size-1), "points to the last created font")
|
37
|
+
assert_equal(@styles.fonts.last.sz, 13, "font sz applied")
|
38
|
+
assert_equal(@styles.fonts.last.color.rgb, "FFFFFFFF", "font color applied")
|
39
|
+
|
40
|
+
assert_equal(xf.borderId, Axlsx::BORDER_ID_ALL, "border id is set")
|
41
|
+
assert_equal(xf.numFmtId, Axlsx::NUM_FMT_PERCENT, "number format id is set")
|
42
|
+
|
43
|
+
assert(xf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created")
|
44
|
+
assert_equal(xf.alignment.horizontal, :left, "horizontal alignment applied")
|
45
|
+
assert_equal(xf.applyProtection, 1, "protection applied")
|
46
|
+
assert_equal(xf.protection.hidden, true, "hidden protection set")
|
47
|
+
assert_equal(xf.protection.locked, true, "cell locking set")
|
48
|
+
assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :borderId => 2 }
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
#:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :dxfs, :tableStyles
|
54
|
+
def test_ensure_locking
|
55
|
+
assert_equal(@styles.numFmts.locked_at, 2, "numFmts should be locked at 2")
|
56
|
+
assert_equal(@styles.fonts.locked_at, 1, "fonts should be locked at 1" )
|
57
|
+
assert_equal(@styles.fills.locked_at, 2, "fills should be locked at 2" )
|
58
|
+
assert_equal(@styles.borders.locked_at, 2, "borders should be locked at two" )
|
59
|
+
assert_equal(@styles.cellStyleXfs.locked_at, 1, "cellStyleXfs should be locked at two" )
|
60
|
+
assert_equal(@styles.cellXfs.locked_at, 1, "cellXfs should be locked at 1" )
|
61
|
+
assert_equal(@styles.dxfs.locked_at, 0, "dxfs should be locked at 0" )
|
62
|
+
assert_equal(@styles.tableStyles.locked_at, 0, "tableStyles should be locked at 0" )
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'axlsx.rb'
|
4
|
+
class TestValidators < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
def teardown
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_validators
|
11
|
+
#unsigned_int
|
12
|
+
assert_nothing_raised { Axlsx.validate_unsigned_int 1 }
|
13
|
+
assert_nothing_raised { Axlsx.validate_unsigned_int +1 }
|
14
|
+
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int -1 }
|
15
|
+
assert_raise(ArgumentError) { Axlsx.validate_unsigned_int '1' }
|
16
|
+
|
17
|
+
#int
|
18
|
+
assert_nothing_raised { Axlsx.validate_int 1 }
|
19
|
+
assert_nothing_raised { Axlsx.validate_int -1 }
|
20
|
+
assert_raise(ArgumentError) { Axlsx.validate_int 'a' }
|
21
|
+
assert_raise(ArgumentError) { Axlsx.validate_int Array }
|
22
|
+
|
23
|
+
#boolean (as 0 or 1)
|
24
|
+
assert_nothing_raised { Axlsx.validate_boolean 0 }
|
25
|
+
assert_nothing_raised { Axlsx.validate_boolean 1 }
|
26
|
+
assert_raise(ArgumentError) { Axlsx.validate_boolean 2 }
|
27
|
+
assert_raise(ArgumentError) { Axlsx.validate_boolean false }
|
28
|
+
|
29
|
+
#string
|
30
|
+
assert_nothing_raised { Axlsx.validate_string "1" }
|
31
|
+
assert_raise(ArgumentError) { Axlsx.validate_string 2 }
|
32
|
+
assert_raise(ArgumentError) { Axlsx.validate_string false }
|
33
|
+
|
34
|
+
#float
|
35
|
+
assert_nothing_raised { Axlsx.validate_float 1.0 }
|
36
|
+
assert_raise(ArgumentError) { Axlsx.validate_float 2 }
|
37
|
+
assert_raise(ArgumentError) { Axlsx.validate_float false }
|
38
|
+
|
39
|
+
#pattern_type
|
40
|
+
assert_nothing_raised { Axlsx.validate_pattern_type :none }
|
41
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type "none" }
|
42
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type "crazy_pattern" }
|
43
|
+
assert_raise(ArgumentError) { Axlsx.validate_pattern_type false }
|
44
|
+
|
45
|
+
#gradient_type
|
46
|
+
assert_nothing_raised { Axlsx.validate_gradient_type :path }
|
47
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type nil }
|
48
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type "fractal" }
|
49
|
+
assert_raise(ArgumentError) { Axlsx.validate_gradient_type false }
|
50
|
+
|
51
|
+
#horizontal alignment
|
52
|
+
assert_nothing_raised { Axlsx.validate_horizontal_alignment :general }
|
53
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment nil }
|
54
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment "wavy" }
|
55
|
+
assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment false }
|
56
|
+
|
57
|
+
#vertical alignment
|
58
|
+
assert_nothing_raised { Axlsx.validate_vertical_alignment :top }
|
59
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment nil }
|
60
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment "dynamic" }
|
61
|
+
assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment false }
|
62
|
+
|
63
|
+
#contentType
|
64
|
+
assert_nothing_raised { Axlsx.validate_content_type Axlsx::WORKBOOK_CT }
|
65
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type nil }
|
66
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type "http://some.url" }
|
67
|
+
assert_raise(ArgumentError) { Axlsx.validate_content_type false }
|
68
|
+
|
69
|
+
#relationshipType
|
70
|
+
assert_nothing_raised { Axlsx.validate_relationship_type Axlsx::WORKBOOK_R }
|
71
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type nil }
|
72
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type "http://some.url" }
|
73
|
+
assert_raise(ArgumentError) { Axlsx.validate_relationship_type false }
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|