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
|
@@ -60,7 +60,7 @@ class TestCell < Test::Unit::TestCase
|
|
|
60
60
|
assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
|
|
61
61
|
assert_nothing_raised("type can be changed") { @c.type = :string }
|
|
62
62
|
assert_equal(@c.value, "1.0", "changing type casts the value")
|
|
63
|
-
|
|
63
|
+
assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type')
|
|
64
64
|
assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
|
|
65
65
|
assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
|
|
66
66
|
assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
|
|
@@ -88,6 +88,8 @@ class TestCell < Test::Unit::TestCase
|
|
|
88
88
|
assert_equal(@c.send(:cell_type_from_value, -1), :integer)
|
|
89
89
|
assert_equal(@c.send(:cell_type_from_value, true), :boolean)
|
|
90
90
|
assert_equal(@c.send(:cell_type_from_value, false), :boolean)
|
|
91
|
+
assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
|
|
92
|
+
assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
|
|
91
93
|
end
|
|
92
94
|
|
|
93
95
|
def test_cast_value
|
|
@@ -104,6 +106,8 @@ class TestCell < Test::Unit::TestCase
|
|
|
104
106
|
@c.type = :boolean
|
|
105
107
|
assert_equal(@c.send(:cast_value, true), 1)
|
|
106
108
|
assert_equal(@c.send(:cast_value, false), 0)
|
|
109
|
+
@c.type = :iso_8601
|
|
110
|
+
assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24"))
|
|
107
111
|
end
|
|
108
112
|
|
|
109
113
|
def test_color
|
|
@@ -161,9 +165,12 @@ class TestCell < Test::Unit::TestCase
|
|
|
161
165
|
end
|
|
162
166
|
|
|
163
167
|
def test_u
|
|
168
|
+
@c.type = :string
|
|
164
169
|
assert_raise(ArgumentError) { @c.u = -1.1 }
|
|
165
|
-
assert_nothing_raised { @c.u =
|
|
166
|
-
assert_equal(@c.u,
|
|
170
|
+
assert_nothing_raised { @c.u = :single }
|
|
171
|
+
assert_equal(@c.u, :single)
|
|
172
|
+
doc = Nokogiri::XML(@c.to_xml_string(1,1))
|
|
173
|
+
assert(doc.xpath('//u[@val="single"]'))
|
|
167
174
|
end
|
|
168
175
|
|
|
169
176
|
def test_i
|
|
@@ -186,8 +193,8 @@ class TestCell < Test::Unit::TestCase
|
|
|
186
193
|
|
|
187
194
|
def test_family
|
|
188
195
|
assert_raise(ArgumentError) { @c.family = -1.1 }
|
|
189
|
-
assert_nothing_raised { @c.family =
|
|
190
|
-
assert_equal(@c.family,
|
|
196
|
+
assert_nothing_raised { @c.family = 5 }
|
|
197
|
+
assert_equal(@c.family, 5)
|
|
191
198
|
end
|
|
192
199
|
|
|
193
200
|
def test_b
|
|
@@ -250,6 +257,8 @@ class TestCell < Test::Unit::TestCase
|
|
|
250
257
|
end
|
|
251
258
|
|
|
252
259
|
def test_to_xml_string_with_run
|
|
260
|
+
# Actually quite a number of similar run styles
|
|
261
|
+
# but the processing should be the same
|
|
253
262
|
@c.b = true
|
|
254
263
|
@c.type = :string
|
|
255
264
|
@c.value = "a"
|
|
@@ -258,6 +267,7 @@ class TestCell < Test::Unit::TestCase
|
|
|
258
267
|
c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
|
|
259
268
|
assert(c_xml.xpath("//b"))
|
|
260
269
|
end
|
|
270
|
+
|
|
261
271
|
def test_to_xml_string_formula
|
|
262
272
|
p = Axlsx::Package.new
|
|
263
273
|
ws = p.workbook.add_worksheet do |sheet|
|
|
@@ -268,9 +278,33 @@ class TestCell < Test::Unit::TestCase
|
|
|
268
278
|
|
|
269
279
|
end
|
|
270
280
|
|
|
281
|
+
def test_font_size_with_custom_style_and_no_sz
|
|
282
|
+
@c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
|
|
283
|
+
sz = @c.send(:font_size)
|
|
284
|
+
assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def test_font_size_with_bolding
|
|
288
|
+
@c.style = @c.row.worksheet.workbook.styles.add_style :b => true
|
|
289
|
+
assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size))
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def test_font_size_with_custom_sz
|
|
293
|
+
@c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
|
|
294
|
+
sz = @c.send(:font_size)
|
|
295
|
+
assert_equal(sz, 52)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def test_cell_with_sz
|
|
300
|
+
@c.sz = 25
|
|
301
|
+
assert_equal(25, @c.send(:font_size))
|
|
302
|
+
end
|
|
271
303
|
def test_to_xml
|
|
272
304
|
# TODO This could use some much more stringent testing related to the xml content generated!
|
|
273
|
-
@ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)"]
|
|
305
|
+
@ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"]
|
|
306
|
+
@ws.rows.last.cells[5].u = true
|
|
307
|
+
|
|
274
308
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
|
275
309
|
doc = Nokogiri::XML(@ws.to_xml_string)
|
|
276
310
|
errors = []
|
|
@@ -7,7 +7,7 @@ class TestCol < Test::Unit::TestCase
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def test_initialize
|
|
10
|
-
options = { :width => 12, :collapsed => true, :hidden => true, :
|
|
10
|
+
options = { :width => 12, :collapsed => true, :hidden => true, :outline_level => 1, :phonetic => true, :style => 1}
|
|
11
11
|
|
|
12
12
|
col = Axlsx::Col.new 0, 0, options
|
|
13
13
|
options.each{ |key, value| assert_equal(col.send(key.to_sym), value) }
|
|
@@ -58,6 +58,16 @@ class TestCol < Test::Unit::TestCase
|
|
|
58
58
|
assert_nothing_raised(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = true }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
def test_to_xml_string
|
|
62
|
+
@col.width = 100
|
|
63
|
+
doc = Nokogiri::XML(@col.to_xml_string)
|
|
64
|
+
assert_equal(1, doc.xpath("//col [@bestFit='#{@col.best_fit}']").size)
|
|
65
|
+
assert_equal(1, doc.xpath("//col [@max=#{@col.max}]").size)
|
|
66
|
+
assert_equal(1, doc.xpath("//col [@min=#{@col.min}]").size)
|
|
67
|
+
assert_equal(1, doc.xpath("//col [@width=#{@col.width}]").size)
|
|
68
|
+
assert_equal(1, doc.xpath("//col [@customWidth='#{@col.custom_width}']").size)
|
|
69
|
+
end
|
|
70
|
+
|
|
61
71
|
def test_style
|
|
62
72
|
assert_equal(@col.style, nil)
|
|
63
73
|
@col.style = 1
|
|
@@ -5,6 +5,37 @@ class TestColorScale < Test::Unit::TestCase
|
|
|
5
5
|
@color_scale = Axlsx::ColorScale.new
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
def test_three_tone
|
|
9
|
+
color_scale = Axlsx::ColorScale.three_tone
|
|
10
|
+
assert_equal 3, color_scale.value_objects.size
|
|
11
|
+
assert_equal 3, color_scale.colors.size
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_two_tone
|
|
15
|
+
color_scale = Axlsx::ColorScale.two_tone
|
|
16
|
+
assert_equal 2, color_scale.value_objects.size
|
|
17
|
+
assert_equal 2, color_scale.colors.size
|
|
18
|
+
end
|
|
19
|
+
def test_default_cfvo
|
|
20
|
+
first = Axlsx::ColorScale.default_cfvos.first
|
|
21
|
+
second = Axlsx::ColorScale.default_cfvos.last
|
|
22
|
+
assert_equal 'FFFF7128', first[:color]
|
|
23
|
+
assert_equal :min,first[:type]
|
|
24
|
+
assert_equal 0, first[:val]
|
|
25
|
+
|
|
26
|
+
assert_equal 'FFFFEF9C', second[:color]
|
|
27
|
+
assert_equal :max, second[:type]
|
|
28
|
+
assert_equal 0, second[:val]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_partial_default_cfvo_override
|
|
32
|
+
first_def = {:type => :percent, :val => "10.0", :color => 'FF00FF00'}
|
|
33
|
+
color_scale = Axlsx::ColorScale.new(first_def)
|
|
34
|
+
assert_equal color_scale.value_objects.first.val, first_def[:val]
|
|
35
|
+
assert_equal color_scale.value_objects.first.type, first_def[:type]
|
|
36
|
+
assert_equal color_scale.colors.first.rgb, first_def[:color]
|
|
37
|
+
end
|
|
38
|
+
|
|
8
39
|
def test_add
|
|
9
40
|
@color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE"
|
|
10
41
|
assert_equal(@color_scale.value_objects.size,3)
|
|
@@ -12,8 +43,6 @@ class TestColorScale < Test::Unit::TestCase
|
|
|
12
43
|
end
|
|
13
44
|
|
|
14
45
|
def test_delete_at
|
|
15
|
-
assert_raise(ArgumentError, "minimum two are protected") { @color_scale.delete_at 0 }
|
|
16
|
-
assert_raise(ArgumentError, "minimum two are protected") { @color_scale.delete_at 1 }
|
|
17
46
|
@color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE"
|
|
18
47
|
assert_nothing_raised {@color_scale.delete_at 2}
|
|
19
48
|
assert_equal(@color_scale.value_objects.size,2)
|
|
@@ -5,7 +5,7 @@ class TestComment < Test::Unit::TestCase
|
|
|
5
5
|
p = Axlsx::Package.new
|
|
6
6
|
wb = p.workbook
|
|
7
7
|
@ws = wb.add_worksheet
|
|
8
|
-
@c1 = @ws.add_comment :ref => 'A1', :text => '
|
|
8
|
+
@c1 = @ws.add_comment :ref => 'A1', :text => 'text with special char <', :author => 'author with special char <', :visible => false
|
|
9
9
|
@c2 = @ws.add_comment :ref => 'C3', :text => 'rust bucket', :author => 'PO'
|
|
10
10
|
end
|
|
11
11
|
|
|
@@ -14,12 +14,12 @@ class TestComment < Test::Unit::TestCase
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def test_author
|
|
17
|
-
assert(@c1.author == '
|
|
17
|
+
assert(@c1.author == 'author with special char <')
|
|
18
18
|
assert(@c2.author == 'PO')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def test_text
|
|
22
|
-
assert(@c1.text == '
|
|
22
|
+
assert(@c1.text == 'text with special char <')
|
|
23
23
|
assert(@c2.text == 'rust bucket')
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -28,6 +28,10 @@ class TestComment < Test::Unit::TestCase
|
|
|
28
28
|
assert_equal(@c2.author_index, 0)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def test_visible
|
|
32
|
+
assert_equal(false, @c1.visible)
|
|
33
|
+
assert_equal(true, @c2.visible)
|
|
34
|
+
end
|
|
31
35
|
def test_ref
|
|
32
36
|
assert(@c1.ref == 'A1')
|
|
33
37
|
assert(@c2.ref == 'C3')
|
|
@@ -45,13 +49,24 @@ class TestComment < Test::Unit::TestCase
|
|
|
45
49
|
assert(@c1.vml_shape.bottom_row == pos[1]+4)
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
def
|
|
52
|
+
def test_to_xml_string
|
|
49
53
|
doc = Nokogiri::XML(@c1.to_xml_string)
|
|
50
54
|
assert_equal(doc.xpath("//comment[@ref='#{@c1.ref}']").size, 1)
|
|
51
|
-
assert_equal(doc.xpath("//comment[@authorId='#{@c1.author_index.
|
|
52
|
-
assert_equal(doc.xpath("//t[text()='#{@c1.author}']").size, 1)
|
|
55
|
+
assert_equal(doc.xpath("//comment[@authorId='#{@c1.author_index.to_s}']").size, 1)
|
|
56
|
+
assert_equal(doc.xpath("//t[text()='#{@c1.author}:\n']").size, 1)
|
|
53
57
|
assert_equal(doc.xpath("//t[text()='#{@c1.text}']").size, 1)
|
|
54
58
|
end
|
|
55
59
|
|
|
60
|
+
def test_comment_text_contain_author_and_text
|
|
61
|
+
comment = @ws.add_comment :ref => 'C4', :text => 'some text', :author => 'Bob'
|
|
62
|
+
doc = Nokogiri::XML(comment.to_xml_string)
|
|
63
|
+
assert_equal("Bob:\nsome text", doc.xpath("//comment/text").text)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_comment_text_does_not_contain_stray_colon_if_author_blank
|
|
67
|
+
comment = @ws.add_comment :ref => 'C5', :text => 'some text', :author => ''
|
|
68
|
+
doc = Nokogiri::XML(comment.to_xml_string)
|
|
69
|
+
assert_equal("some text", doc.xpath("//comment/text").text)
|
|
70
|
+
end
|
|
56
71
|
end
|
|
57
72
|
|
|
@@ -25,9 +25,9 @@ class TestComments < Test::Unit::TestCase
|
|
|
25
25
|
end
|
|
26
26
|
def test_authors
|
|
27
27
|
assert_equal(@ws.comments.authors.size, @ws.comments.size)
|
|
28
|
-
@ws.add_comment(:text => 'Yes We Can!', :author =>
|
|
28
|
+
@ws.add_comment(:text => 'Yes We Can!', :author => 'bob', :ref => 'F1')
|
|
29
29
|
assert_equal(@ws.comments.authors.size, 3)
|
|
30
|
-
@ws.add_comment(:text => 'Yes We Can!', :author =>
|
|
30
|
+
@ws.add_comment(:text => 'Yes We Can!', :author => 'bob', :ref => 'F1')
|
|
31
31
|
assert_equal(@ws.comments.authors.size, 3, 'only unique authors are returned')
|
|
32
32
|
end
|
|
33
33
|
def test_pn
|
|
@@ -130,6 +130,13 @@ class TestConditionalFormatting < Test::Unit::TestCase
|
|
|
130
130
|
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'")
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
+
def test_multiple_formulas
|
|
134
|
+
@ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1 <> 2","5"] }
|
|
135
|
+
doc = Nokogiri::XML.parse(@ws.to_xml_string)
|
|
136
|
+
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1 <> 2'")
|
|
137
|
+
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='5'")
|
|
138
|
+
end
|
|
139
|
+
|
|
133
140
|
def test_sqref
|
|
134
141
|
assert_raise(ArgumentError) { @cf.sqref = 10 }
|
|
135
142
|
assert_nothing_raised { @cf.sqref = "A1:A1" }
|
|
@@ -11,6 +11,13 @@ class TestDataBar < Test::Unit::TestCase
|
|
|
11
11
|
assert_equal @data_bar.showValue, true
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def test_override_default_cfvos
|
|
15
|
+
data_bar = Axlsx::DataBar.new({:color => 'FF00FF00'}, {:type => :min, :val => "20"})
|
|
16
|
+
assert_equal("20", data_bar.value_objects.first.val)
|
|
17
|
+
assert_equal("0", data_bar.value_objects.last.val)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
14
21
|
def test_minLength
|
|
15
22
|
assert_raise(ArgumentError) { @data_bar.minLength = :invalid_type }
|
|
16
23
|
assert_nothing_raised { @data_bar.minLength = 0}
|
|
@@ -113,20 +113,12 @@ class TestDateTimeConverter < Test::Unit::TestCase
|
|
|
113
113
|
def test_timezone
|
|
114
114
|
|
|
115
115
|
utc = Time.utc 2012 # January 1st, 2012 at 0:00 UTC
|
|
116
|
-
|
|
117
|
-
# JRuby makes no assumption on time zone. randym
|
|
118
|
-
#local = begin
|
|
119
|
-
# Time.new 2012, 1, 1, 1, 0, 0, 3600 # January 1st, 2012 at 1:00 GMT+1
|
|
120
|
-
#rescue ArgumentError
|
|
121
|
-
# Time.parse "2012-01-01 01:00:00 +0100"
|
|
122
|
-
#end
|
|
123
|
-
|
|
124
|
-
local = Time.parse "2012-01-01 01:00:00 +0100"
|
|
116
|
+
local = Time.parse "2012-01-01 09:00:00 +0900"
|
|
125
117
|
|
|
126
118
|
assert_equal local, utc
|
|
127
|
-
assert_equal Axlsx::DateTimeConverter::time_to_serial(local),
|
|
119
|
+
assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - local.utc_offset.to_f/86400, Axlsx::DateTimeConverter::time_to_serial(utc)
|
|
128
120
|
Axlsx::Workbook.date1904 = true
|
|
129
|
-
assert_equal Axlsx::DateTimeConverter::time_to_serial(local), Axlsx::DateTimeConverter::time_to_serial(utc)
|
|
121
|
+
assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - local.utc_offset.to_f/86400, Axlsx::DateTimeConverter::time_to_serial(utc)
|
|
130
122
|
end
|
|
131
123
|
|
|
132
124
|
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
require 'tc_helper'
|
|
2
|
+
|
|
3
|
+
class TestHeaderFooter < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@p = Axlsx::Package.new
|
|
7
|
+
ws = @p.workbook.add_worksheet :name => 'test'
|
|
8
|
+
@hf = ws.header_footer
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_initialize
|
|
12
|
+
assert_equal(nil, @hf.odd_header)
|
|
13
|
+
assert_equal(nil, @hf.odd_footer)
|
|
14
|
+
|
|
15
|
+
assert_equal(nil, @hf.even_header)
|
|
16
|
+
assert_equal(nil, @hf.even_footer)
|
|
17
|
+
|
|
18
|
+
assert_equal(nil, @hf.first_header)
|
|
19
|
+
assert_equal(nil, @hf.first_footer)
|
|
20
|
+
|
|
21
|
+
assert_equal(nil, @hf.different_first)
|
|
22
|
+
assert_equal(nil, @hf.different_odd_even)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_initialize_with_options
|
|
26
|
+
header_footer = {
|
|
27
|
+
:odd_header => 'oh',
|
|
28
|
+
:odd_footer => 'of',
|
|
29
|
+
|
|
30
|
+
:even_header => 'eh',
|
|
31
|
+
:even_footer => 'ef',
|
|
32
|
+
|
|
33
|
+
:first_header => 'fh',
|
|
34
|
+
:first_footer => 'ff',
|
|
35
|
+
|
|
36
|
+
:different_first => true,
|
|
37
|
+
:different_odd_even => true
|
|
38
|
+
}
|
|
39
|
+
optioned = @p.workbook.add_worksheet(:name => 'optioned', :header_footer => header_footer).header_footer
|
|
40
|
+
|
|
41
|
+
assert_equal('oh', optioned.odd_header)
|
|
42
|
+
assert_equal('of', optioned.odd_footer)
|
|
43
|
+
|
|
44
|
+
assert_equal('eh', optioned.even_header)
|
|
45
|
+
assert_equal('ef', optioned.even_footer)
|
|
46
|
+
|
|
47
|
+
assert_equal('fh', optioned.first_header)
|
|
48
|
+
assert_equal('ff', optioned.first_footer)
|
|
49
|
+
|
|
50
|
+
assert_equal(true, optioned.different_first)
|
|
51
|
+
assert_equal(true, optioned.different_odd_even)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_string_attributes
|
|
55
|
+
%w(odd_header odd_footer even_header even_footer first_header first_footer).each do |attr|
|
|
56
|
+
assert_raise(ArgumentError, 'only strings allowed in string attributes') { @hf.send("#{attr}=", 1) }
|
|
57
|
+
assert_nothing_raised { @hf.send("#{attr}=", 'test_string') }
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_boolean_attributes
|
|
62
|
+
%w(different_first different_odd_even).each do |attr|
|
|
63
|
+
assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @hf.send("#{attr}=", 'foo') }
|
|
64
|
+
assert_nothing_raised { @hf.send("#{attr}=", 1) }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_set_all_values
|
|
69
|
+
@hf.set(
|
|
70
|
+
:odd_header => 'oh',
|
|
71
|
+
:odd_footer => 'of',
|
|
72
|
+
|
|
73
|
+
:even_header => 'eh',
|
|
74
|
+
:even_footer => 'ef',
|
|
75
|
+
|
|
76
|
+
:first_header => 'fh',
|
|
77
|
+
:first_footer => 'ff',
|
|
78
|
+
|
|
79
|
+
:different_first => true,
|
|
80
|
+
:different_odd_even => true
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
assert_equal('oh', @hf.odd_header)
|
|
84
|
+
assert_equal('of', @hf.odd_footer)
|
|
85
|
+
|
|
86
|
+
assert_equal('eh', @hf.even_header)
|
|
87
|
+
assert_equal('ef', @hf.even_footer)
|
|
88
|
+
|
|
89
|
+
assert_equal('fh', @hf.first_header)
|
|
90
|
+
assert_equal('ff', @hf.first_footer)
|
|
91
|
+
|
|
92
|
+
assert_equal(true, @hf.different_first)
|
|
93
|
+
assert_equal(true, @hf.different_odd_even)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_to_xml_all_values
|
|
97
|
+
@hf.set(
|
|
98
|
+
:odd_header => 'oh',
|
|
99
|
+
:odd_footer => 'of',
|
|
100
|
+
|
|
101
|
+
:even_header => 'eh',
|
|
102
|
+
:even_footer => 'ef',
|
|
103
|
+
|
|
104
|
+
:first_header => 'fh',
|
|
105
|
+
:first_footer => 'ff',
|
|
106
|
+
|
|
107
|
+
:different_first => true,
|
|
108
|
+
:different_odd_even => true
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
doc = Nokogiri::XML.parse(@hf.to_xml_string)
|
|
112
|
+
assert_equal(1, doc.xpath(".//headerFooter[@differentFirst='true'][@differentOddEven='true']").size)
|
|
113
|
+
|
|
114
|
+
assert_equal(1, doc.xpath(".//headerFooter/oddHeader").size)
|
|
115
|
+
assert_equal('oh', doc.xpath(".//headerFooter/oddHeader").text)
|
|
116
|
+
assert_equal(1, doc.xpath(".//headerFooter/oddFooter").size)
|
|
117
|
+
assert_equal('of', doc.xpath(".//headerFooter/oddFooter").text)
|
|
118
|
+
|
|
119
|
+
assert_equal(1, doc.xpath(".//headerFooter/evenHeader").size)
|
|
120
|
+
assert_equal('eh', doc.xpath(".//headerFooter/evenHeader").text)
|
|
121
|
+
assert_equal(1, doc.xpath(".//headerFooter/evenFooter").size)
|
|
122
|
+
assert_equal('ef', doc.xpath(".//headerFooter/evenFooter").text)
|
|
123
|
+
|
|
124
|
+
assert_equal(1, doc.xpath(".//headerFooter/firstHeader").size)
|
|
125
|
+
assert_equal('fh', doc.xpath(".//headerFooter/firstHeader").text)
|
|
126
|
+
assert_equal(1, doc.xpath(".//headerFooter/firstFooter").size)
|
|
127
|
+
assert_equal('ff', doc.xpath(".//headerFooter/firstFooter").text)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_to_xml_some_values
|
|
131
|
+
@hf.set(
|
|
132
|
+
:odd_header => 'oh',
|
|
133
|
+
:different_odd_even => false
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
doc = Nokogiri::XML.parse(@hf.to_xml_string)
|
|
137
|
+
assert_equal(1, doc.xpath(".//headerFooter[@differentOddEven='false']").size)
|
|
138
|
+
assert_equal(0, doc.xpath(".//headerFooter[@differentFirst]").size)
|
|
139
|
+
|
|
140
|
+
assert_equal(1, doc.xpath(".//headerFooter/oddHeader").size)
|
|
141
|
+
assert_equal('oh', doc.xpath(".//headerFooter/oddHeader").text)
|
|
142
|
+
assert_equal(0, doc.xpath(".//headerFooter/oddFooter").size)
|
|
143
|
+
|
|
144
|
+
assert_equal(0, doc.xpath(".//headerFooter/evenHeader").size)
|
|
145
|
+
assert_equal(0, doc.xpath(".//headerFooter/evenFooter").size)
|
|
146
|
+
|
|
147
|
+
assert_equal(0, doc.xpath(".//headerFooter/firstHeader").size)
|
|
148
|
+
assert_equal(0, doc.xpath(".//headerFooter/firstFooter").size)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'tc_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestPageSetUpPr < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@page_setup_pr = Axlsx::PageSetUpPr.new(:fit_to_page => true, :auto_page_breaks => true)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_fit_to_page
|
|
9
|
+
assert_equal true, @page_setup_pr.fit_to_page
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_auto_page_breaks
|
|
13
|
+
assert_equal true, @page_setup_pr.auto_page_breaks
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -44,6 +44,11 @@ class TestPageSetup < Test::Unit::TestCase
|
|
|
44
44
|
assert_equal(50, @ps.scale)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
def test_paper_size
|
|
48
|
+
assert_raise(ArgumentError) { @ps.paper_size = 119 }
|
|
49
|
+
assert_nothing_raised { @ps.paper_size = 10 }
|
|
50
|
+
end
|
|
51
|
+
|
|
47
52
|
def test_set_some_values
|
|
48
53
|
@ps.set(:fit_to_width => 2, :orientation => :portrait)
|
|
49
54
|
assert_equal(2, @ps.fit_to_width)
|
|
@@ -58,7 +63,7 @@ class TestPageSetup < Test::Unit::TestCase
|
|
|
58
63
|
assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil)
|
|
59
64
|
assert(@ps.fit_to_page? == false)
|
|
60
65
|
end
|
|
61
|
-
|
|
66
|
+
|
|
62
67
|
def test_with_height_fit_to_page?
|
|
63
68
|
assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil)
|
|
64
69
|
@ps.set(:fit_to_height => 1)
|
|
@@ -7,61 +7,21 @@ class TestPane < Test::Unit::TestCase
|
|
|
7
7
|
#inverse defaults for booleans
|
|
8
8
|
@nil_options = { :active_pane => :bottom_left, :state => :frozen, :top_left_cell => 'A2' }
|
|
9
9
|
@int_0_options = { :x_split => 2, :y_split => 2 }
|
|
10
|
-
|
|
11
|
-
@string_options = { :top_left_cell => 'A2' }
|
|
12
|
-
@integer_options = { :x_split => 2, :y_split => 2 }
|
|
13
|
-
@symbol_options = { :active_pane => :bottom_left, :state => :frozen }
|
|
14
|
-
|
|
15
|
-
@options = @nil_options.merge(@int_0_options)
|
|
16
|
-
|
|
10
|
+
@options = @nil_options.merge(@int_0_options)
|
|
17
11
|
@pane = Axlsx::Pane.new(@options)
|
|
18
12
|
end
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
pane = Axlsx::Pane.new
|
|
22
|
-
|
|
23
|
-
@nil_options.each do |key, value|
|
|
24
|
-
assert_equal(nil, pane.send(key.to_sym), "initialized default #{key} should be nil")
|
|
25
|
-
assert_equal(value, @pane.send(key.to_sym), "initialized options #{key} should be #{value}")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
@int_0_options.each do |key, value|
|
|
29
|
-
assert_equal(0, pane.send(key.to_sym), "initialized default #{key} should be 0")
|
|
30
|
-
assert_equal(value, @pane.send(key.to_sym), "initialized options #{key} should be #{value}")
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_string_attribute_validation
|
|
35
|
-
@string_options.each do |key, value|
|
|
36
|
-
assert_raise(ArgumentError, "#{key} must be string") { @pane.send("#{key}=".to_sym, :symbol) }
|
|
37
|
-
assert_nothing_raised { @pane.send("#{key}=".to_sym, "foo") }
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_symbol_attribute_validation
|
|
42
|
-
@symbol_options.each do |key, value|
|
|
43
|
-
assert_raise(ArgumentError, "#{key} must be symbol") { @pane.send("#{key}=".to_sym, "foo") }
|
|
44
|
-
assert_nothing_raised { @pane.send("#{key}=".to_sym, value) }
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_integer_attribute_validation
|
|
49
|
-
@integer_options.each do |key, value|
|
|
50
|
-
assert_raise(ArgumentError, "#{key} must be integer") { @pane.send("#{key}=".to_sym, "foo") }
|
|
51
|
-
assert_nothing_raised { @pane.send("#{key}=".to_sym, value) }
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
13
|
+
|
|
14
|
+
|
|
55
15
|
def test_active_pane
|
|
56
16
|
assert_raise(ArgumentError) { @pane.active_pane = "10" }
|
|
57
17
|
assert_nothing_raised { @pane.active_pane = :top_left }
|
|
58
|
-
assert_equal(@pane.active_pane,
|
|
18
|
+
assert_equal(@pane.active_pane, "topLeft")
|
|
59
19
|
end
|
|
60
20
|
|
|
61
21
|
def test_state
|
|
62
22
|
assert_raise(ArgumentError) { @pane.state = "foo" }
|
|
63
23
|
assert_nothing_raised { @pane.state = :frozen_split }
|
|
64
|
-
assert_equal(@pane.state,
|
|
24
|
+
assert_equal(@pane.state, "frozenSplit")
|
|
65
25
|
end
|
|
66
26
|
|
|
67
27
|
def test_x_split
|