caxlsx 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +9 -9
- data/.yardopts_guide +18 -18
- data/CHANGELOG.md +354 -343
- data/LICENSE +21 -21
- data/README.md +168 -172
- data/Rakefile +29 -29
- data/examples/generate.rb +15 -15
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -32
- data/lib/axlsx/content_type/content_type.rb +26 -26
- data/lib/axlsx/content_type/default.rb +25 -25
- data/lib/axlsx/content_type/override.rb +25 -25
- data/lib/axlsx/doc_props/app.rb +235 -235
- data/lib/axlsx/doc_props/core.rb +39 -39
- data/lib/axlsx/drawing/area_chart.rb +99 -99
- data/lib/axlsx/drawing/area_series.rb +110 -110
- data/lib/axlsx/drawing/ax_data_source.rb +26 -26
- data/lib/axlsx/drawing/axes.rb +61 -61
- data/lib/axlsx/drawing/axis.rb +190 -190
- data/lib/axlsx/drawing/bar_3D_chart.rb +148 -148
- data/lib/axlsx/drawing/bar_chart.rb +138 -138
- data/lib/axlsx/drawing/bar_series.rb +97 -97
- data/lib/axlsx/drawing/bubble_chart.rb +59 -59
- data/lib/axlsx/drawing/bubble_series.rb +63 -63
- data/lib/axlsx/drawing/cat_axis.rb +85 -85
- data/lib/axlsx/drawing/chart.rb +276 -276
- data/lib/axlsx/drawing/d_lbls.rb +90 -90
- data/lib/axlsx/drawing/drawing.rb +167 -167
- data/lib/axlsx/drawing/graphic_frame.rb +54 -54
- data/lib/axlsx/drawing/hyperlink.rb +100 -100
- data/lib/axlsx/drawing/line_3D_chart.rb +68 -68
- data/lib/axlsx/drawing/line_chart.rb +99 -99
- data/lib/axlsx/drawing/line_series.rb +110 -110
- data/lib/axlsx/drawing/marker.rb +84 -84
- data/lib/axlsx/drawing/num_data.rb +52 -52
- data/lib/axlsx/drawing/num_data_source.rb +62 -62
- data/lib/axlsx/drawing/num_val.rb +34 -34
- data/lib/axlsx/drawing/one_cell_anchor.rb +99 -99
- data/lib/axlsx/drawing/pic.rb +211 -211
- data/lib/axlsx/drawing/picture_locking.rb +42 -42
- data/lib/axlsx/drawing/pie_3D_chart.rb +47 -47
- data/lib/axlsx/drawing/pie_series.rb +74 -74
- data/lib/axlsx/drawing/scaling.rb +60 -60
- data/lib/axlsx/drawing/scatter_chart.rb +74 -74
- data/lib/axlsx/drawing/scatter_series.rb +129 -98
- data/lib/axlsx/drawing/ser_axis.rb +45 -45
- data/lib/axlsx/drawing/series.rb +69 -69
- data/lib/axlsx/drawing/series_title.rb +25 -25
- data/lib/axlsx/drawing/str_data.rb +42 -42
- data/lib/axlsx/drawing/str_val.rb +34 -34
- data/lib/axlsx/drawing/title.rb +97 -97
- data/lib/axlsx/drawing/two_cell_anchor.rb +97 -97
- data/lib/axlsx/drawing/val_axis.rb +37 -37
- data/lib/axlsx/drawing/view_3D.rb +115 -115
- data/lib/axlsx/drawing/vml_drawing.rb +42 -42
- data/lib/axlsx/drawing/vml_shape.rb +66 -66
- data/lib/axlsx/package.rb +388 -388
- data/lib/axlsx/rels/relationship.rb +130 -130
- data/lib/axlsx/rels/relationships.rb +32 -32
- data/lib/axlsx/stylesheet/border.rb +73 -71
- data/lib/axlsx/stylesheet/border_pr.rb +71 -71
- data/lib/axlsx/stylesheet/cell_alignment.rb +132 -132
- data/lib/axlsx/stylesheet/cell_protection.rb +41 -41
- data/lib/axlsx/stylesheet/cell_style.rb +72 -72
- data/lib/axlsx/stylesheet/color.rb +76 -76
- data/lib/axlsx/stylesheet/dxf.rb +79 -79
- data/lib/axlsx/stylesheet/fill.rb +35 -35
- data/lib/axlsx/stylesheet/font.rb +156 -156
- data/lib/axlsx/stylesheet/gradient_fill.rb +103 -103
- data/lib/axlsx/stylesheet/gradient_stop.rb +37 -37
- data/lib/axlsx/stylesheet/num_fmt.rb +86 -86
- data/lib/axlsx/stylesheet/pattern_fill.rb +73 -73
- data/lib/axlsx/stylesheet/styles.rb +494 -420
- data/lib/axlsx/stylesheet/table_style.rb +54 -54
- data/lib/axlsx/stylesheet/table_style_element.rb +77 -77
- data/lib/axlsx/stylesheet/table_styles.rb +46 -46
- data/lib/axlsx/stylesheet/xf.rb +147 -147
- data/lib/axlsx/util/accessors.rb +64 -64
- data/lib/axlsx/util/constants.rb +410 -401
- data/lib/axlsx/util/mime_type_utils.rb +11 -11
- data/lib/axlsx/util/options_parser.rb +16 -16
- data/lib/axlsx/util/serialized_attributes.rb +89 -89
- data/lib/axlsx/util/simple_typed_list.rb +179 -179
- data/lib/axlsx/util/storage.rb +146 -146
- data/lib/axlsx/util/validators.rb +312 -312
- data/lib/axlsx/util/zip_command.rb +73 -73
- data/lib/axlsx/version.rb +5 -5
- data/lib/axlsx/workbook/defined_name.rb +128 -128
- data/lib/axlsx/workbook/defined_names.rb +21 -21
- data/lib/axlsx/workbook/shared_strings_table.rb +77 -77
- data/lib/axlsx/workbook/workbook.rb +395 -370
- data/lib/axlsx/workbook/workbook_view.rb +80 -80
- data/lib/axlsx/workbook/workbook_views.rb +22 -22
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -77
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -94
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +244 -244
- data/lib/axlsx/workbook/worksheet/break.rb +35 -35
- data/lib/axlsx/workbook/worksheet/cell.rb +506 -505
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +164 -164
- data/lib/axlsx/workbook/worksheet/cfvo.rb +60 -60
- data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -18
- data/lib/axlsx/workbook/worksheet/col.rb +145 -145
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -35
- data/lib/axlsx/workbook/worksheet/color_scale.rb +110 -110
- data/lib/axlsx/workbook/worksheet/cols.rb +23 -23
- data/lib/axlsx/workbook/worksheet/comment.rb +91 -91
- data/lib/axlsx/workbook/worksheet/comments.rb +82 -82
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -82
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +220 -220
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -25
- data/lib/axlsx/workbook/worksheet/data_bar.rb +129 -129
- data/lib/axlsx/workbook/worksheet/data_validation.rb +246 -246
- data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -28
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +30 -30
- data/lib/axlsx/workbook/worksheet/dimension.rb +64 -64
- data/lib/axlsx/workbook/worksheet/header_footer.rb +52 -52
- data/lib/axlsx/workbook/worksheet/icon_set.rb +81 -81
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +37 -37
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -33
- data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -97
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -44
- data/lib/axlsx/workbook/worksheet/page_setup.rb +240 -240
- data/lib/axlsx/workbook/worksheet/pane.rb +139 -139
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +296 -294
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -66
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -24
- data/lib/axlsx/workbook/worksheet/print_options.rb +39 -39
- data/lib/axlsx/workbook/worksheet/protected_range.rb +47 -47
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +37 -37
- data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -55
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -250
- data/lib/axlsx/workbook/worksheet/row.rb +164 -164
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -33
- data/lib/axlsx/workbook/worksheet/selection.rb +101 -101
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -29
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +27 -27
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -87
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +118 -118
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +213 -213
- data/lib/axlsx/workbook/worksheet/table.rb +102 -102
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +49 -49
- data/lib/axlsx/workbook/worksheet/tables.rb +34 -34
- data/lib/axlsx/workbook/worksheet/worksheet.rb +786 -768
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +58 -58
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +58 -58
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -74
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -38
- data/lib/axlsx.rb +185 -171
- data/lib/caxlsx.rb +2 -2
- data/lib/schema/dc.xsd +118 -118
- data/lib/schema/dcmitype.xsd +51 -51
- data/lib/schema/dcterms.xsd +331 -331
- data/lib/schema/dml-chartDrawing.xsd +146 -146
- data/lib/schema/dml-compatibility.xsd +14 -14
- data/lib/schema/dml-lockedCanvas.xsd +11 -11
- data/lib/schema/dml-main.xsd +3048 -3048
- data/lib/schema/dml-picture.xsd +23 -23
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -185
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -185
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -28
- data/lib/schema/shared-bibliography.xsd +144 -144
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -166
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -25
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -18
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -59
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -56
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -195
- data/lib/schema/shared-relationshipReference.xsd +25 -25
- data/lib/schema/vml-main.xsd +569 -569
- data/lib/schema/vml-officeDrawing.xsd +509 -509
- data/lib/schema/vml-presentationDrawing.xsd +12 -12
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -108
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -96
- data/lib/schema/xml.xsd +116 -116
- data/test/benchmark.rb +72 -72
- data/test/content_type/tc_content_type.rb +76 -76
- data/test/content_type/tc_default.rb +16 -16
- data/test/content_type/tc_override.rb +14 -14
- data/test/doc_props/tc_app.rb +43 -43
- data/test/doc_props/tc_core.rb +42 -42
- data/test/drawing/tc_area_chart.rb +39 -39
- data/test/drawing/tc_area_series.rb +71 -71
- data/test/drawing/tc_axes.rb +7 -7
- data/test/drawing/tc_axis.rb +112 -112
- data/test/drawing/tc_bar_3D_chart.rb +86 -86
- data/test/drawing/tc_bar_chart.rb +86 -86
- data/test/drawing/tc_bar_series.rb +46 -46
- data/test/drawing/tc_bubble_chart.rb +44 -44
- data/test/drawing/tc_bubble_series.rb +21 -21
- data/test/drawing/tc_cat_axis.rb +31 -31
- data/test/drawing/tc_cat_axis_data.rb +27 -27
- data/test/drawing/tc_chart.rb +123 -123
- data/test/drawing/tc_d_lbls.rb +57 -57
- data/test/drawing/tc_data_source.rb +23 -23
- data/test/drawing/tc_drawing.rb +80 -80
- data/test/drawing/tc_graphic_frame.rb +27 -27
- data/test/drawing/tc_hyperlink.rb +64 -64
- data/test/drawing/tc_line_3d_chart.rb +47 -47
- data/test/drawing/tc_line_chart.rb +39 -39
- data/test/drawing/tc_line_series.rb +71 -71
- data/test/drawing/tc_marker.rb +44 -44
- data/test/drawing/tc_named_axis_data.rb +27 -27
- data/test/drawing/tc_num_data.rb +31 -31
- data/test/drawing/tc_num_val.rb +29 -29
- data/test/drawing/tc_one_cell_anchor.rb +66 -66
- data/test/drawing/tc_pic.rb +103 -103
- data/test/drawing/tc_picture_locking.rb +72 -72
- data/test/drawing/tc_pie_3D_chart.rb +28 -28
- data/test/drawing/tc_pie_series.rb +33 -33
- data/test/drawing/tc_scaling.rb +36 -36
- data/test/drawing/tc_scatter_chart.rb +48 -48
- data/test/drawing/tc_scatter_series.rb +74 -56
- data/test/drawing/tc_ser_axis.rb +31 -31
- data/test/drawing/tc_series.rb +23 -23
- data/test/drawing/tc_series_title.rb +54 -54
- data/test/drawing/tc_str_data.rb +18 -18
- data/test/drawing/tc_str_val.rb +30 -30
- data/test/drawing/tc_title.rb +70 -70
- data/test/drawing/tc_two_cell_anchor.rb +36 -36
- data/test/drawing/tc_val_axis.rb +24 -24
- data/test/drawing/tc_view_3D.rb +54 -54
- data/test/drawing/tc_vml_drawing.rb +25 -25
- data/test/drawing/tc_vml_shape.rb +106 -106
- data/test/profile.rb +24 -24
- data/test/rels/tc_relationship.rb +52 -52
- data/test/rels/tc_relationships.rb +37 -37
- data/test/stylesheet/tc_border.rb +37 -37
- data/test/stylesheet/tc_border_pr.rb +32 -32
- data/test/stylesheet/tc_cell_alignment.rb +81 -81
- data/test/stylesheet/tc_cell_protection.rb +29 -29
- data/test/stylesheet/tc_cell_style.rb +57 -57
- data/test/stylesheet/tc_color.rb +43 -43
- data/test/stylesheet/tc_dxf.rb +81 -81
- data/test/stylesheet/tc_fill.rb +18 -18
- data/test/stylesheet/tc_font.rb +133 -133
- data/test/stylesheet/tc_gradient_fill.rb +72 -72
- data/test/stylesheet/tc_gradient_stop.rb +31 -31
- data/test/stylesheet/tc_num_fmt.rb +30 -30
- data/test/stylesheet/tc_pattern_fill.rb +43 -43
- data/test/stylesheet/tc_styles.rb +309 -261
- data/test/stylesheet/tc_table_style.rb +44 -44
- data/test/stylesheet/tc_table_style_element.rb +45 -45
- data/test/stylesheet/tc_table_styles.rb +29 -29
- data/test/stylesheet/tc_xf.rb +120 -120
- data/test/tc_axlsx.rb +109 -109
- data/test/tc_helper.rb +10 -10
- data/test/tc_package.rb +317 -314
- data/test/util/tc_mime_type_utils.rb +13 -13
- data/test/util/tc_serialized_attributes.rb +19 -19
- data/test/util/tc_simple_typed_list.rb +77 -77
- data/test/util/tc_validators.rb +210 -210
- data/test/workbook/tc_defined_name.rb +49 -49
- data/test/workbook/tc_shared_strings_table.rb +59 -59
- data/test/workbook/tc_workbook.rb +165 -160
- data/test/workbook/tc_workbook_view.rb +50 -50
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -38
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -76
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -50
- data/test/workbook/worksheet/tc_break.rb +49 -49
- data/test/workbook/worksheet/tc_cell.rb +465 -453
- data/test/workbook/worksheet/tc_cfvo.rb +31 -31
- data/test/workbook/worksheet/tc_col.rb +93 -93
- data/test/workbook/worksheet/tc_color_scale.rb +58 -58
- data/test/workbook/worksheet/tc_comment.rb +72 -72
- data/test/workbook/worksheet/tc_comments.rb +57 -57
- data/test/workbook/worksheet/tc_conditional_formatting.rb +224 -224
- data/test/workbook/worksheet/tc_data_bar.rb +46 -46
- data/test/workbook/worksheet/tc_data_validation.rb +265 -265
- data/test/workbook/worksheet/tc_date_time_converter.rb +124 -124
- data/test/workbook/worksheet/tc_header_footer.rb +151 -151
- data/test/workbook/worksheet/tc_icon_set.rb +45 -45
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -19
- data/test/workbook/worksheet/tc_page_margins.rb +97 -97
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -15
- data/test/workbook/worksheet/tc_page_setup.rb +143 -143
- data/test/workbook/worksheet/tc_pane.rb +54 -54
- data/test/workbook/worksheet/tc_pivot_table.rb +180 -143
- data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +62 -62
- data/test/workbook/worksheet/tc_print_options.rb +72 -72
- data/test/workbook/worksheet/tc_protected_range.rb +17 -17
- data/test/workbook/worksheet/tc_rich_text.rb +44 -44
- data/test/workbook/worksheet/tc_rich_text_run.rb +173 -173
- data/test/workbook/worksheet/tc_row.rb +160 -160
- data/test/workbook/worksheet/tc_selection.rb +55 -55
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -18
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -88
- data/test/workbook/worksheet/tc_sheet_pr.rb +49 -49
- data/test/workbook/worksheet/tc_sheet_protection.rb +117 -117
- data/test/workbook/worksheet/tc_sheet_view.rb +214 -214
- data/test/workbook/worksheet/tc_table.rb +77 -77
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -53
- data/test/workbook/worksheet/tc_worksheet.rb +632 -601
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -55
- metadata +101 -101
@@ -1,453 +1,465 @@
|
|
1
|
-
require 'tc_helper.rb'
|
2
|
-
|
3
|
-
class TestCell < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
p = Axlsx::Package.new
|
7
|
-
p.use_shared_strings = true
|
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, :escape_formulas=>true
|
12
|
-
data = (0..26).map { |index| index }
|
13
|
-
@ws.add_row data
|
14
|
-
@cAA = @ws["AA2"]
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_initialize
|
18
|
-
assert_equal(@row.cells.last, @c, "the cell was added to the row")
|
19
|
-
assert_equal(@c.type, :float, "type option is applied")
|
20
|
-
assert_equal(@c.style, 1, "style option is applied")
|
21
|
-
assert_equal(@c.value, 1.0, "type option is applied and value is casted")
|
22
|
-
assert_equal(@c.escape_formulas, true, "escape formulas option is applied")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_style_date_data
|
26
|
-
c = Axlsx::Cell.new(@c.row, Time.now)
|
27
|
-
assert_equal(Axlsx::STYLE_DATE, c.style)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_row
|
31
|
-
assert_equal(@c.row, @row)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_index
|
35
|
-
assert_equal(@c.index, @row.cells.index(@c))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_pos
|
39
|
-
assert_equal(@c.pos, [@c.index, @c.row.index(@c)])
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_r
|
43
|
-
assert_equal(@c.r, "A1", "calculate cell reference")
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_wide_r
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_r_abs
|
51
|
-
assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference")
|
52
|
-
assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns")
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_name
|
56
|
-
@c.name = 'foo'
|
57
|
-
assert_equal(1, @ws.workbook.defined_names.size)
|
58
|
-
assert_equal('foo', @ws.workbook.defined_names.last.name)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_autowidth
|
62
|
-
style = @c.row.worksheet.workbook.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
|
63
|
-
@c.style = style
|
64
|
-
assert_in_delta(6.6, @c.autowidth, 0.01)
|
65
|
-
end
|
66
|
-
|
67
|
-
def
|
68
|
-
@c.
|
69
|
-
|
70
|
-
@c.
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def
|
75
|
-
@c.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
assert_equal(@c.value,
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
assert_equal(
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
assert_equal(@c.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
assert_equal(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
assert_equal(@c.send(:cell_type_from_value,
|
122
|
-
assert_equal(@c.send(:cell_type_from_value,
|
123
|
-
assert_equal(@c.send(:cell_type_from_value,
|
124
|
-
assert_equal(@c.send(:cell_type_from_value,
|
125
|
-
assert_equal(@c.send(:cell_type_from_value, 1
|
126
|
-
assert_equal(@c.send(:cell_type_from_value,
|
127
|
-
assert_equal(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
@c.type = :
|
169
|
-
assert_equal(@c.send(:cast_value,
|
170
|
-
|
171
|
-
@c.
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
@c.
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
assert_equal(@c.
|
198
|
-
end
|
199
|
-
|
200
|
-
def
|
201
|
-
assert_raise(ArgumentError) { @c.
|
202
|
-
assert_nothing_raised { @c.
|
203
|
-
assert_equal(@c.
|
204
|
-
end
|
205
|
-
|
206
|
-
def
|
207
|
-
assert_raise(ArgumentError) { @c.
|
208
|
-
assert_nothing_raised { @c.
|
209
|
-
assert_equal(@c.
|
210
|
-
end
|
211
|
-
|
212
|
-
def
|
213
|
-
assert_raise(ArgumentError) { @c.
|
214
|
-
assert_nothing_raised { @c.
|
215
|
-
assert_equal(@c.
|
216
|
-
end
|
217
|
-
|
218
|
-
def
|
219
|
-
assert_raise(ArgumentError) { @c.
|
220
|
-
assert_nothing_raised { @c.
|
221
|
-
assert_equal(@c.
|
222
|
-
end
|
223
|
-
|
224
|
-
def
|
225
|
-
assert_raise(ArgumentError) { @c.
|
226
|
-
assert_nothing_raised { @c.
|
227
|
-
assert_equal(@c.
|
228
|
-
end
|
229
|
-
|
230
|
-
def
|
231
|
-
assert_raise(ArgumentError) { @c.
|
232
|
-
assert_nothing_raised { @c.
|
233
|
-
assert_equal(@c.
|
234
|
-
end
|
235
|
-
|
236
|
-
def
|
237
|
-
assert_raise(ArgumentError) { @c.
|
238
|
-
assert_nothing_raised { @c.
|
239
|
-
assert_equal(@c.
|
240
|
-
end
|
241
|
-
|
242
|
-
def
|
243
|
-
@c.
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
def
|
264
|
-
assert_raise(ArgumentError) { @c.
|
265
|
-
assert_nothing_raised { @c.
|
266
|
-
assert_equal(@c.
|
267
|
-
end
|
268
|
-
|
269
|
-
def
|
270
|
-
assert_raise(ArgumentError) { @c.
|
271
|
-
assert_nothing_raised { @c.
|
272
|
-
assert_equal(@c.
|
273
|
-
end
|
274
|
-
|
275
|
-
def
|
276
|
-
assert_raise(ArgumentError) { @c.
|
277
|
-
assert_nothing_raised { @c.
|
278
|
-
assert_equal(@c.
|
279
|
-
end
|
280
|
-
|
281
|
-
def
|
282
|
-
@c.
|
283
|
-
@c.
|
284
|
-
@c.
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
@c.
|
290
|
-
@c.
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
@c.
|
297
|
-
@c.row.
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
@c.send :
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
@c.
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
@c.
|
317
|
-
assert_equal(@c.
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
@c.
|
323
|
-
|
324
|
-
|
325
|
-
@c.value = 'plain string'
|
326
|
-
@c.
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
assert_equal(
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
@
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
@c.
|
349
|
-
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
350
|
-
|
351
|
-
end
|
352
|
-
|
353
|
-
def
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
doc
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
doc
|
396
|
-
|
397
|
-
assert(doc.xpath("//
|
398
|
-
assert(doc.xpath("//f[
|
399
|
-
assert(doc.xpath("//
|
400
|
-
end
|
401
|
-
|
402
|
-
def
|
403
|
-
p = Axlsx::Package.new
|
404
|
-
ws = p.workbook.add_worksheet do |sheet|
|
405
|
-
sheet.add_row ["=
|
406
|
-
end
|
407
|
-
doc = Nokogiri::XML(ws.to_xml_string)
|
408
|
-
doc.remove_namespaces!
|
409
|
-
|
410
|
-
assert(doc.xpath("//f[
|
411
|
-
assert(doc.xpath("//
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
@
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestCell < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
p.use_shared_strings = true
|
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, :escape_formulas=>true
|
12
|
+
data = (0..26).map { |index| index }
|
13
|
+
@ws.add_row data
|
14
|
+
@cAA = @ws["AA2"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize
|
18
|
+
assert_equal(@row.cells.last, @c, "the cell was added to the row")
|
19
|
+
assert_equal(@c.type, :float, "type option is applied")
|
20
|
+
assert_equal(@c.style, 1, "style option is applied")
|
21
|
+
assert_equal(@c.value, 1.0, "type option is applied and value is casted")
|
22
|
+
assert_equal(@c.escape_formulas, true, "escape formulas option is applied")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_style_date_data
|
26
|
+
c = Axlsx::Cell.new(@c.row, Time.now)
|
27
|
+
assert_equal(Axlsx::STYLE_DATE, c.style)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_row
|
31
|
+
assert_equal(@c.row, @row)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_index
|
35
|
+
assert_equal(@c.index, @row.cells.index(@c))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_pos
|
39
|
+
assert_equal(@c.pos, [@c.index, @c.row.index(@c)])
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_r
|
43
|
+
assert_equal(@c.r, "A1", "calculate cell reference")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_wide_r
|
47
|
+
assert_equal(@cAA.r, "AA2", "calculate cell reference")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_r_abs
|
51
|
+
assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference")
|
52
|
+
assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns")
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_name
|
56
|
+
@c.name = 'foo'
|
57
|
+
assert_equal(1, @ws.workbook.defined_names.size)
|
58
|
+
assert_equal('foo', @ws.workbook.defined_names.last.name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_autowidth
|
62
|
+
style = @c.row.worksheet.workbook.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
|
63
|
+
@c.style = style
|
64
|
+
assert_in_delta(6.6, @c.autowidth, 0.01)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_autowidth_with_bold_font_multiplier
|
68
|
+
style = @c.row.worksheet.workbook.styles.add_style(b: true)
|
69
|
+
@c.row.worksheet.workbook.bold_font_multiplier = 1.05
|
70
|
+
@c.style = style
|
71
|
+
assert_in_delta(6.93, @c.autowidth, 0.01)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_autowidth_with_font_scale_divisor
|
75
|
+
@c.row.worksheet.workbook.font_scale_divisor = 11.0
|
76
|
+
assert_in_delta(6.0, @c.autowidth, 0.01)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_time
|
80
|
+
@c.type = :time
|
81
|
+
now = DateTime.now
|
82
|
+
@c.value = now
|
83
|
+
assert_equal(@c.value, now.to_time)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_date
|
87
|
+
@c.type = :date
|
88
|
+
now = Time.now
|
89
|
+
@c.value = now
|
90
|
+
assert_equal(@c.value, now.to_date)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_style
|
94
|
+
assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style=@c.row.worksheet.workbook.styles.cellXfs.size }
|
95
|
+
assert_nothing_raised("must allow valid style index changes") {@c.style=1}
|
96
|
+
assert_equal(@c.style, 1)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_type
|
100
|
+
assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
|
101
|
+
assert_nothing_raised("type can be changed") { @c.type = :string }
|
102
|
+
assert_equal(@c.value, "1.0", "changing type casts the value")
|
103
|
+
assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type')
|
104
|
+
assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
|
105
|
+
assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
|
106
|
+
assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_value
|
110
|
+
assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
|
111
|
+
assert_nothing_raised("type can be changed") { @c.type = :string }
|
112
|
+
assert_equal(@c.value, "1.0", "changing type casts the value")
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_col_ref
|
116
|
+
#TODO move to axlsx spec
|
117
|
+
assert_equal(Axlsx.col_ref(0), "A")
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_cell_type_from_value
|
121
|
+
assert_equal(@c.send(:cell_type_from_value, 1.0), :float)
|
122
|
+
assert_equal(@c.send(:cell_type_from_value, "1e1"), :float)
|
123
|
+
assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}"), :float)
|
124
|
+
assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}"), :string)
|
125
|
+
assert_equal(@c.send(:cell_type_from_value, "1e-1"), :float)
|
126
|
+
assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}"), :float)
|
127
|
+
assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}"), :string)
|
128
|
+
assert_equal(@c.send(:cell_type_from_value, 1), :integer)
|
129
|
+
assert_equal(@c.send(:cell_type_from_value, Date.today), :date)
|
130
|
+
assert_equal(@c.send(:cell_type_from_value, Time.now), :time)
|
131
|
+
assert_equal(@c.send(:cell_type_from_value, []), :string)
|
132
|
+
assert_equal(@c.send(:cell_type_from_value, "d"), :string)
|
133
|
+
assert_equal(@c.send(:cell_type_from_value, nil), :string)
|
134
|
+
assert_equal(@c.send(:cell_type_from_value, -1), :integer)
|
135
|
+
assert_equal(@c.send(:cell_type_from_value, true), :boolean)
|
136
|
+
assert_equal(@c.send(:cell_type_from_value, false), :boolean)
|
137
|
+
assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
|
138
|
+
assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext)
|
139
|
+
assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_cell_type_from_value_looks_like_number_but_is_not
|
143
|
+
mimic_number = Class.new do
|
144
|
+
def initialize(to_s_value)
|
145
|
+
@to_s_value = to_s_value
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_s
|
149
|
+
@to_s_value
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
number_strings = [
|
154
|
+
'1',
|
155
|
+
'1234567890',
|
156
|
+
'1.0',
|
157
|
+
'1e1',
|
158
|
+
'0',
|
159
|
+
"1e#{Float::MIN_10_EXP}"
|
160
|
+
]
|
161
|
+
|
162
|
+
number_strings.each do |number_string|
|
163
|
+
assert_equal(@c.send(:cell_type_from_value, mimic_number.new(number_string)), :string)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_cast_value
|
168
|
+
@c.type = :string
|
169
|
+
assert_equal(@c.send(:cast_value, 1.0), "1.0")
|
170
|
+
@c.type = :integer
|
171
|
+
assert_equal(@c.send(:cast_value, 1.0), 1)
|
172
|
+
@c.type = :float
|
173
|
+
assert_equal(@c.send(:cast_value, "1.0"), 1.0)
|
174
|
+
@c.type = :string
|
175
|
+
assert_equal(@c.send(:cast_value, nil), nil)
|
176
|
+
@c.type = :richtext
|
177
|
+
assert_equal(@c.send(:cast_value, nil), nil)
|
178
|
+
@c.type = :float
|
179
|
+
assert_equal(@c.send(:cast_value, nil), nil)
|
180
|
+
@c.type = :boolean
|
181
|
+
assert_equal(@c.send(:cast_value, true), 1)
|
182
|
+
assert_equal(@c.send(:cast_value, false), 0)
|
183
|
+
@c.type = :iso_8601
|
184
|
+
assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24"))
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_cast_time_subclass
|
188
|
+
subtime = Class.new(Time) do
|
189
|
+
def to_time
|
190
|
+
raise "#to_time of Time subclass should not be called"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
time = subtime.now
|
195
|
+
|
196
|
+
@c.type = :time
|
197
|
+
assert_equal(time, @c.send(:cast_value, time))
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_color
|
201
|
+
assert_raise(ArgumentError) { @c.color = -1.1 }
|
202
|
+
assert_nothing_raised { @c.color = "FF00FF00" }
|
203
|
+
assert_equal(@c.color.rgb, "FF00FF00")
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_scheme
|
207
|
+
assert_raise(ArgumentError) { @c.scheme = -1.1 }
|
208
|
+
assert_nothing_raised { @c.scheme = :major }
|
209
|
+
assert_equal(@c.scheme, :major)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_vertAlign
|
213
|
+
assert_raise(ArgumentError) { @c.vertAlign = -1.1 }
|
214
|
+
assert_nothing_raised { @c.vertAlign = :baseline }
|
215
|
+
assert_equal(@c.vertAlign, :baseline)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_sz
|
219
|
+
assert_raise(ArgumentError) { @c.sz = -1.1 }
|
220
|
+
assert_nothing_raised { @c.sz = 12 }
|
221
|
+
assert_equal(@c.sz, 12)
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_extend
|
225
|
+
assert_raise(ArgumentError) { @c.extend = -1.1 }
|
226
|
+
assert_nothing_raised { @c.extend = false }
|
227
|
+
assert_equal(@c.extend, false)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_condense
|
231
|
+
assert_raise(ArgumentError) { @c.condense = -1.1 }
|
232
|
+
assert_nothing_raised { @c.condense = false }
|
233
|
+
assert_equal(@c.condense, false)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_shadow
|
237
|
+
assert_raise(ArgumentError) { @c.shadow = -1.1 }
|
238
|
+
assert_nothing_raised { @c.shadow = false }
|
239
|
+
assert_equal(@c.shadow, false)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_outline
|
243
|
+
assert_raise(ArgumentError) { @c.outline = -1.1 }
|
244
|
+
assert_nothing_raised { @c.outline = false }
|
245
|
+
assert_equal(@c.outline, false)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_strike
|
249
|
+
assert_raise(ArgumentError) { @c.strike = -1.1 }
|
250
|
+
assert_nothing_raised { @c.strike = false }
|
251
|
+
assert_equal(@c.strike, false)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_u
|
255
|
+
@c.type = :string
|
256
|
+
assert_raise(ArgumentError) { @c.u = -1.1 }
|
257
|
+
assert_nothing_raised { @c.u = :single }
|
258
|
+
assert_equal(@c.u, :single)
|
259
|
+
doc = Nokogiri::XML(@c.to_xml_string(1,1))
|
260
|
+
assert(doc.xpath('//u[@val="single"]'))
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_i
|
264
|
+
assert_raise(ArgumentError) { @c.i = -1.1 }
|
265
|
+
assert_nothing_raised { @c.i = false }
|
266
|
+
assert_equal(@c.i, false)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_rFont
|
270
|
+
assert_raise(ArgumentError) { @c.font_name = -1.1 }
|
271
|
+
assert_nothing_raised { @c.font_name = "Arial" }
|
272
|
+
assert_equal(@c.font_name, "Arial")
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_charset
|
276
|
+
assert_raise(ArgumentError) { @c.charset = -1.1 }
|
277
|
+
assert_nothing_raised { @c.charset = 1 }
|
278
|
+
assert_equal(@c.charset, 1)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_family
|
282
|
+
assert_raise(ArgumentError) { @c.family = -1.1 }
|
283
|
+
assert_nothing_raised { @c.family = 5 }
|
284
|
+
assert_equal(@c.family, 5)
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_b
|
288
|
+
assert_raise(ArgumentError) { @c.b = -1.1 }
|
289
|
+
assert_nothing_raised { @c.b = false }
|
290
|
+
assert_equal(@c.b, false)
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_merge_with_string
|
294
|
+
@c.row.add_cell 2
|
295
|
+
@c.row.add_cell 3
|
296
|
+
@c.merge "A2"
|
297
|
+
assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:A2")
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_merge_with_cell
|
301
|
+
@c.row.add_cell 2
|
302
|
+
@c.row.add_cell 3
|
303
|
+
@c.merge @row.cells.last
|
304
|
+
assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_reverse_merge_with_cell
|
308
|
+
@c.row.add_cell 2
|
309
|
+
@c.row.add_cell 3
|
310
|
+
@row.cells.last.merge @c
|
311
|
+
assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_ssti
|
315
|
+
assert_raise(ArgumentError, "ssti must be an unsigned integer!") { @c.send(:ssti=, -1) }
|
316
|
+
@c.send :ssti=, 1
|
317
|
+
assert_equal(@c.ssti, 1)
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_plain_string
|
321
|
+
@c.type = :integer
|
322
|
+
assert_equal(@c.plain_string?, false)
|
323
|
+
|
324
|
+
@c.type = :string
|
325
|
+
@c.value = 'plain string'
|
326
|
+
assert_equal(@c.plain_string?, true)
|
327
|
+
|
328
|
+
@c.value = nil
|
329
|
+
assert_equal(@c.plain_string?, false)
|
330
|
+
|
331
|
+
@c.value = ''
|
332
|
+
assert_equal(@c.plain_string?, false)
|
333
|
+
|
334
|
+
@c.value = '=sum'
|
335
|
+
assert_equal(@c.plain_string?, false)
|
336
|
+
|
337
|
+
@c.value = 'plain string'
|
338
|
+
@c.font_name = 'Arial'
|
339
|
+
assert_equal(@c.plain_string?, false)
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_to_xml_string
|
343
|
+
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
344
|
+
assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_to_xml_string_nil
|
348
|
+
@c.value = nil
|
349
|
+
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
350
|
+
assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_to_xml_string_with_run
|
354
|
+
# Actually quite a number of similar run styles
|
355
|
+
# but the processing should be the same
|
356
|
+
@c.b = true
|
357
|
+
@c.type = :string
|
358
|
+
@c.value = "a"
|
359
|
+
@c.font_name = 'arial'
|
360
|
+
@c.color = 'FF0000'
|
361
|
+
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
362
|
+
assert(c_xml.xpath("//b").any?)
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_to_xml_string_formula
|
366
|
+
p = Axlsx::Package.new
|
367
|
+
ws = p.workbook.add_worksheet do |sheet|
|
368
|
+
sheet.add_row ["=IF(2+2=4,4,5)"]
|
369
|
+
end
|
370
|
+
doc = Nokogiri::XML(ws.to_xml_string)
|
371
|
+
doc.remove_namespaces!
|
372
|
+
assert(doc.xpath("//f[text()='IF(2+2=4,4,5)']").any?)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_to_xml_string_formula_escaped
|
376
|
+
p = Axlsx::Package.new
|
377
|
+
ws = p.workbook.add_worksheet do |sheet|
|
378
|
+
sheet.add_row ["=IF(2+2=4,4,5)"], escape_formulas: true
|
379
|
+
end
|
380
|
+
doc = Nokogiri::XML(ws.to_xml_string)
|
381
|
+
doc.remove_namespaces!
|
382
|
+
assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_to_xml_string_formula_escape_array_parameter
|
386
|
+
p = Axlsx::Package.new
|
387
|
+
ws = p.workbook.add_worksheet do |sheet|
|
388
|
+
sheet.add_row [
|
389
|
+
"=IF(2+2=4,4,5)",
|
390
|
+
"=IF(13+13=4,4,5)",
|
391
|
+
"=IF(99+99=4,4,5)"
|
392
|
+
], escape_formulas: [true, false, true]
|
393
|
+
end
|
394
|
+
doc = Nokogiri::XML(ws.to_xml_string)
|
395
|
+
doc.remove_namespaces!
|
396
|
+
|
397
|
+
assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
|
398
|
+
assert(doc.xpath("//f[text()='IF(13+13=4,4,5)']").any?)
|
399
|
+
assert(doc.xpath("//t[text()='=IF(99+99=4,4,5)']").any?)
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_to_xml_string_array_formula
|
403
|
+
p = Axlsx::Package.new
|
404
|
+
ws = p.workbook.add_worksheet do |sheet|
|
405
|
+
sheet.add_row ["{=SUM(C2:C11*D2:D11)}"]
|
406
|
+
end
|
407
|
+
doc = Nokogiri::XML(ws.to_xml_string)
|
408
|
+
doc.remove_namespaces!
|
409
|
+
assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']").any?)
|
410
|
+
assert(doc.xpath("//f[@t='array']").any?)
|
411
|
+
assert(doc.xpath("//f[@ref='A1']").any?)
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_to_xml_string_text_formula
|
415
|
+
p = Axlsx::Package.new
|
416
|
+
ws = p.workbook.add_worksheet do |sheet|
|
417
|
+
sheet.add_row ["=1+1", "-1+1"], type: :text
|
418
|
+
end
|
419
|
+
doc = Nokogiri::XML(ws.to_xml_string)
|
420
|
+
doc.remove_namespaces!
|
421
|
+
|
422
|
+
assert(doc.xpath("//f[text()='1+1']").empty?)
|
423
|
+
assert(doc.xpath("//t[text()='=1+1']").any?)
|
424
|
+
|
425
|
+
assert(doc.xpath("//f[text()='1+1']").empty?)
|
426
|
+
assert(doc.xpath("//t[text()='-1+1']").any?)
|
427
|
+
end
|
428
|
+
|
429
|
+
def test_font_size_with_custom_style_and_no_sz
|
430
|
+
@c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
|
431
|
+
sz = @c.send(:font_size)
|
432
|
+
assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_font_size_with_bolding
|
436
|
+
@c.style = @c.row.worksheet.workbook.styles.add_style :b => true
|
437
|
+
assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size))
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_font_size_with_custom_sz
|
441
|
+
@c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
|
442
|
+
sz = @c.send(:font_size)
|
443
|
+
assert_equal(sz, 52)
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_cell_with_sz
|
447
|
+
@c.sz = 25
|
448
|
+
assert_equal(25, @c.send(:font_size))
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_to_xml
|
452
|
+
# TODO This could use some much more stringent testing related to the xml content generated!
|
453
|
+
@ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"]
|
454
|
+
@ws.rows.last.cells[5].u = true
|
455
|
+
|
456
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
457
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
458
|
+
errors = []
|
459
|
+
schema.validate(doc).each do |error|
|
460
|
+
errors.push error
|
461
|
+
puts error.message
|
462
|
+
end
|
463
|
+
assert(errors.empty?, "error free validation")
|
464
|
+
end
|
465
|
+
end
|