axlsx 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +13 -5
- data/examples/colored_links.rb +59 -0
- data/examples/example.rb +421 -266
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/finance.rb +82 -0
- data/examples/finance.xlsx +0 -0
- data/examples/financial.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/where_is_my_color.xlsx +0 -0
- data/lib/axlsx.rb +11 -4
- 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 +7 -4
- data/lib/axlsx/drawing/axis.rb +3 -3
- data/lib/axlsx/drawing/chart.rb +2 -3
- data/lib/axlsx/drawing/d_lbls.rb +21 -31
- data/lib/axlsx/drawing/drawing.rb +6 -0
- data/lib/axlsx/drawing/hyperlink.rb +40 -32
- data/lib/axlsx/drawing/marker.rb +13 -13
- 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 +20 -22
- data/lib/axlsx/drawing/pic.rb +25 -27
- data/lib/axlsx/drawing/picture_locking.rb +12 -44
- data/lib/axlsx/drawing/scaling.rb +13 -13
- data/lib/axlsx/drawing/scatter_chart.rb +3 -3
- 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/view_3D.rb +51 -37
- data/lib/axlsx/drawing/vml_shape.rb +23 -23
- data/lib/axlsx/package.rb +14 -16
- 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 +19 -16
- 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 +22 -13
- data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- 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 +49 -0
- data/lib/axlsx/util/options_parser.rb +15 -0
- data/lib/axlsx/util/serialized_attributes.rb +46 -0
- data/lib/axlsx/util/simple_typed_list.rb +16 -4
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +13 -58
- data/lib/axlsx/workbook/workbook.rb +27 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -19
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +20 -27
- data/lib/axlsx/workbook/worksheet/cell.rb +38 -39
- data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
- data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
- data/lib/axlsx/workbook/worksheet/col.rb +34 -27
- data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
- data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
- data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
- data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
- data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
- 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 +6 -9
- data/lib/axlsx/workbook/worksheet/page_setup.rb +20 -19
- data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
- 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/selection.rb +30 -38
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -26
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +19 -57
- 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 +16 -18
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +10 -27
- data/lib/axlsx/workbook/worksheet/worksheet.rb +6 -7
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +11 -33
- data/test/content_type/tc_default.rb +0 -11
- data/test/content_type/tc_override.rb +0 -13
- data/test/drawing/tc_d_lbls.rb +14 -4
- data/test/tc_axlsx.rb +20 -2
- data/test/workbook/tc_defined_name.rb +2 -2
- data/test/workbook/tc_workbook.rb +15 -0
- data/test/workbook/worksheet/tc_col.rb +11 -1
- data/test/workbook/worksheet/tc_pane.rb +5 -45
- data/test/workbook/worksheet/tc_selection.rb +9 -48
- metadata +13 -3
|
@@ -5,18 +5,7 @@ module Axlsx
|
|
|
5
5
|
# @see README for examples
|
|
6
6
|
class Table
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
# The reference to the table data
|
|
10
|
-
# @return [String]
|
|
11
|
-
attr_reader :ref
|
|
12
|
-
|
|
13
|
-
# The name of the table.
|
|
14
|
-
# @return [String]
|
|
15
|
-
attr_reader :name
|
|
16
|
-
|
|
17
|
-
# The style for the table.
|
|
18
|
-
# @return [TableStyle]
|
|
19
|
-
attr_reader :style
|
|
8
|
+
include Axlsx::OptionsParser
|
|
20
9
|
|
|
21
10
|
# Creates a new Table object
|
|
22
11
|
# @param [String] ref The reference to the table data like 'A1:G24'.
|
|
@@ -30,12 +19,22 @@ module Axlsx
|
|
|
30
19
|
@sheet.workbook.tables << self
|
|
31
20
|
@table_style_info = TableStyleInfo.new(options[:style_info]) if options[:style_info]
|
|
32
21
|
@name = "Table#{index+1}"
|
|
33
|
-
options
|
|
34
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
35
|
-
end
|
|
22
|
+
parse_options options
|
|
36
23
|
yield self if block_given?
|
|
37
24
|
end
|
|
38
25
|
|
|
26
|
+
# The reference to the table data
|
|
27
|
+
# @return [String]
|
|
28
|
+
attr_reader :ref
|
|
29
|
+
|
|
30
|
+
# The name of the table.
|
|
31
|
+
# @return [String]
|
|
32
|
+
attr_reader :name
|
|
33
|
+
|
|
34
|
+
# The style for the table.
|
|
35
|
+
# @return [TableStyle]
|
|
36
|
+
attr_reader :style
|
|
37
|
+
|
|
39
38
|
# The index of this chart in the workbooks charts collection
|
|
40
39
|
# @return [Integer]
|
|
41
40
|
def index
|
|
@@ -63,7 +62,7 @@ module Axlsx
|
|
|
63
62
|
@name = v
|
|
64
63
|
end
|
|
65
64
|
end
|
|
66
|
-
|
|
65
|
+
|
|
67
66
|
# TableStyleInfo for the table.
|
|
68
67
|
# initialization can be fed via the :style_info option
|
|
69
68
|
def table_style_info
|
|
@@ -83,8 +82,7 @@ module Axlsx
|
|
|
83
82
|
str << '<tableColumn id ="' << (index+1).to_s << '" name="' << cell.value << '"/>'
|
|
84
83
|
end
|
|
85
84
|
str << '</tableColumns>'
|
|
86
|
-
|
|
87
|
-
table_style_info.to_xml_string(str) # '<tableStyleInfo showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0" name="TableStyleMedium9" />'
|
|
85
|
+
table_style_info.to_xml_string(str)
|
|
88
86
|
str << '</table>'
|
|
89
87
|
end
|
|
90
88
|
|
|
@@ -3,10 +3,9 @@ module Axlsx
|
|
|
3
3
|
# The table style info class manages style attributes for defined tables in
|
|
4
4
|
# a worksheet
|
|
5
5
|
class TableStyleInfo
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
include Axlsx::SerializedAttributes
|
|
8
|
+
include Axlsx::Accessors
|
|
10
9
|
# creates a new TableStyleInfo instance
|
|
11
10
|
# @param [Hash] options
|
|
12
11
|
# @option [Boolean] show_first_column indicates if the first column should
|
|
@@ -22,32 +21,18 @@ module Axlsx
|
|
|
22
21
|
def initialize(options = {})
|
|
23
22
|
initialize_defaults
|
|
24
23
|
@name = 'TableStyleMedium9'
|
|
25
|
-
options
|
|
26
|
-
send("#{k}=", v) if respond_to? "#{k}="
|
|
27
|
-
end
|
|
24
|
+
parse_options options
|
|
28
25
|
end
|
|
29
26
|
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# @return [Boolean]
|
|
35
|
-
attr_reader :#{attr}
|
|
36
|
-
|
|
37
|
-
# The #{attr} writer
|
|
38
|
-
# @param [Boolean] value The value to assign to #{attr}
|
|
39
|
-
# @return [Boolean]
|
|
40
|
-
def #{attr}=(value)
|
|
41
|
-
Axlsx::validate_boolean(value)
|
|
42
|
-
@#{attr} = value
|
|
43
|
-
end
|
|
44
|
-
}
|
|
45
|
-
end
|
|
27
|
+
# boolean attributes for this object
|
|
28
|
+
boolean_attr_accessor :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes
|
|
29
|
+
serializable_attributes :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes,
|
|
30
|
+
:name
|
|
46
31
|
|
|
47
32
|
# Initialize all the values to false as Excel requires them to
|
|
48
33
|
# explicitly be disabled or all will show.
|
|
49
34
|
def initialize_defaults
|
|
50
|
-
|
|
35
|
+
%w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
|
|
51
36
|
self.send("#{attr}=", 0)
|
|
52
37
|
end
|
|
53
38
|
end
|
|
@@ -59,9 +44,7 @@ module Axlsx
|
|
|
59
44
|
# @param [String] str the string to contact this objects serialization to.
|
|
60
45
|
def to_xml_string(str = '')
|
|
61
46
|
str << '<tableStyleInfo '
|
|
62
|
-
|
|
63
|
-
str << Axlsx::camel(key, false) << "='#{value}' "
|
|
64
|
-
end
|
|
47
|
+
serialized_attributes str
|
|
65
48
|
str << '/>'
|
|
66
49
|
end
|
|
67
50
|
end
|
|
@@ -3,6 +3,7 @@ module Axlsx
|
|
|
3
3
|
|
|
4
4
|
# The Worksheet class represents a worksheet in the workbook.
|
|
5
5
|
class Worksheet
|
|
6
|
+
include Axlsx::OptionsParser
|
|
6
7
|
|
|
7
8
|
# definition of characters which are less than the maximum width of 0-9 in the default font for use in String#count.
|
|
8
9
|
# This is used for autowidth calculations
|
|
@@ -24,9 +25,7 @@ module Axlsx
|
|
|
24
25
|
@sheet_protection = nil
|
|
25
26
|
|
|
26
27
|
initialize_page_options(options)
|
|
27
|
-
options
|
|
28
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
29
|
-
end
|
|
28
|
+
parse_options options
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
# Initalizes page margin, setup and print options
|
|
@@ -238,7 +237,7 @@ module Axlsx
|
|
|
238
237
|
# Indicates if gridlines should be shown in the sheet.
|
|
239
238
|
# This is true by default.
|
|
240
239
|
# @return [Boolean]
|
|
241
|
-
# @deprecated Use
|
|
240
|
+
# @deprecated Use SheetView#show_grid_lines= instead.
|
|
242
241
|
def show_gridlines=(v)
|
|
243
242
|
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
|
|
244
243
|
Axlsx::validate_boolean v
|
|
@@ -247,7 +246,7 @@ module Axlsx
|
|
|
247
246
|
|
|
248
247
|
# @see selected
|
|
249
248
|
# @return [Boolean]
|
|
250
|
-
# @deprecated Use
|
|
249
|
+
# @deprecated Use SheetView#tab_selected= instead.
|
|
251
250
|
def selected=(v)
|
|
252
251
|
warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
|
|
253
252
|
Axlsx::validate_boolean v
|
|
@@ -256,7 +255,7 @@ module Axlsx
|
|
|
256
255
|
|
|
257
256
|
# Indicates if the worksheet should show gridlines or not
|
|
258
257
|
# @return Boolean
|
|
259
|
-
# @deprecated Use
|
|
258
|
+
# @deprecated Use SheetView#show_grid_lines instead.
|
|
260
259
|
def show_gridlines
|
|
261
260
|
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
|
|
262
261
|
sheet_view.show_grid_lines
|
|
@@ -266,7 +265,7 @@ module Axlsx
|
|
|
266
265
|
# It is possible to have more than one worksheet selected, however it might cause issues
|
|
267
266
|
# in some older versions of excel when using copy and paste.
|
|
268
267
|
# @return Boolean
|
|
269
|
-
# @deprecated Use
|
|
268
|
+
# @deprecated Use SheetView#tab_selected instead.
|
|
270
269
|
def selected
|
|
271
270
|
warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
|
|
272
271
|
sheet_view.tab_selected
|
|
@@ -3,6 +3,9 @@ module Axlsx
|
|
|
3
3
|
# A worksheet hyperlink object. Note that this is not the same as a drawing hyperlink object.
|
|
4
4
|
class WorksheetHyperlink
|
|
5
5
|
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
include Axlsx::Accessors
|
|
8
|
+
include Axlsx::SerializedAttributes
|
|
6
9
|
# Creates a new hyperlink object.
|
|
7
10
|
# @note the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method
|
|
8
11
|
# @param [Worksheet] worksheet the Worksheet that owns this hyperlink
|
|
@@ -16,14 +19,13 @@ module Axlsx
|
|
|
16
19
|
DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet
|
|
17
20
|
@worksheet = worksheet
|
|
18
21
|
@target = :external
|
|
19
|
-
options
|
|
20
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
21
|
-
end
|
|
22
|
+
parse_options options
|
|
22
23
|
yield self if block_given?
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
string_attr_accessor :display, :location, :tooltip
|
|
27
|
+
|
|
28
|
+
serializable_attributes :display, :tooltip, :ref
|
|
27
29
|
|
|
28
30
|
#Cell location of hyperlink on worksheet.
|
|
29
31
|
# @return [String]
|
|
@@ -39,29 +41,11 @@ module Axlsx
|
|
|
39
41
|
# @param [String|Cell] cell_reference The string reference or cell that defines where this hyperlink shows in the worksheet.
|
|
40
42
|
def ref=(cell_reference)
|
|
41
43
|
cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
|
|
42
|
-
|
|
43
44
|
Axlsx::validate_string cell_reference
|
|
44
45
|
@ref = cell_reference
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
STRING_ATTRIBUTES.each do |attr|
|
|
49
|
-
class_eval %{
|
|
50
|
-
# The #{attr} attribute reader
|
|
51
|
-
# @return [String]
|
|
52
|
-
attr_reader :#{attr}
|
|
53
|
-
|
|
54
|
-
# The #{attr} writer
|
|
55
|
-
# @param [String] value The value to assign to #{attr}
|
|
56
|
-
# @return [String]
|
|
57
|
-
def #{attr}=(value)
|
|
58
|
-
Axlsx::validate_string(value)
|
|
59
|
-
@#{attr}= value
|
|
60
|
-
end
|
|
61
|
-
}
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# The relationship required by this hyperlink when the taget is :external
|
|
48
|
+
# The relationship required by this hyperlink when the taget is :external
|
|
65
49
|
# @return [Relationship]
|
|
66
50
|
def relationship
|
|
67
51
|
return unless @target == :external
|
|
@@ -80,7 +64,7 @@ module Axlsx
|
|
|
80
64
|
# @return [String]
|
|
81
65
|
def to_xml_string(str='')
|
|
82
66
|
str << '<hyperlink '
|
|
83
|
-
|
|
67
|
+
serialized_attributes str, location_or_id
|
|
84
68
|
str << '/>'
|
|
85
69
|
end
|
|
86
70
|
|
|
@@ -88,14 +72,8 @@ module Axlsx
|
|
|
88
72
|
# location should only be specified for non-external targets.
|
|
89
73
|
# r:id should only be specified for external targets.
|
|
90
74
|
# @return [Hash]
|
|
91
|
-
def
|
|
92
|
-
|
|
93
|
-
if @target == :external
|
|
94
|
-
h['r:id'] = id
|
|
95
|
-
else
|
|
96
|
-
h['location'] = location
|
|
97
|
-
end
|
|
98
|
-
h
|
|
75
|
+
def location_or_id
|
|
76
|
+
@target == :external ? { :"r:id" => id } : { :location => location }
|
|
99
77
|
end
|
|
100
78
|
end
|
|
101
79
|
end
|
|
@@ -3,14 +3,6 @@ require 'tc_helper.rb'
|
|
|
3
3
|
|
|
4
4
|
class TestDefault < Test::Unit::TestCase
|
|
5
5
|
|
|
6
|
-
def test_initialization_requires_Extension_and_ContentType
|
|
7
|
-
assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new }
|
|
8
|
-
assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :Extension=>"xml" }
|
|
9
|
-
assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :ContentType=>"asdf" }
|
|
10
|
-
|
|
11
|
-
assert_nothing_raised {Axlsx::Default.new :Extension=>"foo", :ContentType=>Axlsx::XML_CT}
|
|
12
|
-
|
|
13
|
-
end
|
|
14
6
|
def test_content_type_restriction
|
|
15
7
|
assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" }
|
|
16
8
|
end
|
|
@@ -20,8 +12,5 @@ class TestDefault < Test::Unit::TestCase
|
|
|
20
12
|
doc = Nokogiri::XML(type.to_xml_string)
|
|
21
13
|
assert_equal(doc.xpath("Default[@ContentType='#{Axlsx::XML_CT}']").size, 1)
|
|
22
14
|
assert_equal(doc.xpath("Default[@Extension='xml']").size, 1)
|
|
23
|
-
|
|
24
15
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
16
|
end
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
1
|
require 'tc_helper.rb'
|
|
3
|
-
|
|
4
2
|
class TestOverride < Test::Unit::TestCase
|
|
5
3
|
|
|
6
|
-
def test_initialization_requires_Extension_and_ContentType
|
|
7
|
-
err = "requires PartName and ContentType options"
|
|
8
|
-
assert_raise(ArgumentError, err) { Axlsx::Override.new }
|
|
9
|
-
assert_raise(ArgumentError, err) { Axlsx::Override.new :PartName=>"xml" }
|
|
10
|
-
assert_raise(ArgumentError, err) { Axlsx::Override.new :ContentType=>"asdf" }
|
|
11
|
-
assert_nothing_raised {Axlsx::Override.new :PartName=>"foo", :ContentType=>Axlsx::CHART_CT}
|
|
12
|
-
end
|
|
13
|
-
|
|
14
4
|
def test_content_type_restriction
|
|
15
5
|
assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType=>"asdf" }
|
|
16
6
|
end
|
|
@@ -20,8 +10,5 @@ class TestOverride < Test::Unit::TestCase
|
|
|
20
10
|
doc = Nokogiri::XML(type.to_xml_string)
|
|
21
11
|
assert_equal(doc.xpath("Override[@ContentType='#{Axlsx::CHART_CT}']").size, 1)
|
|
22
12
|
assert_equal(doc.xpath("Override[@PartName='somechart.xml']").size, 1)
|
|
23
|
-
|
|
24
13
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
14
|
end
|
data/test/drawing/tc_d_lbls.rb
CHANGED
|
@@ -4,19 +4,29 @@ class TestDLbls < Test::Unit::TestCase
|
|
|
4
4
|
|
|
5
5
|
def setup
|
|
6
6
|
@d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart)
|
|
7
|
+
@boolean_attributes =[:show_legend_key,
|
|
8
|
+
:show_val,
|
|
9
|
+
:show_cat_name,
|
|
10
|
+
:show_ser_name,
|
|
11
|
+
:show_percent,
|
|
12
|
+
:show_bubble_size,
|
|
13
|
+
:show_leader_lines]
|
|
7
14
|
end
|
|
8
15
|
|
|
9
16
|
def test_initialization
|
|
10
17
|
assert_equal(:bestFit, @d_lbls.d_lbl_pos)
|
|
11
|
-
|
|
18
|
+
@boolean_attributes.each do |attr|
|
|
12
19
|
assert_equal(false, @d_lbls.send(attr))
|
|
13
20
|
end
|
|
14
21
|
end
|
|
15
22
|
|
|
16
23
|
def test_initialization_with_optoins
|
|
17
|
-
|
|
24
|
+
|
|
25
|
+
options_hash = Hash[*[@boolean_attributes.map { |name| [name, true] }] ]
|
|
26
|
+
|
|
18
27
|
d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart, options_hash.merge( { :d_lbl_pos => :t }))
|
|
19
|
-
|
|
28
|
+
|
|
29
|
+
@boolean_attributes.each do |attr|
|
|
20
30
|
assert_equal(true, d_lbls.send(attr), "boolean attributes set by options")
|
|
21
31
|
end
|
|
22
32
|
assert_equal(:t, d_lbls.d_lbl_pos, "d_lbl_pos set by options")
|
|
@@ -27,7 +37,7 @@ class TestDLbls < Test::Unit::TestCase
|
|
|
27
37
|
end
|
|
28
38
|
|
|
29
39
|
def test_boolean_attributes
|
|
30
|
-
|
|
40
|
+
@boolean_attributes.each do |attr|
|
|
31
41
|
assert_raise(ArgumentError, "rejects non boolean value for #{attr}") { @d_lbls.send("#{attr}=", :foo) }
|
|
32
42
|
assert_nothing_raised("accepts boolean value for #{attr}") { @d_lbls.send("#{attr}=", true) }
|
|
33
43
|
assert_nothing_raised("accepts boolean value for #{attr}") { @d_lbls.send("#{attr}=", false) }
|
data/test/tc_axlsx.rb
CHANGED
|
@@ -14,8 +14,26 @@ class TestAxlsx < Test::Unit::TestCase
|
|
|
14
14
|
}
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
18
|
-
|
|
17
|
+
def test_cell_range_empty_if_no_cell
|
|
18
|
+
assert_equal(Axlsx.cell_range([]), "")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_cell_range_relative
|
|
22
|
+
p = Axlsx::Package.new
|
|
23
|
+
ws = p.workbook.add_worksheet
|
|
24
|
+
row = ws.add_row
|
|
25
|
+
c1 = row.add_cell
|
|
26
|
+
c2 = row.add_cell
|
|
27
|
+
assert_equal(Axlsx.cell_range([c2, c1], false), "A1:B1")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_cell_range_absolute
|
|
31
|
+
p = Axlsx::Package.new
|
|
32
|
+
ws = p.workbook.add_worksheet :name => "Sheet <'>\" 1"
|
|
33
|
+
row = ws.add_row
|
|
34
|
+
c1 = row.add_cell
|
|
35
|
+
c2 = row.add_cell
|
|
36
|
+
assert_equal(Axlsx.cell_range([c2, c1], true), "'Sheet <''>" 1'!$A$1:$B$1")
|
|
19
37
|
end
|
|
20
38
|
|
|
21
39
|
def test_name_to_indices
|
|
@@ -10,14 +10,14 @@ class TestDefinedNames < Test::Unit::TestCase
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_string_attributes
|
|
13
|
-
|
|
13
|
+
%w(short_cut_key status_bar help description custom_menu comment).each do |attr|
|
|
14
14
|
assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) }
|
|
15
15
|
assert_nothing_raised { @dn.send("#{attr}=", '_xlnm.Sheet_Title') }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def test_boolean_attributes
|
|
20
|
-
|
|
20
|
+
%w(workbook_parameter publish_to_server xlm vb_proceedure function hidden).each do |attr|
|
|
21
21
|
assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @dn.send("#{attr}=", 'foo') }
|
|
22
22
|
assert_nothing_raised { @dn.send("#{attr}=", 1) }
|
|
23
23
|
end
|
|
@@ -16,6 +16,13 @@ class TestWorkbook < Test::Unit::TestCase
|
|
|
16
16
|
assert_equal(@wb.use_autowidth, false)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
|
|
20
|
+
def test_sheet_by_name_retrieval
|
|
21
|
+
@wb.add_worksheet(:name=>'foo')
|
|
22
|
+
@wb.add_worksheet(:name=>'bar')
|
|
23
|
+
assert_equal('foo', @wb.sheet_by_name('foo').name)
|
|
24
|
+
|
|
25
|
+
end
|
|
19
26
|
def test_date1904
|
|
20
27
|
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
|
21
28
|
@wb.date1904 = :false
|
|
@@ -42,6 +49,14 @@ class TestWorkbook < Test::Unit::TestCase
|
|
|
42
49
|
assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
|
|
43
50
|
assert_equal(ws.name, "bob", "name option gets passed to worksheet")
|
|
44
51
|
end
|
|
52
|
+
|
|
53
|
+
def test_insert_worksheet
|
|
54
|
+
@wb.add_worksheet(:name => 'A')
|
|
55
|
+
@wb.add_worksheet(:name => 'B')
|
|
56
|
+
ws3 = @wb.insert_worksheet(0, :name => 'C')
|
|
57
|
+
assert_equal(ws3.name, @wb.worksheets.first.name)
|
|
58
|
+
end
|
|
59
|
+
|
|
45
60
|
def test_relationships
|
|
46
61
|
#current relationship size is 1 due to style relation
|
|
47
62
|
assert(@wb.relationships.size == 1)
|
|
@@ -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
|