axlsx 1.2.0 → 2.0.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.
- checksums.yaml +7 -0
- data/.yardopts +3 -2
- data/.yardopts_guide +19 -0
- data/CHANGELOG.md +64 -1
- data/README.md +105 -87
- data/Rakefile +0 -5
- data/examples/2010_comments.rb +17 -0
- data/examples/anchor_swapping.rb +28 -0
- data/examples/auto_filter.rb +16 -0
- data/examples/basic_charts.rb +4 -0
- data/examples/colored_links.rb +59 -0
- data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
- data/examples/example.rb +569 -258
- data/examples/ios_preview.rb +14 -0
- data/examples/page_setup.rb +11 -0
- data/examples/pivot_table.rb +39 -0
- data/examples/skydrive/real_example.rb +8 -8
- data/examples/styles.rb +66 -0
- data/examples/underline.rb +13 -0
- data/examples/wrap_text.rb +21 -0
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/content_type/default.rb +6 -37
- data/lib/axlsx/content_type/override.rb +6 -38
- data/lib/axlsx/doc_props/app.rb +10 -7
- data/lib/axlsx/doc_props/core.rb +6 -1
- data/lib/axlsx/drawing/axes.rb +61 -0
- data/lib/axlsx/drawing/axis.rb +20 -17
- data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
- data/lib/axlsx/drawing/cat_axis.rb +2 -10
- data/lib/axlsx/drawing/chart.rb +33 -6
- data/lib/axlsx/drawing/d_lbls.rb +21 -31
- data/lib/axlsx/drawing/drawing.rb +11 -17
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +42 -36
- data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
- data/lib/axlsx/drawing/line_chart.rb +99 -0
- data/lib/axlsx/drawing/line_series.rb +20 -2
- data/lib/axlsx/drawing/marker.rb +38 -18
- data/lib/axlsx/drawing/num_data.rb +6 -6
- data/lib/axlsx/drawing/num_data_source.rb +17 -16
- data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
- data/lib/axlsx/drawing/pic.rb +43 -45
- data/lib/axlsx/drawing/picture_locking.rb +12 -44
- data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
- data/lib/axlsx/drawing/scaling.rb +13 -13
- data/lib/axlsx/drawing/scatter_chart.rb +32 -21
- data/lib/axlsx/drawing/ser_axis.rb +15 -16
- data/lib/axlsx/drawing/series.rb +3 -6
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +7 -8
- data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
- data/lib/axlsx/drawing/val_axis.rb +14 -13
- data/lib/axlsx/drawing/view_3D.rb +52 -38
- data/lib/axlsx/drawing/vml_shape.rb +20 -79
- data/lib/axlsx/package.rb +58 -28
- data/lib/axlsx/rels/relationship.rb +75 -9
- data/lib/axlsx/rels/relationships.rb +8 -1
- data/lib/axlsx/stylesheet/border.rb +29 -20
- data/lib/axlsx/stylesheet/border_pr.rb +5 -4
- data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
- data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
- data/lib/axlsx/stylesheet/cell_style.rb +19 -14
- data/lib/axlsx/stylesheet/color.rb +20 -17
- data/lib/axlsx/stylesheet/dxf.rb +4 -4
- data/lib/axlsx/stylesheet/font.rb +22 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
- data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
- data/lib/axlsx/stylesheet/styles.rb +37 -22
- data/lib/axlsx/stylesheet/table_style.rb +17 -16
- data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
- data/lib/axlsx/stylesheet/table_styles.rb +14 -11
- data/lib/axlsx/stylesheet/xf.rb +28 -26
- data/lib/axlsx/util/accessors.rb +64 -0
- data/lib/axlsx/util/constants.rb +127 -6
- data/lib/axlsx/util/options_parser.rb +15 -0
- data/lib/axlsx/util/serialized_attributes.rb +79 -0
- data/lib/axlsx/util/simple_typed_list.rb +50 -15
- data/lib/axlsx/util/validators.rb +51 -16
- data/lib/axlsx/version.rb +2 -2
- data/lib/axlsx/workbook/defined_name.rb +14 -59
- data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
- data/lib/axlsx/workbook/workbook.rb +85 -6
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
- data/lib/axlsx/workbook/worksheet/break.rb +37 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
- data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
- data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
- data/lib/axlsx/workbook/worksheet/col.rb +43 -29
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
- data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
- data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
- data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
- data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
- data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
- data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
- data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
- data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
- data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +59 -83
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
- data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
- data/lib/axlsx/workbook/worksheet/table.rb +25 -19
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
- data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/axlsx.rb +55 -5
- data/lib/schema/sml.xsd +4 -0
- data/test/axlsx.qcachegrind +2226 -0
- data/test/benchmark.rb +2 -3
- data/test/content_type/tc_default.rb +0 -11
- data/test/content_type/tc_override.rb +0 -13
- data/test/doc_props/tc_core.rb +7 -0
- data/test/drawing/tc_axes.rb +8 -0
- data/test/drawing/tc_axis.rb +15 -17
- data/test/drawing/tc_bar_3D_chart.rb +6 -0
- data/test/drawing/tc_cat_axis.rb +9 -9
- data/test/drawing/tc_chart.rb +20 -0
- data/test/drawing/tc_d_lbls.rb +14 -4
- data/test/drawing/tc_drawing.rb +0 -5
- data/test/drawing/tc_graphic_frame.rb +5 -3
- data/test/drawing/tc_hyperlink.rb +0 -4
- data/test/drawing/tc_line_chart.rb +39 -0
- data/test/drawing/tc_line_series.rb +8 -2
- data/test/drawing/tc_pic.rb +14 -3
- data/test/drawing/tc_ser_axis.rb +13 -12
- data/test/drawing/tc_two_cell_anchor.rb +3 -3
- data/test/drawing/tc_val_axis.rb +6 -6
- data/test/drawing/tc_vml_shape.rb +9 -3
- data/test/profile.rb +11 -21
- data/test/rels/tc_relationship.rb +32 -9
- data/test/rels/tc_relationships.rb +12 -1
- data/test/stylesheet/tc_color.rb +6 -0
- data/test/stylesheet/tc_styles.rb +15 -2
- data/test/tc_axlsx.rb +35 -2
- data/test/tc_helper.rb +7 -1
- data/test/tc_package.rb +44 -5
- data/test/util/tc_serialized_attributes.rb +19 -0
- data/test/util/tc_validators.rb +26 -1
- data/test/workbook/tc_defined_name.rb +2 -2
- data/test/workbook/tc_shared_strings_table.rb +6 -0
- data/test/workbook/tc_workbook.rb +38 -1
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
- data/test/workbook/worksheet/tc_break.rb +49 -0
- data/test/workbook/worksheet/tc_cell.rb +40 -6
- data/test/workbook/worksheet/tc_col.rb +11 -1
- data/test/workbook/worksheet/tc_color_scale.rb +31 -2
- data/test/workbook/worksheet/tc_comment.rb +21 -6
- data/test/workbook/worksheet/tc_comments.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
- data/test/workbook/worksheet/tc_data_bar.rb +7 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
- data/test/workbook/worksheet/tc_header_footer.rb +151 -0
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
- data/test/workbook/worksheet/tc_page_setup.rb +6 -1
- data/test/workbook/worksheet/tc_pane.rb +5 -45
- data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
- data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
- data/test/workbook/worksheet/tc_row.rb +4 -4
- data/test/workbook/worksheet/tc_selection.rb +9 -48
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
- data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
- data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +131 -16
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
- metadata +97 -64
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.pdf +0 -0
- data/examples/image1.gif +0 -0
- data/examples/image1.jpg +0 -0
- data/examples/image1.png +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/sample.png +0 -0
- data/examples/scraping_html.rb +0 -91
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/sheet_view.rb +0 -34
- data/examples/two_cell_anchor_image.rb +0 -11
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def shared_test_pivot_table_xml_validity(pivot_table)
|
|
5
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
6
|
+
doc = Nokogiri::XML(pivot_table.to_xml_string)
|
|
7
|
+
errors = []
|
|
8
|
+
schema.validate(doc).each do |error|
|
|
9
|
+
errors.push error
|
|
10
|
+
puts error.message
|
|
11
|
+
end
|
|
12
|
+
assert(errors.empty?, "error free validation")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class TestPivotTable < Test::Unit::TestCase
|
|
16
|
+
def setup
|
|
17
|
+
p = Axlsx::Package.new
|
|
18
|
+
@ws = p.workbook.add_worksheet
|
|
19
|
+
|
|
20
|
+
@ws << ["Year","Month","Region", "Type", "Sales"]
|
|
21
|
+
@ws << [2012, "Nov", "East", "Soda", "12345"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_initialization
|
|
25
|
+
assert(@ws.workbook.pivot_tables.empty?)
|
|
26
|
+
assert(@ws.pivot_tables.empty?)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_add_pivot_table
|
|
30
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
31
|
+
assert_equal('G5:G6', pivot_table.ref, 'ref assigned from first parameter')
|
|
32
|
+
assert_equal('A1:D5', pivot_table.range, 'range assigned from second parameter')
|
|
33
|
+
assert_equal('PivotTable1', pivot_table.name, 'name automatically generated')
|
|
34
|
+
assert(pivot_table.is_a?(Axlsx::PivotTable), "must create a pivot table")
|
|
35
|
+
assert_equal(@ws.workbook.pivot_tables.last, pivot_table, "must be added to workbook pivot tables collection")
|
|
36
|
+
assert_equal(@ws.pivot_tables.last, pivot_table, "must be added to worksheet pivot tables collection")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_set_pivot_table_data_sheet
|
|
40
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
41
|
+
data_sheet = @ws.clone
|
|
42
|
+
data_sheet.name = "Pivot Table Data Source"
|
|
43
|
+
|
|
44
|
+
assert_equal(pivot_table.data_sheet.name, @ws.name, "must default to the same sheet the pivot table is added to")
|
|
45
|
+
pivot_table.data_sheet = data_sheet
|
|
46
|
+
assert_equal(pivot_table.data_sheet.name, data_sheet.name, "data sheet assigned to pivot table")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_add_pivot_table_with_config
|
|
50
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
|
|
51
|
+
pt.rows = ['Year', 'Month']
|
|
52
|
+
pt.columns = ['Type']
|
|
53
|
+
pt.data = ['Sales']
|
|
54
|
+
pt.pages = ['Region']
|
|
55
|
+
end
|
|
56
|
+
assert_equal(['Year', 'Month'], pivot_table.rows)
|
|
57
|
+
assert_equal(['Type'], pivot_table.columns)
|
|
58
|
+
assert_equal([{:ref=>"Sales"}], pivot_table.data)
|
|
59
|
+
assert_equal(['Region'], pivot_table.pages)
|
|
60
|
+
shared_test_pivot_table_xml_validity(pivot_table)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_add_pivot_table_with_options_on_data_field
|
|
64
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') do |pt|
|
|
65
|
+
pt.data = [{:ref=>"Sales", :subtotal => 'average'}]
|
|
66
|
+
end
|
|
67
|
+
assert_equal([{:ref=>"Sales", :subtotal => 'average'}], pivot_table.data)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_header_indices
|
|
71
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5')
|
|
72
|
+
assert_equal(0, pivot_table.header_index_of('Year' ))
|
|
73
|
+
assert_equal(1, pivot_table.header_index_of('Month' ))
|
|
74
|
+
assert_equal(2, pivot_table.header_index_of('Region' ))
|
|
75
|
+
assert_equal(3, pivot_table.header_index_of('Type' ))
|
|
76
|
+
assert_equal(4, pivot_table.header_index_of('Sales' ))
|
|
77
|
+
assert_equal(nil, pivot_table.header_index_of('Missing'))
|
|
78
|
+
assert_equal(%w(A1 B1 C1 D1 E1), pivot_table.header_cell_refs)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_pn
|
|
82
|
+
@ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
83
|
+
assert_equal(@ws.pivot_tables.first.pn, "pivotTables/pivotTable1.xml")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_index
|
|
87
|
+
@ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
88
|
+
assert_equal(@ws.pivot_tables.first.index, @ws.workbook.pivot_tables.index(@ws.pivot_tables.first))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_relationships
|
|
92
|
+
assert(@ws.relationships.empty?)
|
|
93
|
+
@ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
94
|
+
assert_equal(@ws.relationships.size, 1, "adding a pivot table adds a relationship")
|
|
95
|
+
@ws.add_pivot_table('G10:G11', 'A1:D5')
|
|
96
|
+
assert_equal(@ws.relationships.size, 2, "adding a pivot table adds a relationship")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_to_xml_string
|
|
100
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
101
|
+
shared_test_pivot_table_xml_validity(pivot_table)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_to_xml_string_with_configuration
|
|
105
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
|
|
106
|
+
pt.rows = ['Year', 'Month']
|
|
107
|
+
pt.columns = ['Type']
|
|
108
|
+
pt.data = ['Sales']
|
|
109
|
+
pt.pages = ['Region']
|
|
110
|
+
end
|
|
111
|
+
shared_test_pivot_table_xml_validity(pivot_table)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_to_xml_string_with_options_on_data_field
|
|
115
|
+
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
|
|
116
|
+
pt.data = [{:ref=>"Sales", :subtotal => 'average'}]
|
|
117
|
+
end
|
|
118
|
+
shared_test_pivot_table_xml_validity(pivot_table)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestPivotTableCacheDefinition < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
p = Axlsx::Package.new
|
|
6
|
+
@ws = p.workbook.add_worksheet
|
|
7
|
+
5.times do
|
|
8
|
+
@ws << ["aa","aa","aa","aa"]
|
|
9
|
+
end
|
|
10
|
+
@pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
|
|
11
|
+
@cache_definition = @pivot_table.cache_definition
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_initialization
|
|
15
|
+
assert(@cache_definition.is_a?(Axlsx::PivotTableCacheDefinition), "must create a pivot table cache definition")
|
|
16
|
+
assert_equal(@pivot_table, @cache_definition.pivot_table, 'refers back to its pivot table')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_pn
|
|
20
|
+
assert_equal('pivotCache/pivotCacheDefinition1.xml', @cache_definition.pn)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_rId
|
|
24
|
+
assert_equal @pivot_table.relationships.for(@cache_definition).Id, @cache_definition.rId
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_index
|
|
28
|
+
assert_equal(0, @cache_definition.index)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_cache_id
|
|
32
|
+
assert_equal(1, @cache_definition.cache_id)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_data_sheet
|
|
36
|
+
data_sheet = @ws.clone
|
|
37
|
+
data_sheet.name = "Pivot Table Data Source"
|
|
38
|
+
@pivot_table.data_sheet = data_sheet
|
|
39
|
+
|
|
40
|
+
assert(@cache_definition.to_xml_string.include?(data_sheet.name), "must set the data source correctly")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_to_xml_string
|
|
44
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
45
|
+
doc = Nokogiri::XML(@cache_definition.to_xml_string)
|
|
46
|
+
errors = []
|
|
47
|
+
schema.validate(doc).each do |error|
|
|
48
|
+
errors.push error
|
|
49
|
+
puts error.message
|
|
50
|
+
end
|
|
51
|
+
assert(errors.empty?, "error free validation")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -12,13 +12,13 @@ class TestRow < Test::Unit::TestCase
|
|
|
12
12
|
assert(@row.cells.empty?, "no cells by default")
|
|
13
13
|
assert_equal(@row.worksheet, @ws, "has a reference to the worksheet")
|
|
14
14
|
assert_nil(@row.height, "height defaults to nil")
|
|
15
|
-
assert(!@row.custom_height
|
|
15
|
+
assert(!@row.custom_height, "no custom height by default")
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def test_initialize_with_fixed_height
|
|
19
19
|
row = @ws.add_row([1,2,3,4,5], :height=>40)
|
|
20
20
|
assert_equal(40, row.height)
|
|
21
|
-
assert(row.custom_height
|
|
21
|
+
assert(row.custom_height)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def test_style
|
|
@@ -57,7 +57,7 @@ class TestRow < Test::Unit::TestCase
|
|
|
57
57
|
|
|
58
58
|
def test_custom_height
|
|
59
59
|
@row.height = 20
|
|
60
|
-
assert(@row.custom_height
|
|
60
|
+
assert(@row.custom_height)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def test_height
|
|
@@ -111,7 +111,7 @@ class TestRow < Test::Unit::TestCase
|
|
|
111
111
|
@row.add_cell 1
|
|
112
112
|
@row.height = 20
|
|
113
113
|
r_s_xml = Nokogiri::XML(@row.to_xml_string(0, ''))
|
|
114
|
-
assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=
|
|
114
|
+
assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight='true']").size, 1)
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
end
|
|
@@ -3,70 +3,34 @@ require 'tc_helper.rb'
|
|
|
3
3
|
|
|
4
4
|
class TestSelection < Test::Unit::TestCase
|
|
5
5
|
def setup
|
|
6
|
-
@
|
|
7
|
-
@options = @nil_options
|
|
8
|
-
|
|
9
|
-
@string_options = { :active_cell => 'A2', :sqref => 'A2' }
|
|
10
|
-
@integer_options = { :active_cell_id => 1 }
|
|
11
|
-
@symbol_options = { :pane => :top_left }
|
|
12
|
-
|
|
6
|
+
@options = { :active_cell => 'A2', :active_cell_id => 1, :pane => :top_left, :sqref => 'A2' }
|
|
13
7
|
@selection = Axlsx::Selection.new(@options)
|
|
14
8
|
end
|
|
15
|
-
|
|
16
|
-
def test_initialize
|
|
17
|
-
selection = Axlsx::Selection.new
|
|
18
|
-
|
|
19
|
-
@nil_options.each do |key, value|
|
|
20
|
-
assert_equal(nil, selection.send(key.to_sym), "initialized default #{key} should be nil")
|
|
21
|
-
assert_equal(value, @selection.send(key.to_sym), "initialized options #{key} should be #{value}")
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_string_attribute_validation
|
|
26
|
-
@string_options.each do |key, value|
|
|
27
|
-
assert_raise(ArgumentError, "#{key} must be string") { @selection.send("#{key}=".to_sym, :symbol) }
|
|
28
|
-
assert_nothing_raised { @selection.send("#{key}=".to_sym, "foo") }
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_symbol_attribute_validation
|
|
33
|
-
@symbol_options.each do |key, value|
|
|
34
|
-
assert_raise(ArgumentError, "#{key} must be symbol") { @selection.send("#{key}=".to_sym, "foo") }
|
|
35
|
-
assert_nothing_raised { @selection.send("#{key}=".to_sym, value) }
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_integer_attribute_validation
|
|
40
|
-
@integer_options.each do |key, value|
|
|
41
|
-
assert_raise(ArgumentError, "#{key} must be integer") { @selection.send("#{key}=".to_sym, "foo") }
|
|
42
|
-
assert_nothing_raised { @selection.send("#{key}=".to_sym, value) }
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
9
|
+
|
|
46
10
|
def test_active_cell
|
|
47
11
|
assert_raise(ArgumentError) { @selection.active_cell = :active_cell }
|
|
48
12
|
assert_nothing_raised { @selection.active_cell = "F5" }
|
|
49
13
|
assert_equal(@selection.active_cell, "F5")
|
|
50
14
|
end
|
|
51
|
-
|
|
15
|
+
|
|
52
16
|
def test_active_cell_id
|
|
53
17
|
assert_raise(ArgumentError) { @selection.active_cell_id = "foo" }
|
|
54
18
|
assert_nothing_raised { @selection.active_cell_id = 11 }
|
|
55
19
|
assert_equal(@selection.active_cell_id, 11)
|
|
56
20
|
end
|
|
57
|
-
|
|
21
|
+
|
|
58
22
|
def test_pane
|
|
59
23
|
assert_raise(ArgumentError) { @selection.pane = "foo´" }
|
|
60
24
|
assert_nothing_raised { @selection.pane = :bottom_right }
|
|
61
|
-
assert_equal(@selection.pane,
|
|
25
|
+
assert_equal(@selection.pane, "bottomRight")
|
|
62
26
|
end
|
|
63
|
-
|
|
27
|
+
|
|
64
28
|
def test_sqref
|
|
65
29
|
assert_raise(ArgumentError) { @selection.sqref = :sqref }
|
|
66
30
|
assert_nothing_raised { @selection.sqref = "G32" }
|
|
67
31
|
assert_equal(@selection.sqref, "G32")
|
|
68
32
|
end
|
|
69
|
-
|
|
33
|
+
|
|
70
34
|
def test_to_xml
|
|
71
35
|
p = Axlsx::Package.new
|
|
72
36
|
@ws = p.workbook.add_worksheet :name => "sheetview"
|
|
@@ -76,18 +40,15 @@ class TestSelection < Test::Unit::TestCase
|
|
|
76
40
|
vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
|
|
77
41
|
vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
|
|
78
42
|
end
|
|
79
|
-
|
|
43
|
+
|
|
80
44
|
doc = Nokogiri::XML.parse(@ws.to_xml_string)
|
|
81
|
-
|
|
45
|
+
|
|
82
46
|
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='B2'][@pane='topLeft'][@activeCell='B2']").size)
|
|
83
47
|
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='B2'][@pane='topLeft'][@activeCell='B2']")
|
|
84
|
-
|
|
85
48
|
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I10'][@pane='topRight'][@activeCell='I10']").size)
|
|
86
49
|
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I10'][@pane='topRight'][@activeCell='I10']")
|
|
87
|
-
|
|
88
50
|
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='E55'][@pane='bottomLeft'][@activeCell='E55']").size)
|
|
89
51
|
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='E55'][@pane='bottomLeft'][@activeCell='E55']")
|
|
90
|
-
|
|
91
52
|
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I57'][@pane='bottomRight'][@activeCell='I57']").size)
|
|
92
53
|
assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I57'][@pane='bottomRight'][@activeCell='I57']")
|
|
93
54
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'tc_helper'
|
|
2
|
+
|
|
3
|
+
class TestSheetCalcPr < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@sheet_calc_pr = Axlsx::SheetCalcPr.new(:full_calc_on_load => false)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_full_calc_on_load
|
|
10
|
+
assert_equal false, @sheet_calc_pr.full_calc_on_load
|
|
11
|
+
assert Axlsx::SheetCalcPr.new.full_calc_on_load
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_to_xml_string
|
|
15
|
+
doc = Nokogiri::XML(@sheet_calc_pr.to_xml_string)
|
|
16
|
+
assert_equal 1, doc.xpath('//sheetCalcPr[@fullCalcOnLoad="false"]').size
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestSheetFormatPr < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@options = {
|
|
7
|
+
:base_col_width => 5,
|
|
8
|
+
:default_col_width => 7.2,
|
|
9
|
+
:default_row_height => 5.2,
|
|
10
|
+
:custom_height => true,
|
|
11
|
+
:zero_height => false,
|
|
12
|
+
:thick_top => true,
|
|
13
|
+
:thick_bottom => true,
|
|
14
|
+
:outline_level_row => 0,
|
|
15
|
+
:outline_level_col => 0
|
|
16
|
+
}
|
|
17
|
+
@sheet_format_pr = Axlsx::SheetFormatPr.new(@options)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_default_initialization
|
|
21
|
+
sheet_format_pr = Axlsx::SheetFormatPr.new
|
|
22
|
+
assert_equal 8, sheet_format_pr.base_col_width
|
|
23
|
+
assert_equal 18, sheet_format_pr.default_row_height
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_initialization_with_options
|
|
27
|
+
@options.each do |key, value|
|
|
28
|
+
assert_equal value, @sheet_format_pr.instance_variable_get("@#{key}")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_base_col_width
|
|
33
|
+
assert_raise(ArgumentError) { @sheet_format_pr.base_col_width = :foo }
|
|
34
|
+
assert_nothing_raised { @sheet_format_pr.base_col_width = 1 }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_outline_level_row
|
|
38
|
+
assert_raise(ArgumentError) { @sheet_format_pr.outline_level_row = :foo }
|
|
39
|
+
assert_nothing_raised { @sheet_format_pr.outline_level_row = 1 }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_outline_level_col
|
|
43
|
+
assert_raise(ArgumentError) { @sheet_format_pr.outline_level_col = :foo }
|
|
44
|
+
assert_nothing_raised { @sheet_format_pr.outline_level_col = 1 }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_default_row_height
|
|
48
|
+
assert_raise(ArgumentError) { @sheet_format_pr.default_row_height = :foo }
|
|
49
|
+
assert_nothing_raised { @sheet_format_pr.default_row_height= 1.0 }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_default_col_width
|
|
53
|
+
assert_raise(ArgumentError) { @sheet_format_pr.default_col_width= :foo }
|
|
54
|
+
assert_nothing_raised { @sheet_format_pr.default_col_width = 1.0 }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_custom_height
|
|
58
|
+
assert_raise(ArgumentError) { @sheet_format_pr.custom_height= :foo }
|
|
59
|
+
assert_nothing_raised { @sheet_format_pr.custom_height = true }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_zero_height
|
|
63
|
+
assert_raise(ArgumentError) { @sheet_format_pr.zero_height= :foo }
|
|
64
|
+
assert_nothing_raised { @sheet_format_pr.zero_height = true }
|
|
65
|
+
end
|
|
66
|
+
def test_thick_top
|
|
67
|
+
assert_raise(ArgumentError) { @sheet_format_pr.thick_top= :foo }
|
|
68
|
+
assert_nothing_raised { @sheet_format_pr.thick_top = true }
|
|
69
|
+
end
|
|
70
|
+
def test_thick_bottom
|
|
71
|
+
assert_raise(ArgumentError) { @sheet_format_pr.thick_bottom= :foo }
|
|
72
|
+
assert_nothing_raised { @sheet_format_pr.thick_bottom = true }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_to_xml_string
|
|
76
|
+
doc = Nokogiri::XML(@sheet_format_pr.to_xml_string)
|
|
77
|
+
assert doc.xpath("sheetFormatPr[@thickBottom='true']")
|
|
78
|
+
assert doc.xpath("sheetFormatPr[@baseColWidth=5]")
|
|
79
|
+
assert doc.xpath("sheetFormatPr[@default_col_width=7.2]")
|
|
80
|
+
assert doc.xpath("sheetFormatPr[@default_row_height=5.2]")
|
|
81
|
+
assert doc.xpath("sheetFormatPr[@custom_height='true']")
|
|
82
|
+
assert doc.xpath("sheetFormatPr[@zero_height='false']")
|
|
83
|
+
assert doc.xpath("sheetFormatPr[@thick_top='true']")
|
|
84
|
+
assert doc.xpath("sheetFormatPr[@outline_level_row=0]")
|
|
85
|
+
assert doc.xpath("sheetFormatPr[@outline_level_col=0]")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TestSheetPr < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
worksheet = Axlsx::Package.new.workbook.add_worksheet
|
|
8
|
+
@options = {
|
|
9
|
+
:sync_horizontal => false,
|
|
10
|
+
:sync_vertical => false,
|
|
11
|
+
:transtion_evaluation => true,
|
|
12
|
+
:transition_entry => true,
|
|
13
|
+
:published => false,
|
|
14
|
+
:filter_mode => true,
|
|
15
|
+
:enable_format_conditions_calculation => false,
|
|
16
|
+
:code_name => '007',
|
|
17
|
+
:sync_ref => 'foo'
|
|
18
|
+
}
|
|
19
|
+
@sheet_pr = Axlsx::SheetPr.new(worksheet, @options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_initialization
|
|
23
|
+
@options.each do |key, value|
|
|
24
|
+
assert_equal value, @sheet_pr.send(key)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|