axlsx 1.0.16 → 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/.yardopts +1 -0
- data/CHANGELOG.md +18 -3
- data/README.md +189 -55
- data/examples/example.csv +1000 -0
- data/examples/example.rb +264 -142
- 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/content_type/content_type.rb +13 -12
- data/lib/axlsx/content_type/default.rb +10 -6
- data/lib/axlsx/content_type/override.rb +13 -8
- data/lib/axlsx/doc_props/app.rb +38 -41
- data/lib/axlsx/doc_props/core.rb +13 -17
- data/lib/axlsx/drawing/axis.rb +39 -19
- data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
- data/lib/axlsx/drawing/bar_series.rb +14 -14
- data/lib/axlsx/drawing/cat_axis.rb +16 -14
- data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
- data/lib/axlsx/drawing/chart.rb +40 -41
- data/lib/axlsx/drawing/drawing.rb +16 -12
- data/lib/axlsx/drawing/graphic_frame.rb +22 -21
- data/lib/axlsx/drawing/hyperlink.rb +13 -12
- data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
- data/lib/axlsx/drawing/line_series.rb +12 -11
- data/lib/axlsx/drawing/marker.rb +11 -8
- data/lib/axlsx/drawing/named_axis_data.rb +36 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
- data/lib/axlsx/drawing/pic.rb +26 -38
- data/lib/axlsx/drawing/picture_locking.rb +22 -18
- data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
- data/lib/axlsx/drawing/pie_series.rb +16 -12
- data/lib/axlsx/drawing/scaling.rb +11 -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 +11 -10
- data/lib/axlsx/drawing/series.rb +16 -15
- data/lib/axlsx/drawing/series_title.rb +15 -14
- data/lib/axlsx/drawing/title.rb +27 -26
- data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
- data/lib/axlsx/drawing/val_axis.rb +9 -7
- data/lib/axlsx/drawing/val_axis_data.rb +18 -17
- data/lib/axlsx/drawing/view_3D.rb +23 -20
- data/lib/axlsx/package.rb +116 -51
- data/lib/axlsx/rels/relationship.rb +12 -8
- data/lib/axlsx/rels/relationships.rb +8 -1
- data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
- data/lib/axlsx/stylesheet/border.rb +28 -23
- data/lib/axlsx/stylesheet/border_pr.rb +17 -15
- data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
- data/lib/axlsx/stylesheet/cell_style.rb +9 -5
- data/lib/axlsx/stylesheet/color.rb +21 -14
- data/lib/axlsx/stylesheet/fill.rb +8 -5
- data/lib/axlsx/stylesheet/font.rb +22 -14
- data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
- data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
- data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
- data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
- data/lib/axlsx/stylesheet/styles.rb +53 -41
- data/lib/axlsx/stylesheet/table_style.rb +10 -4
- data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
- data/lib/axlsx/stylesheet/table_styles.rb +12 -8
- data/lib/axlsx/stylesheet/xf.rb +30 -25
- data/lib/axlsx/util/cbf.rb +1 -0
- data/lib/axlsx/util/constants.rb +27 -14
- data/lib/axlsx/util/ms_off_crypto.rb +1 -1
- data/lib/axlsx/util/parser.rb +1 -0
- data/lib/axlsx/util/simple_typed_list.rb +20 -10
- data/lib/axlsx/util/storage.rb +1 -0
- data/lib/axlsx/util/validators.rb +23 -7
- data/lib/axlsx/version.rb +2 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +69 -0
- data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
- data/lib/axlsx/workbook/workbook.rb +81 -35
- data/lib/axlsx/workbook/worksheet/cell.rb +172 -117
- data/lib/axlsx/workbook/worksheet/col.rb +114 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
- data/lib/axlsx/workbook/worksheet/row.rb +53 -21
- data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
- 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 +269 -121
- data/lib/axlsx.rb +41 -14
- 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 +31 -31
- data/test/content_type/tc_default.rb +9 -22
- data/test/content_type/tc_override.rb +8 -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 +13 -14
- 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 +10 -6
- 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 +12 -5
- 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 +16 -6
- 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 +43 -9
- 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 +38 -0
- data/test/workbook/tc_workbook.rb +32 -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 +70 -13
- 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 +126 -0
- data/test/workbook/worksheet/tc_page_margins.rb +97 -0
- data/test/workbook/worksheet/tc_row.rb +54 -4
- data/test/workbook/worksheet/tc_worksheet.rb +191 -31
- metadata +162 -109
- data/test/drawing/tc_hyperlink.rb~ +0 -71
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'tc_helper.rb'
|
|
3
|
+
|
|
4
|
+
class TestDateTimeConverter < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
@margin_of_error = 0.000_001
|
|
7
|
+
@extended_time_range = begin
|
|
8
|
+
Time.parse "1893-08-05"
|
|
9
|
+
Time.parse "9999-12-31T23:59:59Z"
|
|
10
|
+
true
|
|
11
|
+
rescue
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_date_to_serial_1900
|
|
17
|
+
Axlsx::Workbook.date1904 = false
|
|
18
|
+
tests = if @extended_time_range
|
|
19
|
+
{ # examples taken straight from the spec
|
|
20
|
+
"1893-08-05" => -2338.0,
|
|
21
|
+
"1900-01-01" => 2.0,
|
|
22
|
+
"1910-02-03" => 3687.0,
|
|
23
|
+
"2006-02-01" => 38749.0,
|
|
24
|
+
"9999-12-31" => 2958465.0
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
{ # examples taken inside the possible values
|
|
28
|
+
"1970-01-01" => 25569.0, # Unix epoch
|
|
29
|
+
"1970-01-02" => 25570.0,
|
|
30
|
+
"2006-02-01" => 38749.0,
|
|
31
|
+
"2038-01-19" => 50424.0, # max date using signed timestamp in 32bit
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
tests.each do |date_string, expected|
|
|
35
|
+
serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string)
|
|
36
|
+
assert_equal expected, serial
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_date_to_serial_1904
|
|
41
|
+
Axlsx::Workbook.date1904 = true
|
|
42
|
+
tests = if @extended_time_range
|
|
43
|
+
{ # examples taken straight from the spec
|
|
44
|
+
"1893-08-05" => -3800.0,
|
|
45
|
+
"1904-01-01" => 0.0,
|
|
46
|
+
"1910-02-03" => 2225.0,
|
|
47
|
+
"2006-02-01" => 37287.0,
|
|
48
|
+
"9999-12-31" => 2957003.0
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
{ # examples taken inside the possible values
|
|
52
|
+
"1970-01-01" => 24107.0, # Unix epoch
|
|
53
|
+
"1970-01-02" => 24108.0,
|
|
54
|
+
"2006-02-01" => 37287.0,
|
|
55
|
+
"2038-01-19" => 48962.0, # max date using signed timestamp in 32bit
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
tests.each do |date_string, expected|
|
|
59
|
+
serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string)
|
|
60
|
+
assert_equal expected, serial
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_time_to_serial_1900
|
|
65
|
+
Axlsx::Workbook.date1904 = false
|
|
66
|
+
tests = if @extended_time_range
|
|
67
|
+
{ # examples taken straight from the spec
|
|
68
|
+
"1893-08-05T00:00:01Z" => -2337.999989,
|
|
69
|
+
"1899-12-28T18:00:00Z" => -1.25,
|
|
70
|
+
"1910-02-03T10:05:54Z" => 3687.4207639,
|
|
71
|
+
"1900-01-01T12:00:00Z" => 2.5, # wrongly indicated as 1.5 in the spec!
|
|
72
|
+
"9999-12-31T23:59:59Z" => 2958465.9999884
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
{ # examples taken inside the possible values
|
|
76
|
+
"1970-01-01T00:00:00Z" => 25569.0, # Unix epoch
|
|
77
|
+
"1970-01-01T12:00:00Z" => 25569.5,
|
|
78
|
+
"2000-01-01T00:00:00Z" => 36526.0,
|
|
79
|
+
"2038-01-19T03:14:07Z" => 50424.134803, # max signed timestamp in 32bit
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
tests.each do |time_string, expected|
|
|
83
|
+
serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string)
|
|
84
|
+
assert_in_delta expected, serial, @margin_of_error
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_time_to_serial_1904
|
|
89
|
+
Axlsx::Workbook.date1904 = true
|
|
90
|
+
# ruby 1.8.7 cannot parse dates prior to epoch. see http://ruby-doc.org/core-1.8.7/Time.html
|
|
91
|
+
|
|
92
|
+
tests = if @extended_time_range
|
|
93
|
+
{ # examples taken straight from the spec
|
|
94
|
+
"1893-08-05T00:00:01Z" => -3799.999989,
|
|
95
|
+
"1910-02-03T10:05:54Z" => 2225.4207639,
|
|
96
|
+
"1904-01-01T12:00:00Z" => 0.5000000,
|
|
97
|
+
"9999-12-31T23:59:59Z" => 2957003.9999884
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
{ # examples taken inside the possible values
|
|
101
|
+
"1970-01-01T00:00:00Z" => 24107.0, # Unix epoch
|
|
102
|
+
"1970-01-01T12:00:00Z" => 24107.5,
|
|
103
|
+
"2000-01-01T00:00:00Z" => 35064.0,
|
|
104
|
+
"2038-01-19T03:14:07Z" => 48962.134803, # max signed timestamp in 32bit
|
|
105
|
+
}
|
|
106
|
+
end
|
|
107
|
+
tests.each do |time_string, expected|
|
|
108
|
+
serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string)
|
|
109
|
+
assert_in_delta expected, serial, @margin_of_error
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_timezone
|
|
114
|
+
utc = Time.utc 2012 # January 1st, 2012 at 0:00 UTC
|
|
115
|
+
local = begin
|
|
116
|
+
Time.new 2012, 1, 1, 1, 0, 0, 3600 # January 1st, 2012 at 1:00 GMT+1
|
|
117
|
+
rescue ArgumentError
|
|
118
|
+
Time.parse "2012-01-01 01:00:00 +0100"
|
|
119
|
+
end
|
|
120
|
+
assert_equal local, utc
|
|
121
|
+
assert_equal Axlsx::DateTimeConverter::time_to_serial(local), Axlsx::DateTimeConverter::time_to_serial(utc)
|
|
122
|
+
Axlsx::Workbook.date1904 = true
|
|
123
|
+
assert_equal Axlsx::DateTimeConverter::time_to_serial(local), Axlsx::DateTimeConverter::time_to_serial(utc)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestPageMargins < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
p = Axlsx::Package.new
|
|
7
|
+
ws = p.workbook.add_worksheet :name=>"hmmm"
|
|
8
|
+
@pm = ws.page_margins
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_initialize
|
|
12
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_LEFT_RIGHT, @pm.left)
|
|
13
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_LEFT_RIGHT, @pm.right)
|
|
14
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.top)
|
|
15
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.bottom)
|
|
16
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_HEADER_FOOTER, @pm.header)
|
|
17
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_HEADER_FOOTER, @pm.footer)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_initialize_with_options
|
|
21
|
+
optioned = Axlsx::PageMargins.new(:left => 2, :right => 3, :top => 2, :bottom => 1, :header => 0.1, :footer => 0.1)
|
|
22
|
+
assert_equal(2, optioned.left)
|
|
23
|
+
assert_equal(3, optioned.right)
|
|
24
|
+
assert_equal(2, optioned.top)
|
|
25
|
+
assert_equal(1, optioned.bottom)
|
|
26
|
+
assert_equal(0.1, optioned.header)
|
|
27
|
+
assert_equal(0.1, optioned.footer)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_set_all_values
|
|
32
|
+
@pm.set(:left => 1.1, :right => 1.2, :top => 1.3, :bottom => 1.4, :header => 0.8, :footer => 0.9)
|
|
33
|
+
assert_equal(1.1, @pm.left)
|
|
34
|
+
assert_equal(1.2, @pm.right)
|
|
35
|
+
assert_equal(1.3, @pm.top)
|
|
36
|
+
assert_equal(1.4, @pm.bottom)
|
|
37
|
+
assert_equal(0.8, @pm.header)
|
|
38
|
+
assert_equal(0.9, @pm.footer)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_set_some_values
|
|
42
|
+
@pm.set(:left => 1.1, :right => 1.2)
|
|
43
|
+
assert_equal(1.1, @pm.left)
|
|
44
|
+
assert_equal(1.2, @pm.right)
|
|
45
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.top)
|
|
46
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.bottom)
|
|
47
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_HEADER_FOOTER, @pm.header)
|
|
48
|
+
assert_equal(Axlsx::PageMargins::DEFAULT_HEADER_FOOTER, @pm.footer)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_to_xml
|
|
52
|
+
@pm.left = 1.1
|
|
53
|
+
@pm.right = 1.2
|
|
54
|
+
@pm.top = 1.3
|
|
55
|
+
@pm.bottom = 1.4
|
|
56
|
+
@pm.header = 0.8
|
|
57
|
+
@pm.footer = 0.9
|
|
58
|
+
doc = Nokogiri::XML.parse(@pm.to_xml_string)
|
|
59
|
+
assert_equal(1, doc.xpath(".//pageMargins[@left=1.1][@right=1.2][@top=1.3][@bottom=1.4][@header=0.8][@footer=0.9]").size)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_left
|
|
63
|
+
assert_raise(ArgumentError) { @pm.left = -1.2 }
|
|
64
|
+
assert_nothing_raised { @pm.left = 1.5 }
|
|
65
|
+
assert_equal(@pm.left, 1.5)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_right
|
|
69
|
+
assert_raise(ArgumentError) { @pm.right = -1.2 }
|
|
70
|
+
assert_nothing_raised { @pm.right = 1.5 }
|
|
71
|
+
assert_equal(@pm.right, 1.5)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_top
|
|
75
|
+
assert_raise(ArgumentError) { @pm.top = -1.2 }
|
|
76
|
+
assert_nothing_raised { @pm.top = 1.5 }
|
|
77
|
+
assert_equal(@pm.top, 1.5)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_bottom
|
|
81
|
+
assert_raise(ArgumentError) { @pm.bottom = -1.2 }
|
|
82
|
+
assert_nothing_raised { @pm.bottom = 1.5 }
|
|
83
|
+
assert_equal(@pm.bottom, 1.5)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_header
|
|
87
|
+
assert_raise(ArgumentError) { @pm.header = -1.2 }
|
|
88
|
+
assert_nothing_raised { @pm.header = 1.5 }
|
|
89
|
+
assert_equal(@pm.header, 1.5)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_footer
|
|
93
|
+
assert_raise(ArgumentError) { @pm.footer = -1.2 }
|
|
94
|
+
assert_nothing_raised { @pm.footer = 1.5 }
|
|
95
|
+
assert_equal(@pm.footer, 1.5)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
|
|
4
3
|
class TestRow < Test::Unit::TestCase
|
|
5
4
|
|
|
@@ -8,16 +7,37 @@ class TestRow < Test::Unit::TestCase
|
|
|
8
7
|
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
|
9
8
|
@row = @ws.add_row
|
|
10
9
|
end
|
|
11
|
-
|
|
10
|
+
|
|
12
11
|
def test_initialize
|
|
13
12
|
assert(@row.cells.empty?, "no cells by default")
|
|
14
13
|
assert_equal(@row.worksheet, @ws, "has a reference to the worksheet")
|
|
14
|
+
assert_nil(@row.height, "height defaults to nil")
|
|
15
|
+
assert(!@row.custom_height?, "no custom height by default")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_initialize_with_fixed_height
|
|
19
|
+
row = @ws.add_row([1,2,3,4,5], :height=>40)
|
|
20
|
+
assert_equal(40, row.height)
|
|
21
|
+
assert(row.custom_height?)
|
|
15
22
|
end
|
|
16
23
|
|
|
17
24
|
def test_style
|
|
18
25
|
r = @ws.add_row([1,2,3,4,5])
|
|
19
26
|
r.style=1
|
|
20
|
-
r.cells.each { |c| assert_equal(c.style,1) }
|
|
27
|
+
r.cells.each { |c| assert_equal(c.style,1) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_nil_cells
|
|
31
|
+
row = @ws.add_row([nil,1,2,nil,4,5,nil])
|
|
32
|
+
r_s_xml = Nokogiri::XML(row.to_xml_string(0, ''))
|
|
33
|
+
assert_equal(r_s_xml.xpath(".//row/c").size, 4)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_nil_cell_r
|
|
37
|
+
row = @ws.add_row([nil,1,2,nil,4,5,nil])
|
|
38
|
+
r_s_xml = Nokogiri::XML(row.to_xml_string(0, ''))
|
|
39
|
+
assert_equal(r_s_xml.xpath(".//row/c").first['r'], 'B1')
|
|
40
|
+
assert_equal(r_s_xml.xpath(".//row/c").last['r'], 'F1')
|
|
21
41
|
end
|
|
22
42
|
|
|
23
43
|
def test_index
|
|
@@ -33,4 +53,34 @@ class TestRow < Test::Unit::TestCase
|
|
|
33
53
|
r = @ws.add_row [1,2,3], :style=>0, :types=>:integer
|
|
34
54
|
assert_equal(r.cells.size, 3)
|
|
35
55
|
end
|
|
56
|
+
|
|
57
|
+
def test_custom_height
|
|
58
|
+
@row.height = 20
|
|
59
|
+
assert(@row.custom_height?)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_height
|
|
63
|
+
assert_raise(ArgumentError) { @row.height = -3 }
|
|
64
|
+
assert_nothing_raised { @row.height = 15 }
|
|
65
|
+
assert_equal(15, @row.height)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_to_xml_without_custom_height
|
|
69
|
+
doc = Nokogiri::XML.parse(@row.to_xml_string(0))
|
|
70
|
+
assert_equal(0, doc.xpath(".//row[@ht]").size)
|
|
71
|
+
assert_equal(0, doc.xpath(".//row[@customHeight]").size)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_to_xml_string
|
|
75
|
+
r_s_xml = Nokogiri::XML(@row.to_xml_string(0, ''))
|
|
76
|
+
assert_equal(r_s_xml.xpath(".//row[@r=1]").size, 1)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_to_xml_string_with_custom_height
|
|
80
|
+
@row.add_cell 1
|
|
81
|
+
@row.height = 20
|
|
82
|
+
r_s_xml = Nokogiri::XML(@row.to_xml_string(0, ''))
|
|
83
|
+
assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size, 1)
|
|
84
|
+
end
|
|
85
|
+
|
|
36
86
|
end
|
|
@@ -1,18 +1,63 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'axlsx.rb'
|
|
1
|
+
require 'tc_helper.rb'
|
|
3
2
|
|
|
4
3
|
class TestWorksheet < Test::Unit::TestCase
|
|
5
|
-
def setup
|
|
6
|
-
p = Axlsx::Package.new
|
|
7
|
-
@
|
|
4
|
+
def setup
|
|
5
|
+
@p = Axlsx::Package.new
|
|
6
|
+
@wb = @p.workbook
|
|
7
|
+
@ws = @wb.add_worksheet
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
def test_pn
|
|
11
12
|
assert_equal(@ws.pn, "worksheets/sheet1.xml")
|
|
12
13
|
ws = @ws.workbook.add_worksheet
|
|
13
14
|
assert_equal(ws.pn, "worksheets/sheet2.xml")
|
|
14
15
|
end
|
|
15
16
|
|
|
17
|
+
def test_page_margins
|
|
18
|
+
assert(@ws.page_margins.is_a? Axlsx::PageMargins)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_page_margins_yeild
|
|
22
|
+
@ws.page_margins do |pm|
|
|
23
|
+
assert(pm.is_a? Axlsx::PageMargins)
|
|
24
|
+
assert(@ws.page_margins == pm)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_no_autowidth
|
|
29
|
+
@ws.workbook.use_autowidth = false
|
|
30
|
+
@ws.add_row [1,2,3,4]
|
|
31
|
+
assert_equal(@ws.column_info[0].width, nil)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_initialization_options
|
|
35
|
+
page_margins = {:left => 2, :right => 2, :bottom => 2, :top => 2, :header => 2, :footer => 2}
|
|
36
|
+
optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :selected => true, :show_gridlines => false)
|
|
37
|
+
assert_equal(optioned.page_margins.left, page_margins[:left])
|
|
38
|
+
assert_equal(optioned.page_margins.right, page_margins[:right])
|
|
39
|
+
assert_equal(optioned.page_margins.top, page_margins[:top])
|
|
40
|
+
assert_equal(optioned.page_margins.bottom, page_margins[:bottom])
|
|
41
|
+
assert_equal(optioned.page_margins.header, page_margins[:header])
|
|
42
|
+
assert_equal(optioned.page_margins.footer, page_margins[:footer])
|
|
43
|
+
assert_equal(optioned.name, 'bob')
|
|
44
|
+
assert_equal(optioned.selected, true)
|
|
45
|
+
assert_equal(optioned.show_gridlines, false)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_use_gridlines
|
|
50
|
+
assert_raise(ArgumentError) { @ws.show_gridlines = -1.1 }
|
|
51
|
+
assert_nothing_raised { @ws.show_gridlines = false }
|
|
52
|
+
assert_equal(@ws.show_gridlines, false)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_selected
|
|
56
|
+
assert_raise(ArgumentError) { @ws.selected = -1.1 }
|
|
57
|
+
assert_nothing_raised { @ws.selected = true }
|
|
58
|
+
assert_equal(@ws.selected, true)
|
|
59
|
+
end
|
|
60
|
+
|
|
16
61
|
def test_rels_pn
|
|
17
62
|
assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels")
|
|
18
63
|
ws = @ws.workbook.add_worksheet
|
|
@@ -24,18 +69,28 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
24
69
|
ws = @ws.workbook.add_worksheet
|
|
25
70
|
assert_equal(ws.rId, "rId2")
|
|
26
71
|
end
|
|
27
|
-
|
|
72
|
+
|
|
28
73
|
def test_index
|
|
29
74
|
assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
|
|
30
75
|
end
|
|
31
|
-
|
|
76
|
+
|
|
77
|
+
def test_dimension
|
|
78
|
+
@ws.add_row [1, 2, 3]
|
|
79
|
+
@ws.add_row [4, 5, 6]
|
|
80
|
+
assert_equal @ws.dimension, "A1:C2"
|
|
81
|
+
end
|
|
82
|
+
|
|
32
83
|
def test_referencing
|
|
33
84
|
@ws.add_row [1, 2, 3]
|
|
34
85
|
@ws.add_row [4, 5, 6]
|
|
35
86
|
range = @ws["A1:C2"]
|
|
87
|
+
first_row = @ws[0]
|
|
88
|
+
last_row = @ws[1]
|
|
89
|
+
assert_equal(@ws.rows[0],first_row)
|
|
90
|
+
assert_equal(@ws.rows[1],last_row)
|
|
36
91
|
assert_equal(range.size, 6)
|
|
37
92
|
assert_equal(range.first, @ws.rows.first.cells.first)
|
|
38
|
-
assert_equal(range.last, @ws.rows.last.cells.last)
|
|
93
|
+
assert_equal(range.last, @ws.rows.last.cells.last)
|
|
39
94
|
end
|
|
40
95
|
|
|
41
96
|
def test_add_row
|
|
@@ -61,7 +116,7 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
61
116
|
@ws.add_row [1,2,3,4]
|
|
62
117
|
@ws.add_row [1,2,3,4]
|
|
63
118
|
@ws.col_style( (1..2), 1, :row_offset=>1)
|
|
64
|
-
@ws.rows[(1..-1)].each do | r |
|
|
119
|
+
@ws.rows[(1..-1)].each do | r |
|
|
65
120
|
assert_equal(r.cells[1].style, 1)
|
|
66
121
|
assert_equal(r.cells[2].style, 1)
|
|
67
122
|
end
|
|
@@ -82,7 +137,7 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
82
137
|
@ws.add_row [1,2,3,4]
|
|
83
138
|
@ws.add_row [1,2,3,4]
|
|
84
139
|
c = @ws.cols[1]
|
|
85
|
-
assert_equal(c.size, 4)
|
|
140
|
+
assert_equal(c.size, 4)
|
|
86
141
|
assert_equal(c[0].value, 2)
|
|
87
142
|
end
|
|
88
143
|
|
|
@@ -92,16 +147,103 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
92
147
|
@ws.add_row [1,2,3,4]
|
|
93
148
|
@ws.add_row [1,2,3,4]
|
|
94
149
|
@ws.row_style 1, 1, :col_offset=>1
|
|
95
|
-
@ws.rows[1].cells[(1..-1)].each do | c |
|
|
150
|
+
@ws.rows[1].cells[(1..-1)].each do | c |
|
|
96
151
|
assert_equal(c.style, 1)
|
|
97
152
|
end
|
|
98
153
|
assert_equal(@ws.rows[1].cells[0].style, 0)
|
|
99
154
|
assert_equal(@ws.rows[2].cells[1].style, 0)
|
|
100
155
|
end
|
|
101
|
-
|
|
102
|
-
def
|
|
156
|
+
|
|
157
|
+
def test_to_xml_string_fit_to_page
|
|
158
|
+
@ws.fit_to_page = true
|
|
159
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
160
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:pageSetUpPr[@fitToPage="true"]').size, 1)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_to_xml_string_dimensions
|
|
164
|
+
@ws.add_row [1,2,3]
|
|
165
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
166
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size, 1)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_to_xml_string_selected
|
|
170
|
+
@ws.selected = true
|
|
171
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
172
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@tabSelected="true"]').size, 1)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_to_xml_string_show_gridlines
|
|
176
|
+
@ws.show_gridlines = false
|
|
177
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
178
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@showGridLines="false"]').size, 1)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_to_xml_string_show_selection
|
|
183
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
184
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@activeCell="A1"]').size, 1)
|
|
185
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref="A1"]').size, 1)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def test_to_xml_string_auto_fit_data
|
|
189
|
+
@ws.add_row [1, "two"]
|
|
190
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
191
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:cols/xmlns:col').size, 2)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def test_to_xml_string_sheet_data
|
|
195
|
+
@ws.add_row [1, "two"]
|
|
196
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
197
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetData/xmlns:row').size, 1)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def test_to_xml_string_auto_filter
|
|
201
|
+
@ws.add_row [1, "two"]
|
|
202
|
+
@ws.auto_filter = "A1:B1"
|
|
203
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
204
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size, 1)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def test_to_xml_string_merge_cells
|
|
208
|
+
@ws.add_row [1, "two"]
|
|
209
|
+
@ws.merge_cells "A1:D1"
|
|
210
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
211
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size, 1)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def test_to_xml_string_page_margins
|
|
215
|
+
@ws.page_margins do |pm|
|
|
216
|
+
pm.left = 9
|
|
217
|
+
pm.right = 7
|
|
218
|
+
end
|
|
219
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
220
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size, 1)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_to_xml_string_drawing
|
|
224
|
+
c = @ws.add_chart Axlsx::Pie3DChart
|
|
225
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
226
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:drawing[@r:id="rId1"]').size, 1)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def test_to_xml_string_tables
|
|
230
|
+
@ws.add_row ["one", "two"]
|
|
231
|
+
@ws.add_row [1, 2]
|
|
232
|
+
@ws.add_table "A1:B2"
|
|
233
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
234
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size, 1)
|
|
235
|
+
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts/xmlns:tablePart[@r:id="rId1"]').size, 1)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def test_abs_auto_filter
|
|
239
|
+
@ws.add_row [1, "two", 3]
|
|
240
|
+
@ws.auto_filter = "A1:C1"
|
|
241
|
+
assert_equal(@ws.abs_auto_filter, "'Sheet1'!$A$1:$C$1")
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def test_to_xml_string
|
|
103
245
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
104
|
-
doc = Nokogiri::XML(@ws.
|
|
246
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
105
247
|
errors = []
|
|
106
248
|
schema.validate(doc).each do |error|
|
|
107
249
|
errors.push error
|
|
@@ -110,6 +252,19 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
110
252
|
assert(errors.empty?, "error free validation")
|
|
111
253
|
end
|
|
112
254
|
|
|
255
|
+
def test_valid_with_page_margins
|
|
256
|
+
@ws.page_margins.set :left => 9
|
|
257
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
258
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
259
|
+
errors = []
|
|
260
|
+
schema.validate(doc).each do |error|
|
|
261
|
+
errors.push error
|
|
262
|
+
puts error.message
|
|
263
|
+
end
|
|
264
|
+
assert(errors.empty?, "error free validation")
|
|
265
|
+
|
|
266
|
+
end
|
|
267
|
+
|
|
113
268
|
def test_relationships
|
|
114
269
|
assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
|
|
115
270
|
c = @ws.add_chart Axlsx::Pie3DChart
|
|
@@ -118,35 +273,40 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
118
273
|
assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
|
|
119
274
|
end
|
|
120
275
|
|
|
121
|
-
|
|
276
|
+
|
|
122
277
|
def test_name_unique
|
|
123
278
|
assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> @ws) }
|
|
124
279
|
end
|
|
125
280
|
|
|
126
|
-
def
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
@ws.add_row ["chasing windmills", "penut"], :style=>small
|
|
131
|
-
assert(@ws.auto_fit_data.size == 2, "a data item for each column")
|
|
132
|
-
|
|
133
|
-
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")
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
@ws.add_row ["mule"], :style=>big
|
|
137
|
-
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")
|
|
281
|
+
def test_name_size
|
|
282
|
+
assert_raise(ArgumentError, "name too long!") { @ws.name = Array.new(32, "A").join('') }
|
|
283
|
+
assert_nothing_raised { @ws.name = Array.new(31, "A").join('') }
|
|
138
284
|
end
|
|
139
285
|
|
|
140
|
-
def
|
|
141
|
-
|
|
286
|
+
def test_set_fixed_width_column
|
|
287
|
+
@ws.add_row ["mule", "donkey", "horse"], :widths => [20, :ignore, nil]
|
|
288
|
+
assert(@ws.column_info.size == 3, "a data item for each column")
|
|
289
|
+
assert_equal(@ws.column_info[0].width, 20, "adding a row with fixed width updates :fixed attribute")
|
|
290
|
+
assert_equal(@ws.column_info[1].width, nil, ":ignore does not set any data")
|
|
291
|
+
end
|
|
142
292
|
|
|
143
|
-
|
|
293
|
+
def test_fixed_height
|
|
294
|
+
@ws.add_row [1, 2, 3], :height => 40
|
|
295
|
+
assert_equal(40, @ws.rows[-1].height)
|
|
296
|
+
end
|
|
144
297
|
|
|
298
|
+
def test_set_column_width
|
|
299
|
+
@ws.add_row ["chasing windmills", "penut"]
|
|
300
|
+
@ws.column_widths nil, 0.5
|
|
301
|
+
assert_equal(@ws.column_info[1].width, 0.5, 'eat my width')
|
|
302
|
+
assert_raise(ArgumentError, 'reject invalid columns') { @ws.column_widths 2, 7, nil }
|
|
303
|
+
assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 }
|
|
304
|
+
assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" }
|
|
145
305
|
end
|
|
146
306
|
|
|
147
307
|
def test_merge_cells
|
|
148
308
|
assert(@ws.merged_cells.is_a?(Array))
|
|
149
|
-
assert_equal(@ws.merged_cells.size, 0)
|
|
309
|
+
assert_equal(@ws.merged_cells.size, 0)
|
|
150
310
|
@ws.add_row [1,2,3]
|
|
151
311
|
@ws.add_row [4,5,6]
|
|
152
312
|
@ws.add_row [7,8,9]
|