axlsx 1.2.0 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +3 -2
- data/CHANGELOG.md +34 -1
- data/README.md +47 -33
- data/Rakefile +1 -1
- data/examples/auto_filter.rb +16 -0
- data/examples/basic_charts.rb +4 -0
- data/examples/colored_links.rb +59 -0
- data/examples/doc/_index.html +88 -0
- data/examples/doc/class_list.html +53 -0
- data/examples/doc/css/common.css +1 -0
- data/examples/doc/css/full_list.css +57 -0
- data/examples/doc/css/style.css +328 -0
- data/examples/doc/file_list.html +52 -0
- data/examples/doc/frames.html +28 -0
- data/examples/doc/index.html +88 -0
- data/examples/doc/js/app.js +214 -0
- data/examples/doc/js/full_list.js +173 -0
- data/examples/doc/js/jquery.js +4 -0
- data/examples/doc/method_list.html +52 -0
- data/examples/doc/top-level-namespace.html +102 -0
- data/examples/example.rb +447 -257
- data/examples/finance.rb +82 -0
- data/examples/hyperlinks.rb +23 -0
- data/examples/page_setup.rb +11 -0
- data/examples/skydrive/axlsx.csv +1 -0
- data/examples/skydrive/axlsx.xlsx +0 -0
- data/examples/skydrive/real_example.rb +8 -8
- data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
- data/examples/sprk2012/basics.rb +11 -0
- data/examples/sprk2012/basics.xlsx +0 -0
- data/examples/sprk2012/gravatar.jpeg +0 -0
- data/examples/sprk2012/hair_club.jpg +0 -0
- data/examples/sprk2012/images.rb +9 -0
- data/examples/{example.xlsx → sprk2012/images.xlsx} +0 -0
- data/examples/sprk2012/line_chart.rb +56 -0
- data/examples/sprk2012/line_chart.xlsx +0 -0
- data/examples/sprk2012/sprk2012.key +0 -0
- data/examples/sprk2012/styles.rb +20 -0
- data/examples/sprk2012/styles.xlsx +0 -0
- data/examples/styles.rb +62 -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/drawing/axis.rb +4 -4
- 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 +52 -38
- data/lib/axlsx/drawing/vml_shape.rb +23 -23
- data/lib/axlsx/package.rb +14 -17
- 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 +11 -2
- 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/constants.rb +105 -4
- 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 -2
- data/lib/axlsx/util/validators.rb +33 -8
- data/lib/axlsx/version.rb +2 -2
- data/lib/axlsx/workbook/defined_name.rb +13 -58
- data/lib/axlsx/workbook/workbook.rb +33 -2
- 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/cell.rb +82 -45
- 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/date_time_converter.rb +1 -1
- 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 +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/print_options.rb +8 -30
- data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +48 -81
- 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_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 +22 -17
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +51 -14
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +79 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/axlsx.rb +19 -5
- 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/stylesheet/tc_styles.rb +13 -0
- data/test/tc_axlsx.rb +20 -2
- data/test/tc_package.rb +1 -0
- data/test/util/tc_validators.rb +22 -1
- data/test/workbook/tc_defined_name.rb +2 -2
- data/test/workbook/tc_workbook.rb +15 -0
- 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_cell.rb +35 -5
- data/test/workbook/worksheet/tc_col.rb +11 -1
- 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_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_pr.rb +27 -0
- data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +17 -3
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
- metadata +74 -10
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
|
@@ -5,59 +5,14 @@ module Axlsx
|
|
|
5
5
|
# @see Worksheet#add_row
|
|
6
6
|
class Row
|
|
7
7
|
|
|
8
|
+
include SerializedAttributes
|
|
9
|
+
include Accessors
|
|
8
10
|
# No support is provided for the following attributes
|
|
9
11
|
# spans
|
|
10
12
|
# thickTop
|
|
11
13
|
# thickBottom
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
# A list of serilizable attributes.
|
|
15
|
-
# @note height(ht) and customHeight are manages separately for now. Have a look at Row#height
|
|
16
|
-
SERIALIZABLE_ATTRIBUTES = [:hidden, :outlineLevel, :collapsed, :s, :customFormat, :ph]
|
|
17
|
-
|
|
18
|
-
# The worksheet this row belongs to
|
|
19
|
-
# @return [Worksheet]
|
|
20
|
-
attr_reader :worksheet
|
|
21
|
-
|
|
22
|
-
# The cells this row holds
|
|
23
|
-
# @return [SimpleTypedList]
|
|
24
|
-
attr_reader :cells
|
|
25
|
-
|
|
26
|
-
# Row height measured in point size. There is no margin padding on row height.
|
|
27
|
-
# @return [Float]
|
|
28
|
-
attr_reader :height
|
|
29
|
-
|
|
30
|
-
# Flag indicating if the outlining of row.
|
|
31
|
-
# @return [Boolean]
|
|
32
|
-
attr_reader :collapsed
|
|
33
|
-
|
|
34
|
-
# Flag indicating if the the row is hidden.
|
|
35
|
-
# @return [Boolean]
|
|
36
|
-
attr_reader :hidden
|
|
37
|
-
|
|
38
|
-
# Outlining level of the row, when outlining is on
|
|
39
|
-
# @return [Integer]
|
|
40
|
-
attr_reader :outlineLevel
|
|
41
|
-
|
|
42
|
-
# The style applied ot the row. This affects the entire row.
|
|
43
|
-
# @return [Integer]
|
|
44
|
-
attr_reader :s
|
|
45
|
-
|
|
46
|
-
# indicates that a style has been applied directly to the row via Row#s
|
|
47
|
-
# @return [Boolean]
|
|
48
|
-
attr_reader :customFormat
|
|
49
|
-
|
|
50
|
-
# indicates if the row should show phonetic
|
|
51
|
-
# @return [Boolean]
|
|
52
|
-
attr_reader :ph
|
|
53
|
-
|
|
54
|
-
# NOTE removing this from the api as it is actually incorrect.
|
|
55
|
-
# having a method to style a row's cells is fine, but it is not an attribute on the row.
|
|
56
|
-
# The proper attribute is ':s'
|
|
57
|
-
# attr_reader style
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
# Creates a new row. New Cell objects are created based on the values, types and style options.
|
|
15
|
+
# Creates a new row. New Cell objects are created based on the values, types and style options.
|
|
61
16
|
# A new cell is created for each item in the values array. style and types options are applied as follows:
|
|
62
17
|
# If the types option is defined and is a symbol it is applied to all the cells created.
|
|
63
18
|
# If the types option is an array, cell types are applied by index for each cell
|
|
@@ -73,7 +28,7 @@ module Axlsx
|
|
|
73
28
|
# @see Row#array_to_cells
|
|
74
29
|
# @see Cell
|
|
75
30
|
def initialize(worksheet, values=[], options={})
|
|
76
|
-
@
|
|
31
|
+
@ht = nil
|
|
77
32
|
self.worksheet = worksheet
|
|
78
33
|
@cells = SimpleTypedList.new Cell
|
|
79
34
|
@worksheet.rows << self
|
|
@@ -81,29 +36,48 @@ module Axlsx
|
|
|
81
36
|
array_to_cells(values, options)
|
|
82
37
|
end
|
|
83
38
|
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
39
|
+
# A list of serializable attributes.
|
|
40
|
+
serializable_attributes :hidden, :outline_level, :collapsed, :custom_format, :s, :ph, :custom_height, :ht
|
|
41
|
+
|
|
42
|
+
# Boolean row attribute accessors
|
|
43
|
+
boolean_attr_accessor :hidden, :collapsed, :custom_format, :ph, :custom_height
|
|
89
44
|
|
|
90
|
-
#
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
45
|
+
# The worksheet this row belongs to
|
|
46
|
+
# @return [Worksheet]
|
|
47
|
+
attr_reader :worksheet
|
|
48
|
+
|
|
49
|
+
# The cells this row holds
|
|
50
|
+
# @return [SimpleTypedList]
|
|
51
|
+
attr_reader :cells
|
|
52
|
+
|
|
53
|
+
# Row height measured in point size. There is no margin padding on row height.
|
|
54
|
+
# @return [Float]
|
|
55
|
+
def height
|
|
56
|
+
@ht
|
|
94
57
|
end
|
|
95
|
-
|
|
96
|
-
#
|
|
97
|
-
|
|
58
|
+
|
|
59
|
+
# Outlining level of the row, when outlining is on
|
|
60
|
+
# @return [Integer]
|
|
61
|
+
attr_reader :outline_level
|
|
62
|
+
alias :outlineLevel :outline_level
|
|
63
|
+
|
|
64
|
+
# The style applied ot the row. This affects the entire row.
|
|
65
|
+
# @return [Integer]
|
|
66
|
+
attr_reader :s
|
|
98
67
|
|
|
99
68
|
# @see Row#s
|
|
100
|
-
def s=(v)
|
|
69
|
+
def s=(v)
|
|
70
|
+
Axlsx.validate_unsigned_numeric(v)
|
|
71
|
+
@custom_format = true
|
|
72
|
+
@s = v
|
|
73
|
+
end
|
|
101
74
|
|
|
102
75
|
# @see Row#outline
|
|
103
|
-
def
|
|
76
|
+
def outline_level=(v)
|
|
104
77
|
Axlsx.validate_unsigned_numeric(v)
|
|
105
|
-
@
|
|
78
|
+
@outline_level = v
|
|
106
79
|
end
|
|
80
|
+
alias :outlineLevel= :outline_level=
|
|
107
81
|
|
|
108
82
|
# The index of this row in the worksheet
|
|
109
83
|
# @return [Integer]
|
|
@@ -116,18 +90,11 @@ module Axlsx
|
|
|
116
90
|
# @param [String] str The string this rows xml will be appended to.
|
|
117
91
|
# @return [String]
|
|
118
92
|
def to_xml_string(r_index, str = '')
|
|
119
|
-
str << '<row
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
end
|
|
123
|
-
if custom_height?
|
|
124
|
-
str << 'customHeight="1" ht="' << height.to_s << '">'
|
|
125
|
-
else
|
|
126
|
-
str << '>'
|
|
127
|
-
end
|
|
93
|
+
str << '<row '
|
|
94
|
+
serialized_attributes(str, { :r => r_index + 1 })
|
|
95
|
+
str << '>'
|
|
128
96
|
@cells.each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) }
|
|
129
97
|
str << '</row>'
|
|
130
|
-
str
|
|
131
98
|
end
|
|
132
99
|
|
|
133
100
|
# Adds a singel sell to the row based on the data provided and updates the worksheet's autofit data.
|
|
@@ -154,13 +121,13 @@ module Axlsx
|
|
|
154
121
|
end
|
|
155
122
|
|
|
156
123
|
# @see height
|
|
157
|
-
def height=(v)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
@
|
|
124
|
+
def height=(v)
|
|
125
|
+
Axlsx::validate_unsigned_numeric(v)
|
|
126
|
+
unless v.nil?
|
|
127
|
+
@ht = v
|
|
128
|
+
@custom_height = true
|
|
129
|
+
end
|
|
130
|
+
@ht
|
|
164
131
|
end
|
|
165
132
|
|
|
166
133
|
private
|
|
@@ -5,15 +5,28 @@ module Axlsx
|
|
|
5
5
|
# @note The recommended way to manage the selection pane options is via SheetView#add_selection
|
|
6
6
|
# @see SheetView#add_selection
|
|
7
7
|
class Selection
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
include Axlsx::OptionsParser
|
|
10
|
+
include Axlsx::SerializedAttributes
|
|
11
|
+
|
|
12
|
+
# Creates a new {Selection} object
|
|
13
|
+
# @option options [Cell, String] active_cell Active Cell Location
|
|
14
|
+
# @option options [Integer] active_cell_id Active Cell Index
|
|
15
|
+
# @option options [Symbol] pane Pane
|
|
16
|
+
# @option options [String] sqref Sequence of References
|
|
17
|
+
def initialize(options={})
|
|
18
|
+
@active_cell = @active_cell_id = @pane = @sqref = nil
|
|
19
|
+
parse_options options
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
serializable_attributes :active_cell, :active_cell_id, :pane, :sqref
|
|
9
23
|
# Active Cell Location
|
|
10
24
|
# Location of the active cell.
|
|
11
25
|
# @see type
|
|
12
26
|
# @return [String]
|
|
13
27
|
# default nil
|
|
14
28
|
attr_reader :active_cell
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
|
|
17
30
|
# Active Cell Index
|
|
18
31
|
# 0-based index of the range reference (in the array of references listed in sqref)
|
|
19
32
|
# containing the active cell. Only used when the selection in sqref is not contiguous.
|
|
@@ -24,8 +37,7 @@ module Axlsx
|
|
|
24
37
|
# @return [Integer]
|
|
25
38
|
# default nil
|
|
26
39
|
attr_reader :active_cell_id
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
|
|
29
41
|
# Pane
|
|
30
42
|
# The pane to which this selection belongs.
|
|
31
43
|
# Options are
|
|
@@ -52,59 +64,39 @@ module Axlsx
|
|
|
52
64
|
# @return [Symbol]
|
|
53
65
|
# default nil
|
|
54
66
|
attr_reader :pane
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
|
|
57
68
|
# Sequence of References
|
|
58
69
|
# Range of the selection. Can be non-contiguous set of ranges.
|
|
59
70
|
# @see type
|
|
60
71
|
# @return [String]
|
|
61
72
|
# default nil
|
|
62
73
|
attr_reader :sqref
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# Creates a new {Selection} object
|
|
66
|
-
# @option options [Cell, String] active_cell Active Cell Location
|
|
67
|
-
# @option options [Integer] active_cell_id Active Cell Index
|
|
68
|
-
# @option options [Symbol] pane Pane
|
|
69
|
-
# @option options [String] sqref Sequence of References
|
|
70
|
-
def initialize(options={})
|
|
71
|
-
#defaults
|
|
72
|
-
@active_cell = @active_cell_id = @pane = @sqref = nil
|
|
73
|
-
|
|
74
|
-
# write options to instance variables
|
|
75
|
-
options.each do |o|
|
|
76
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
|
|
81
75
|
# @see active_cell
|
|
82
76
|
def active_cell=(v)
|
|
83
77
|
cell = (v.class == Axlsx::Cell ? v.r_abs : v)
|
|
84
|
-
Axlsx::validate_string(cell)
|
|
85
|
-
@active_cell = cell
|
|
78
|
+
Axlsx::validate_string(cell)
|
|
79
|
+
@active_cell = cell
|
|
86
80
|
end
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
|
|
89
82
|
# @see active_cell_id
|
|
90
83
|
def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
|
|
93
85
|
# @see pane
|
|
94
|
-
def pane=(v)
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
def pane=(v)
|
|
87
|
+
Axlsx::validate_pane_type(v)
|
|
88
|
+
@pane = Axlsx::camel(v, false)
|
|
89
|
+
end
|
|
90
|
+
|
|
97
91
|
# @see sqref
|
|
98
92
|
def sqref=(v); Axlsx::validate_string(v); @sqref = v end
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
|
|
101
94
|
# Serializes the data validation
|
|
102
95
|
# @param [String] str
|
|
103
96
|
# @return [String]
|
|
104
97
|
def to_xml_string(str = '')
|
|
105
98
|
str << '<selection '
|
|
106
|
-
str
|
|
107
|
-
%{="#{[:pane].include?(key.to_sym) ? value.to_s.gsub(/_(.)/){ $1.upcase } : value}"} unless value.nil? }.join(' ')
|
|
99
|
+
serialized_attributes str
|
|
108
100
|
str << '/>'
|
|
109
101
|
end
|
|
110
102
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
|
|
3
|
+
# the SheetCalcPr object for the worksheet
|
|
4
|
+
# This object contains calculation properties for the worksheet.
|
|
5
|
+
class SheetCalcPr
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
include Axlsx::SerializedAttributes
|
|
8
|
+
include Axlsx::Accessors
|
|
9
|
+
# creates a new SheetCalcPr
|
|
10
|
+
# @param [Hash] options Options for this object
|
|
11
|
+
# @option [Boolean] full_calc_on_load @see full_calc_on_load
|
|
12
|
+
def initialize(options={})
|
|
13
|
+
@full_calc_on_load = true
|
|
14
|
+
parse_options options
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
boolean_attr_accessor :full_calc_on_load
|
|
18
|
+
|
|
19
|
+
serializable_attributes :full_calc_on_load
|
|
20
|
+
|
|
21
|
+
# Serialize the object
|
|
22
|
+
# @param [String] str the string to append this objects serialized
|
|
23
|
+
# content to.
|
|
24
|
+
# @return [String]
|
|
25
|
+
def to_xml_string(str='')
|
|
26
|
+
str << "<sheetCalcPr #{serialized_attributes}/>"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,24 +1,69 @@
|
|
|
1
1
|
module Axlsx
|
|
2
2
|
|
|
3
3
|
# The SheetPr class manages serialization fo a worksheet's sheetPr element.
|
|
4
|
-
# Only fit_to_page is implemented
|
|
5
4
|
class SheetPr
|
|
5
|
+
include Axlsx::OptionsParser
|
|
6
|
+
include Axlsx::Accessors
|
|
7
|
+
include Axlsx::SerializedAttributes
|
|
8
|
+
|
|
9
|
+
serializable_attributes :sync_horizontal,
|
|
10
|
+
:sync_vertical,
|
|
11
|
+
:transtion_evaluation,
|
|
12
|
+
:transition_entry,
|
|
13
|
+
:published,
|
|
14
|
+
:filter_mode,
|
|
15
|
+
:enable_format_conditions_calculation,
|
|
16
|
+
:code_name,
|
|
17
|
+
:sync_ref
|
|
18
|
+
|
|
19
|
+
# These attributes are all boolean so I'm doing a bit of a hand
|
|
20
|
+
# waving magic show to set up the attriubte accessors
|
|
21
|
+
boolean_attr_accessor :sync_horizontal,
|
|
22
|
+
:sync_vertical,
|
|
23
|
+
:transtion_evaluation,
|
|
24
|
+
:transition_entry,
|
|
25
|
+
:published,
|
|
26
|
+
:filter_mode,
|
|
27
|
+
:enable_format_conditions_calculation
|
|
28
|
+
|
|
29
|
+
string_attr_accessor :code_name, :sync_ref
|
|
6
30
|
|
|
7
31
|
# Creates a new SheetPr object
|
|
8
32
|
# @param [Worksheet] worksheet The worksheet that owns this SheetPr object
|
|
9
|
-
def initialize(worksheet)
|
|
33
|
+
def initialize(worksheet, options={})
|
|
10
34
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
11
35
|
@worksheet = worksheet
|
|
36
|
+
parse_options options
|
|
12
37
|
end
|
|
13
38
|
|
|
39
|
+
# The worksheet these properties apply to!
|
|
40
|
+
# @return [Worksheet]
|
|
14
41
|
attr_reader :worksheet
|
|
15
42
|
|
|
16
43
|
# Serialize the object
|
|
17
44
|
# @param [String] str serialized output will be appended to this object if provided.
|
|
18
45
|
# @return [String]
|
|
19
46
|
def to_xml_string(str = '')
|
|
20
|
-
|
|
21
|
-
str << "<sheetPr
|
|
47
|
+
update_properties
|
|
48
|
+
str << "<sheetPr #{serialized_attributes}>"
|
|
49
|
+
page_setup_pr.to_xml_string(str)
|
|
50
|
+
str << "</sheetPr>"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The PageSetUpPr for this sheet pr object
|
|
54
|
+
# @return [PageSetUpPr]
|
|
55
|
+
def page_setup_pr
|
|
56
|
+
@page_setup_pr ||= PageSetUpPr.new
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def update_properties
|
|
62
|
+
page_setup_pr.fit_to_page = worksheet.fit_to_page?
|
|
63
|
+
if worksheet.auto_filter.columns.size > 0
|
|
64
|
+
self.filter_mode = 1
|
|
65
|
+
self.enable_format_conditions_calculation = 1
|
|
66
|
+
end
|
|
22
67
|
end
|
|
23
68
|
end
|
|
24
69
|
end
|
|
@@ -4,110 +4,9 @@ module Axlsx
|
|
|
4
4
|
# The SheetProtection object manages worksheet protection options per sheet.
|
|
5
5
|
class SheetProtection
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# default true
|
|
11
|
-
attr_reader :auto_filter
|
|
12
|
-
|
|
13
|
-
# If 1 or true then deleting columns should not be allowed when the sheet is protected.
|
|
14
|
-
# If 0 or false then deleting columns should be allowed when the sheet is protected.
|
|
15
|
-
# @return [Boolean]
|
|
16
|
-
# default true
|
|
17
|
-
attr_reader :delete_columns
|
|
18
|
-
|
|
19
|
-
# If 1 or true then deleting rows should not be allowed when the sheet is protected.
|
|
20
|
-
# If 0 or false then deleting rows should be allowed when the sheet is protected.
|
|
21
|
-
# @return [Boolean]
|
|
22
|
-
# default true
|
|
23
|
-
attr_reader :delete_rows
|
|
24
|
-
|
|
25
|
-
# If 1 or true then formatting cells should not be allowed when the sheet is protected.
|
|
26
|
-
# If 0 or false then formatting cells should be allowed when the sheet is protected.
|
|
27
|
-
# @return [Boolean]
|
|
28
|
-
# default true
|
|
29
|
-
attr_reader :format_cells
|
|
30
|
-
|
|
31
|
-
# If 1 or true then formatting columns should not be allowed when the sheet is protected.
|
|
32
|
-
# If 0 or false then formatting columns should be allowed when the sheet is protected.
|
|
33
|
-
# @return [Boolean]
|
|
34
|
-
# default true
|
|
35
|
-
attr_reader :format_columns
|
|
36
|
-
|
|
37
|
-
# If 1 or true then formatting rows should not be allowed when the sheet is protected.
|
|
38
|
-
# If 0 or false then formatting rows should be allowed when the sheet is protected.
|
|
39
|
-
# @return [Boolean]
|
|
40
|
-
# default true
|
|
41
|
-
attr_reader :format_rows
|
|
42
|
-
|
|
43
|
-
# If 1 or true then inserting columns should not be allowed when the sheet is protected.
|
|
44
|
-
# If 0 or false then inserting columns should be allowed when the sheet is protected.
|
|
45
|
-
# @return [Boolean]
|
|
46
|
-
# default true
|
|
47
|
-
attr_reader :insert_columns
|
|
48
|
-
|
|
49
|
-
# If 1 or true then inserting hyperlinks should not be allowed when the sheet is protected.
|
|
50
|
-
# If 0 or false then inserting hyperlinks should be allowed when the sheet is protected.
|
|
51
|
-
# @return [Boolean]
|
|
52
|
-
# default true
|
|
53
|
-
attr_reader :insert_hyperlinks
|
|
54
|
-
|
|
55
|
-
# If 1 or true then inserting rows should not be allowed when the sheet is protected.
|
|
56
|
-
# If 0 or false then inserting rows should be allowed when the sheet is protected.
|
|
57
|
-
# @return [Boolean]
|
|
58
|
-
# default true
|
|
59
|
-
attr_reader :insert_rows
|
|
60
|
-
|
|
61
|
-
# If 1 or true then editing of objects should not be allowed when the sheet is protected.
|
|
62
|
-
# If 0 or false then objects are allowed to be edited when the sheet is protected.
|
|
63
|
-
# @return [Boolean]
|
|
64
|
-
# default false
|
|
65
|
-
attr_reader :objects
|
|
66
|
-
|
|
67
|
-
# If 1 or true then PivotTables should not be allowed to operate when the sheet is protected.
|
|
68
|
-
# If 0 or false then PivotTables should be allowed to operate when the sheet is protected.
|
|
69
|
-
# @return [Boolean]
|
|
70
|
-
# default true
|
|
71
|
-
attr_reader :pivot_tables
|
|
72
|
-
|
|
73
|
-
# Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm
|
|
74
|
-
# @return [String]
|
|
75
|
-
attr_reader :salt_value
|
|
76
|
-
|
|
77
|
-
# If 1 or true then Scenarios should not be edited when the sheet is protected.
|
|
78
|
-
# If 0 or false then Scenarios are allowed to be edited when the sheet is protected.
|
|
79
|
-
# @return [Boolean]
|
|
80
|
-
# default false
|
|
81
|
-
attr_reader :scenarios
|
|
82
|
-
|
|
83
|
-
# If 1 or true then selection of locked cells should not be allowed when the sheet is protected.
|
|
84
|
-
# If 0 or false then selection of locked cells should be allowed when the sheet is protected.
|
|
85
|
-
# @return [Boolean]
|
|
86
|
-
# default false
|
|
87
|
-
attr_reader :select_locked_cells
|
|
88
|
-
|
|
89
|
-
# If 1 or true then selection of unlocked cells should not be allowed when the sheet is protected.
|
|
90
|
-
# If 0 or false then selection of unlocked cells should be allowed when the sheet is protected.
|
|
91
|
-
# @return [Boolean]
|
|
92
|
-
# default false
|
|
93
|
-
attr_reader :select_unlocked_cells
|
|
94
|
-
|
|
95
|
-
# If 1 or true then the sheet is protected.
|
|
96
|
-
# If 0 or false then the sheet is not protected.
|
|
97
|
-
# @return [Boolean]
|
|
98
|
-
# default true
|
|
99
|
-
attr_reader :sheet
|
|
100
|
-
|
|
101
|
-
# If 1 or true then sorting should not be allowed when the sheet is protected.
|
|
102
|
-
# If 0 or false then sorting should be allowed when the sheet is protected.
|
|
103
|
-
# @return [Boolean]
|
|
104
|
-
# default true
|
|
105
|
-
attr_reader :sort
|
|
106
|
-
|
|
107
|
-
# Password hash
|
|
108
|
-
# @return [String]
|
|
109
|
-
# default nil
|
|
110
|
-
attr_reader :password
|
|
7
|
+
include Axlsx::OptionsParser
|
|
8
|
+
include Axlsx::SerializedAttributes
|
|
9
|
+
include Axlsx::Accessors
|
|
111
10
|
|
|
112
11
|
# Creates a new SheetProtection instance
|
|
113
12
|
# @option options [Boolean] sheet @see SheetProtection#sheet
|
|
@@ -127,64 +26,62 @@ module Axlsx
|
|
|
127
26
|
# @option options [Boolean] pivot_tables @see SheetProtection#pivot_tables
|
|
128
27
|
# @option options [Boolean] select_unlocked_cells @see SheetProtection#select_unlocked_cells
|
|
129
28
|
# @option options [String] password. The password required for unlocking. @see SheetProtection#password=
|
|
130
|
-
# @option options [Boolean] objects @see SheetProtection#objects
|
|
131
29
|
def initialize(options={})
|
|
132
30
|
@objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false
|
|
133
31
|
@sheet = @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true
|
|
134
32
|
@password = nil
|
|
33
|
+
parse_options options
|
|
34
|
+
end
|
|
135
35
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
36
|
+
boolean_attr_accessor :sheet, :objects, :scenarios, :format_cells, :format_columns, :format_rows,
|
|
37
|
+
:insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
|
|
38
|
+
:select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells
|
|
39
|
+
|
|
40
|
+
serializable_attributes :sheet, :objects, :scenarios, :format_cells, :format_columns, :format_rows,
|
|
41
|
+
:insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
|
|
42
|
+
:select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells, :salt, :password
|
|
43
|
+
|
|
44
|
+
# Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm
|
|
45
|
+
# @return [String]
|
|
46
|
+
attr_reader :salt_value
|
|
47
|
+
|
|
48
|
+
# Password hash
|
|
49
|
+
# @return [String]
|
|
50
|
+
# default nil
|
|
51
|
+
attr_reader :password
|
|
52
|
+
|
|
53
|
+
# This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
|
|
54
|
+
# However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
|
|
55
|
+
# defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
|
|
56
|
+
# figure out why it does not work, and if Excel even supports it.
|
|
57
|
+
# def propper_password=(v)
|
|
58
|
+
# @algorithm_name = v == nil ? nil : 'SHA-1'
|
|
59
|
+
# @salt_value = @spin_count = @hash_value = v if v == nil
|
|
60
|
+
# return if v == nil
|
|
61
|
+
# require 'digest/sha1'
|
|
62
|
+
# @spin_count = 10000
|
|
63
|
+
# @salt_value = Digest::SHA1.hexdigest(rand(36**8).to_s(36))
|
|
64
|
+
# @spin_count.times do |count|
|
|
65
|
+
# @hash_value = Digest::SHA1.hexdigest((@hash_value ||= (@salt_value + v.to_s)) + Array(count).pack('V'))
|
|
66
|
+
# end
|
|
67
|
+
# end
|
|
68
|
+
|
|
69
|
+
# encodes password for protection locking
|
|
70
|
+
def password=(v)
|
|
71
|
+
return if v == nil
|
|
72
|
+
@password = create_password_hash(v)
|
|
139
73
|
end
|
|
140
74
|
|
|
75
|
+
# Serialize the object
|
|
76
|
+
# @param [String] str
|
|
77
|
+
# @return [String]
|
|
78
|
+
def to_xml_string(str = '')
|
|
79
|
+
str << '<sheetProtection '
|
|
80
|
+
serialized_attributes str
|
|
81
|
+
str << '/>'
|
|
82
|
+
end
|
|
141
83
|
|
|
142
|
-
|
|
143
|
-
# @return [Boolean]
|
|
144
|
-
[:sheet, :objects, :scenarios, :select_locked_cells, :sort,
|
|
145
|
-
:select_unlocked_cells, :format_cells, :format_rows, :format_columns,
|
|
146
|
-
:insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns,
|
|
147
|
-
:delete_rows, :auto_filter, :pivot_tables].each do |f_name|
|
|
148
|
-
define_method "#{f_name.to_s}=".to_sym do |v|
|
|
149
|
-
Axlsx::validate_boolean(v)
|
|
150
|
-
instance_variable_set "@#{f_name.to_s}".to_sym, v
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
|
|
155
|
-
# However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
|
|
156
|
-
# defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
|
|
157
|
-
# figure out why it does not work, and if Excel even supports it.
|
|
158
|
-
# def propper_password=(v)
|
|
159
|
-
# @algorithm_name = v == nil ? nil : 'SHA-1'
|
|
160
|
-
# @salt_value = @spin_count = @hash_value = v if v == nil
|
|
161
|
-
# return if v == nil
|
|
162
|
-
# require 'digest/sha1'
|
|
163
|
-
# @spin_count = 10000
|
|
164
|
-
# @salt_value = Digest::SHA1.hexdigest(rand(36**8).to_s(36))
|
|
165
|
-
# @spin_count.times do |count|
|
|
166
|
-
# @hash_value = Digest::SHA1.hexdigest((@hash_value ||= (@salt_value + v.to_s)) + Array(count).pack('V'))
|
|
167
|
-
# end
|
|
168
|
-
# end
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
# encodes password for protection locking
|
|
173
|
-
def password=(v)
|
|
174
|
-
return if v == nil
|
|
175
|
-
@password = create_password_hash(v)
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
# Serialize the object
|
|
179
|
-
# @param [String] str
|
|
180
|
-
# @return [String]
|
|
181
|
-
def to_xml_string(str = '')
|
|
182
|
-
str << '<sheetProtection '
|
|
183
|
-
str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v.to_s}"} }.join(' ')
|
|
184
|
-
str << '/>'
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
private
|
|
84
|
+
private
|
|
188
85
|
# Creates a password hash for a given password
|
|
189
86
|
# @return [String]
|
|
190
87
|
def create_password_hash(password)
|
|
@@ -196,7 +93,6 @@ module Axlsx
|
|
|
196
93
|
password_as_string[2..3] + password_as_string[0..1]
|
|
197
94
|
end
|
|
198
95
|
|
|
199
|
-
|
|
200
96
|
# Encodes a given password
|
|
201
97
|
# Based on the algorithm provided by Daniel Rentz of OpenOffice.
|
|
202
98
|
# http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
|