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,6 +5,8 @@ module Axlsx
|
|
|
5
5
|
# This class is extended for NumData to include the formatCode attribute required for numLit and numCache
|
|
6
6
|
class StrData
|
|
7
7
|
|
|
8
|
+
include Axlsx::OptionsParser
|
|
9
|
+
|
|
8
10
|
# creates a new StrVal object
|
|
9
11
|
# @option options [Array] :data
|
|
10
12
|
# @option options [String] :tag_name
|
|
@@ -12,9 +14,7 @@ module Axlsx
|
|
|
12
14
|
@tag_prefix = :str
|
|
13
15
|
@type = StrVal
|
|
14
16
|
@pt = SimpleTypedList.new(@type)
|
|
15
|
-
options
|
|
16
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
17
|
-
end
|
|
17
|
+
parse_options options
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
|
|
@@ -4,19 +4,20 @@ module Axlsx
|
|
|
4
4
|
#This class specifies data for a particular data point.
|
|
5
5
|
class StrVal
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
# @return [String]
|
|
9
|
-
attr_reader :v
|
|
7
|
+
include Axlsx::OptionsParser
|
|
10
8
|
|
|
11
9
|
# creates a new StrVal object
|
|
12
10
|
# @option options [String] v
|
|
13
11
|
def initialize(options={})
|
|
14
12
|
@v = ""
|
|
15
13
|
@idx = 0
|
|
16
|
-
options
|
|
17
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
18
|
-
end
|
|
14
|
+
parse_options options
|
|
19
15
|
end
|
|
16
|
+
|
|
17
|
+
# a string value.
|
|
18
|
+
# @return [String]
|
|
19
|
+
attr_reader :v
|
|
20
|
+
|
|
20
21
|
# @see v
|
|
21
22
|
def v=(v)
|
|
22
23
|
@v = v.to_s
|
|
@@ -27,7 +28,5 @@ module Axlsx
|
|
|
27
28
|
Axlsx::validate_unsigned_int(idx)
|
|
28
29
|
str << '<c:pt idx="' << idx.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>'
|
|
29
30
|
end
|
|
30
|
-
|
|
31
31
|
end
|
|
32
|
-
|
|
33
32
|
end
|
|
@@ -3,6 +3,20 @@ module Axlsx
|
|
|
3
3
|
# 3D attributes for a chart.
|
|
4
4
|
class View3D
|
|
5
5
|
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
|
|
8
|
+
# Creates a new View3D for charts
|
|
9
|
+
# @option options [Integer] rot_x
|
|
10
|
+
# @option options [String] h_percent
|
|
11
|
+
# @option options [Integer] rot_y
|
|
12
|
+
# @option options [String] depth_percent
|
|
13
|
+
# @option options [Boolean] r_ang_ax
|
|
14
|
+
# @option options [Integer] perspective
|
|
15
|
+
def initialize(options={})
|
|
16
|
+
@rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
|
|
17
|
+
parse_options options
|
|
18
|
+
end
|
|
19
|
+
|
|
6
20
|
# Validation for hPercent
|
|
7
21
|
H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/
|
|
8
22
|
|
|
@@ -14,8 +28,8 @@ module Axlsx
|
|
|
14
28
|
# @return [Integer]
|
|
15
29
|
attr_reader :rot_x
|
|
16
30
|
alias :rotX :rot_x
|
|
17
|
-
|
|
18
|
-
# height of chart as % of chart
|
|
31
|
+
|
|
32
|
+
# height of chart as % of chart width
|
|
19
33
|
# must be between 5% and 500%
|
|
20
34
|
# @return [String]
|
|
21
35
|
attr_reader :h_percent
|
|
@@ -26,7 +40,7 @@ module Axlsx
|
|
|
26
40
|
# @return [Integer]
|
|
27
41
|
attr_reader :rot_y
|
|
28
42
|
alias :rotY :rot_y
|
|
29
|
-
|
|
43
|
+
|
|
30
44
|
# depth or chart as % of chart width
|
|
31
45
|
# must be between 20% and 2000%
|
|
32
46
|
# @return [String]
|
|
@@ -42,60 +56,60 @@ module Axlsx
|
|
|
42
56
|
# @return [Integer]
|
|
43
57
|
attr_reader :perspective
|
|
44
58
|
|
|
45
|
-
# Creates a new View3D for charts
|
|
46
|
-
# @option options [Integer] rot_x
|
|
47
|
-
# @option options [String] h_percent
|
|
48
|
-
# @option options [Integer] rot_y
|
|
49
|
-
# @option options [String] depth_percent
|
|
50
|
-
# @option options [Boolean] r_ang_ax
|
|
51
|
-
# @option options [Integer] perspective
|
|
52
|
-
def initialize(options={})
|
|
53
|
-
@rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
|
|
54
|
-
options.each do |o|
|
|
55
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
59
|
# @see rot_x
|
|
60
|
-
def rot_x=(v)
|
|
60
|
+
def rot_x=(v)
|
|
61
|
+
RangeValidator.validate "View3D.rot_x", -90, 90, v
|
|
62
|
+
@rot_x = v
|
|
63
|
+
end
|
|
61
64
|
alias :rotX= :rot_x=
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
# @see h_percent
|
|
67
|
+
def h_percent=(v)
|
|
68
|
+
RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
|
|
69
|
+
@h_percent = v
|
|
70
|
+
end
|
|
68
71
|
alias :hPercent= :h_percent=
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
# @see rot_y
|
|
74
|
+
def rot_y=(v)
|
|
75
|
+
RangeValidator.validate "View3D.rot_y", 0, 360, v
|
|
76
|
+
@rot_y = v
|
|
77
|
+
end
|
|
72
78
|
alias :rotY= :rot_y=
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
# @see depth_percent
|
|
81
|
+
def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
|
|
76
82
|
alias :depthPercent= :depth_percent=
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
# @see r_ang_ax
|
|
85
|
+
def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
|
|
80
86
|
alias :rAngAx= :r_ang_ax=
|
|
81
|
-
|
|
82
|
-
# @see perspective
|
|
83
|
-
def perspective=(v) DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
|
|
84
87
|
|
|
88
|
+
# @see perspective
|
|
89
|
+
def perspective=(v)
|
|
90
|
+
RangeValidator.validate "View3D.perspective", 0, 240, v
|
|
91
|
+
@perspective = v
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
|
|
85
95
|
|
|
86
96
|
# Serializes the object
|
|
87
97
|
# @param [String] str
|
|
88
98
|
# @return [String]
|
|
89
99
|
def to_xml_string(str = '')
|
|
90
100
|
str << '<c:view3D>'
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
str << '<c:depthPercent val="' << @depth_percent.to_s << '"/>' unless @depth_percent.nil?
|
|
95
|
-
str << '<c:rAngAx val="' << @r_ang_ax.to_s << '"/>' unless @r_ang_ax.nil?
|
|
96
|
-
str << '<c:perspective val="' << @perspective.to_s << '"/>' unless @perspective.nil?
|
|
101
|
+
%w(rot_x h_percent rot_y depth_percent r_ang_ax perspective).each do |key|
|
|
102
|
+
str << element_for_attribute(key, 'c')
|
|
103
|
+
end
|
|
97
104
|
str << '</c:view3D>'
|
|
98
105
|
end
|
|
99
106
|
|
|
107
|
+
private
|
|
108
|
+
# Note: move this to Axlsx module if we find the smae pattern elsewhere.
|
|
109
|
+
def element_for_attribute(name, namespace='')
|
|
110
|
+
val = instance_values[name]
|
|
111
|
+
return "" if val == nil
|
|
112
|
+
"<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val]
|
|
113
|
+
end
|
|
100
114
|
end
|
|
101
115
|
end
|
|
@@ -3,6 +3,28 @@ module Axlsx
|
|
|
3
3
|
# A VmlShape is used to position and render a comment.
|
|
4
4
|
class VmlShape
|
|
5
5
|
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
|
|
8
|
+
# Creates a new VmlShape
|
|
9
|
+
# @option options [Integer|String] left_column
|
|
10
|
+
# @option options [Integer|String] left_offset
|
|
11
|
+
# @option options [Integer|String] top_row
|
|
12
|
+
# @option options [Integer|String] top_offset
|
|
13
|
+
# @option options [Integer|String] right_column
|
|
14
|
+
# @option options [Integer|String] right_offset
|
|
15
|
+
# @option options [Integer|String] bottom_row
|
|
16
|
+
# @option options [Integer|String] bottom_offset
|
|
17
|
+
def initialize(options={})
|
|
18
|
+
@row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
|
|
19
|
+
@left_offset = 15
|
|
20
|
+
@top_offset = 2
|
|
21
|
+
@right_offset = 50
|
|
22
|
+
@bottom_offset = 5
|
|
23
|
+
@id = (0...8).map{65.+(rand(25)).chr}.join
|
|
24
|
+
parse_options options
|
|
25
|
+
yield self if block_given?
|
|
26
|
+
end
|
|
27
|
+
|
|
6
28
|
# The row anchor position for this shape determined by the comment's ref value
|
|
7
29
|
# @return [Integer]
|
|
8
30
|
attr_reader :row
|
|
@@ -43,29 +65,7 @@ module Axlsx
|
|
|
43
65
|
# @return [Integer]
|
|
44
66
|
attr_reader :bottom_offset
|
|
45
67
|
|
|
46
|
-
|
|
47
|
-
# @option options [Integer|String] left_column
|
|
48
|
-
# @option options [Integer|String] left_offset
|
|
49
|
-
# @option options [Integer|String] top_row
|
|
50
|
-
# @option options [Integer|String] top_offset
|
|
51
|
-
# @option options [Integer|String] right_column
|
|
52
|
-
# @option options [Integer|String] right_offset
|
|
53
|
-
# @option options [Integer|String] bottom_row
|
|
54
|
-
# @option options [Integer|String] bottom_offset
|
|
55
|
-
def initialize(options={})
|
|
56
|
-
@row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
|
|
57
|
-
@left_offset = 15
|
|
58
|
-
@top_offset = 2
|
|
59
|
-
@right_offset = 50
|
|
60
|
-
@bottom_offset = 5
|
|
61
|
-
@id = (0...8).map{65.+(rand(25)).chr}.join
|
|
62
|
-
options.each do |o|
|
|
63
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
64
|
-
end
|
|
65
|
-
yield self if block_given?
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# @see column
|
|
68
|
+
# @see column
|
|
69
69
|
def column=(v); Axlsx::validate_integerish(v); @column = v.to_i end
|
|
70
70
|
|
|
71
71
|
# @see row
|
data/lib/axlsx/package.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Axlsx
|
|
|
3
3
|
# Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
|
|
4
4
|
# xlsx document including valdation and serialization.
|
|
5
5
|
class Package
|
|
6
|
-
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
7
|
|
|
8
8
|
# provides access to the app doc properties for this package
|
|
9
9
|
# see App
|
|
@@ -23,9 +23,7 @@ module Axlsx
|
|
|
23
23
|
@workbook = nil
|
|
24
24
|
@core, @app = Core.new, App.new
|
|
25
25
|
@core.creator = options[:author] || @core.creator
|
|
26
|
-
options
|
|
27
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
28
|
-
end
|
|
26
|
+
parse_options options
|
|
29
27
|
yield self if block_given?
|
|
30
28
|
end
|
|
31
29
|
|
|
@@ -175,7 +173,7 @@ module Axlsx
|
|
|
175
173
|
# @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
|
|
176
174
|
# @private
|
|
177
175
|
def parts
|
|
178
|
-
|
|
176
|
+
parts = [
|
|
179
177
|
{:entry => RELS_PN, :doc => relationships.to_xml_string, :schema => RELS_XSD},
|
|
180
178
|
{:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml_string, :schema => SML_XSD},
|
|
181
179
|
{:entry => CORE_PN, :doc => @core.to_xml_string, :schema => CORE_XSD},
|
|
@@ -186,39 +184,39 @@ module Axlsx
|
|
|
186
184
|
]
|
|
187
185
|
|
|
188
186
|
workbook.drawings.each do |drawing|
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD}
|
|
188
|
+
parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD}
|
|
191
189
|
end
|
|
192
190
|
|
|
193
191
|
|
|
194
192
|
workbook.tables.each do |table|
|
|
195
|
-
|
|
193
|
+
parts << {:entry => "xl/#{table.pn}", :doc => table.to_xml_string, :schema => SML_XSD}
|
|
196
194
|
end
|
|
197
195
|
|
|
198
196
|
workbook.comments.each do|comment|
|
|
199
197
|
if comment.size > 0
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
parts << { :entry => "xl/#{comment.pn}", :doc => comment.to_xml_string, :schema => SML_XSD }
|
|
199
|
+
parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing.to_xml_string, :schema => nil }
|
|
202
200
|
end
|
|
203
201
|
end
|
|
204
202
|
|
|
205
203
|
workbook.charts.each do |chart|
|
|
206
|
-
|
|
204
|
+
parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD}
|
|
207
205
|
end
|
|
208
206
|
|
|
209
207
|
workbook.images.each do |image|
|
|
210
|
-
|
|
208
|
+
parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
|
|
211
209
|
end
|
|
212
210
|
|
|
213
211
|
if use_shared_strings
|
|
214
|
-
|
|
212
|
+
parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml_string, :schema => SML_XSD}
|
|
215
213
|
end
|
|
216
214
|
|
|
217
215
|
workbook.worksheets.each do |sheet|
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml_string, :schema => RELS_XSD}
|
|
217
|
+
parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml_string, :schema => SML_XSD}
|
|
220
218
|
end
|
|
221
|
-
|
|
219
|
+
parts
|
|
222
220
|
end
|
|
223
221
|
|
|
224
222
|
# Performs xsd validation for a signle document
|
|
@@ -242,7 +240,6 @@ module Axlsx
|
|
|
242
240
|
# @private
|
|
243
241
|
def content_types
|
|
244
242
|
c_types = base_content_types
|
|
245
|
-
|
|
246
243
|
workbook.drawings.each do |drawing|
|
|
247
244
|
c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
|
|
248
245
|
:ContentType => DRAWING_CT)
|
|
@@ -3,21 +3,12 @@ module Axlsx
|
|
|
3
3
|
# This class details a border used in Office Open XML spreadsheet styles.
|
|
4
4
|
class Border
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.
|
|
10
|
-
attr_reader :diagonalDown
|
|
11
|
-
|
|
12
|
-
# @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.
|
|
13
|
-
attr_reader :outline
|
|
14
|
-
|
|
15
|
-
# @return [SimpleTypedList] A list of BorderPr objects for this border.
|
|
16
|
-
attr_reader :prs
|
|
6
|
+
include Axlsx::SerializedAttributes
|
|
7
|
+
include Axlsx::OptionsParser
|
|
17
8
|
|
|
18
9
|
# Creates a new Border object
|
|
19
|
-
# @option options [Boolean]
|
|
20
|
-
# @option options [Boolean]
|
|
10
|
+
# @option options [Boolean] diagonal_up
|
|
11
|
+
# @option options [Boolean] diagonal_down
|
|
21
12
|
# @option options [Boolean] outline
|
|
22
13
|
# @example - Making a border
|
|
23
14
|
# p = Axlsx::Package.new
|
|
@@ -30,15 +21,33 @@ module Axlsx
|
|
|
30
21
|
# @see Style#add_style
|
|
31
22
|
def initialize(options={})
|
|
32
23
|
@prs = SimpleTypedList.new BorderPr
|
|
33
|
-
options
|
|
34
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
35
|
-
end
|
|
24
|
+
parse_options options
|
|
36
25
|
end
|
|
37
26
|
|
|
27
|
+
serializable_attributes :diagonal_up, :diagonal_down, :outline
|
|
28
|
+
|
|
29
|
+
# @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.
|
|
30
|
+
attr_reader :diagonal_up
|
|
31
|
+
alias :diagonalUp :diagonal_up
|
|
32
|
+
|
|
33
|
+
# @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.
|
|
34
|
+
attr_reader :diagonal_down
|
|
35
|
+
alias :diagonalDown :diagonal_down
|
|
36
|
+
|
|
37
|
+
# @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.
|
|
38
|
+
attr_reader :outline
|
|
39
|
+
|
|
40
|
+
# @return [SimpleTypedList] A list of BorderPr objects for this border.
|
|
41
|
+
attr_reader :prs
|
|
42
|
+
|
|
38
43
|
# @see diagonalUp
|
|
39
|
-
def
|
|
44
|
+
def diagonal_up=(v) Axlsx::validate_boolean v; @diagonal_up = v end
|
|
45
|
+
alias :diagonalUp= :diagonal_up=
|
|
46
|
+
|
|
40
47
|
# @see diagonalDown
|
|
41
|
-
def
|
|
48
|
+
def diagonal_down=(v) Axlsx::validate_boolean v; @diagonal_down = v end
|
|
49
|
+
alias :diagonalDown= :diagonal_down=
|
|
50
|
+
|
|
42
51
|
# @see outline
|
|
43
52
|
def outline=(v) Axlsx::validate_boolean v; @outline = v end
|
|
44
53
|
|
|
@@ -47,9 +56,9 @@ module Axlsx
|
|
|
47
56
|
# @return [String]
|
|
48
57
|
def to_xml_string(str = '')
|
|
49
58
|
str << '<border '
|
|
50
|
-
|
|
51
|
-
str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
|
59
|
+
serialized_attributes str
|
|
52
60
|
str << '>'
|
|
61
|
+
# enforces order
|
|
53
62
|
[:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
|
|
54
63
|
@prs.select { |pr| pr.name == k }.each do |part|
|
|
55
64
|
part.to_xml_string(str)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
module Axlsx
|
|
3
3
|
# A border part.
|
|
4
4
|
class BorderPr
|
|
5
|
-
|
|
5
|
+
include Axlsx::OptionsParser
|
|
6
6
|
# @return [Color] The color of this border part.
|
|
7
7
|
attr_reader :color
|
|
8
8
|
|
|
@@ -45,9 +45,10 @@ module Axlsx
|
|
|
45
45
|
# @option options [Symbol] style
|
|
46
46
|
# @see Axlsx::Border
|
|
47
47
|
def initialize(options={})
|
|
48
|
-
options
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
parse_options(options)
|
|
49
|
+
#options.each do |o|
|
|
50
|
+
# self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
51
|
+
#end
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
# @see name
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
module Axlsx
|
|
3
|
+
|
|
4
|
+
|
|
3
5
|
# CellAlignment stores information about the cell alignment of a style Xf Object.
|
|
4
6
|
# @note Using Styles#add_style is the recommended way to manage cell alignment.
|
|
5
7
|
# @see Styles#add_style
|
|
6
8
|
class CellAlignment
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
include Axlsx::SerializedAttributes
|
|
12
|
+
include Axlsx::OptionsParser
|
|
13
|
+
|
|
14
|
+
serializable_attributes :horizontal, :vertical, :text_rotation, :wrap_text, :indent, :relative_indent, :justify_last_line, :shrink_to_fit, :reading_order
|
|
15
|
+
# Create a new cell_alignment object
|
|
16
|
+
# @option options [Symbol] horizontal
|
|
17
|
+
# @option options [Symbol] vertical
|
|
18
|
+
# @option options [Integer] text_rotation
|
|
19
|
+
# @option options [Boolean] wrap_text
|
|
20
|
+
# @option options [Integer] indent
|
|
21
|
+
# @option options [Integer] relative_indent
|
|
22
|
+
# @option options [Boolean] justify_last_line
|
|
23
|
+
# @option options [Boolean] shrink_to_fit
|
|
24
|
+
# @option options [Integer] reading_order
|
|
25
|
+
def initialize(options={})
|
|
26
|
+
parse_options options
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
7
31
|
# The horizontal alignment of the cell.
|
|
8
32
|
# @note
|
|
9
33
|
# The horizontal cell alignement style must be one of
|
|
@@ -31,11 +55,13 @@ module Axlsx
|
|
|
31
55
|
|
|
32
56
|
# The textRotation of the cell.
|
|
33
57
|
# @return [Integer]
|
|
34
|
-
attr_reader :
|
|
58
|
+
attr_reader :text_rotation
|
|
59
|
+
alias :textRotation :text_rotation
|
|
35
60
|
|
|
36
61
|
# Indicate if the text of the cell should wrap
|
|
37
62
|
# @return [Boolean]
|
|
38
|
-
attr_reader :
|
|
63
|
+
attr_reader :wrap_text
|
|
64
|
+
alias :wrapText :wrap_text
|
|
39
65
|
|
|
40
66
|
# The amount of indent
|
|
41
67
|
# @return [Integer]
|
|
@@ -43,64 +69,64 @@ module Axlsx
|
|
|
43
69
|
|
|
44
70
|
# The amount of relativeIndent
|
|
45
71
|
# @return [Integer]
|
|
46
|
-
attr_reader :
|
|
72
|
+
attr_reader :relative_indent
|
|
73
|
+
alias :relativeIndent :relative_indent
|
|
47
74
|
|
|
48
75
|
# Indicate if the last line should be justified.
|
|
49
76
|
# @return [Boolean]
|
|
50
|
-
attr_reader :
|
|
77
|
+
attr_reader :justify_last_line
|
|
78
|
+
alias :justifyLastLine :justify_last_line
|
|
51
79
|
|
|
52
80
|
# Indicate if the text should be shrunk to the fit in the cell.
|
|
53
81
|
# @return [Boolean]
|
|
54
|
-
attr_reader :
|
|
82
|
+
attr_reader :shrink_to_fit
|
|
83
|
+
alias :shrinkToFit :shrink_to_fit
|
|
55
84
|
|
|
56
85
|
# The reading order of the text
|
|
57
86
|
# 0 Context Dependent
|
|
58
87
|
# 1 Left-to-Right
|
|
59
88
|
# 2 Right-to-Left
|
|
60
89
|
# @return [Integer]
|
|
61
|
-
attr_reader :
|
|
62
|
-
|
|
63
|
-
# Create a new cell_alignment object
|
|
64
|
-
# @option options [Symbol] horizontal
|
|
65
|
-
# @option options [Symbol] vertical
|
|
66
|
-
# @option options [Integer] textRotation
|
|
67
|
-
# @option options [Boolean] wrapText
|
|
68
|
-
# @option options [Integer] indent
|
|
69
|
-
# @option options [Integer] relativeIndent
|
|
70
|
-
# @option options [Boolean] justifyLastLine
|
|
71
|
-
# @option options [Boolean] shrinkToFit
|
|
72
|
-
# @option options [Integer] readingOrder
|
|
73
|
-
def initialize(options={})
|
|
74
|
-
options.each do |o|
|
|
75
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
76
|
-
end
|
|
77
|
-
end
|
|
90
|
+
attr_reader :reading_order
|
|
91
|
+
alias :readingOrder :reading_order
|
|
78
92
|
|
|
79
93
|
# @see horizontal
|
|
80
94
|
def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
|
|
81
95
|
# @see vertical
|
|
82
96
|
def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
|
|
83
97
|
# @see textRotation
|
|
84
|
-
def
|
|
98
|
+
def text_rotation=(v) Axlsx::validate_unsigned_int v; @text_rotation = v end
|
|
99
|
+
alias :textRotation= :text_rotation=
|
|
100
|
+
|
|
85
101
|
# @see wrapText
|
|
86
|
-
def
|
|
102
|
+
def wrap_text=(v) Axlsx::validate_boolean v; @wrap_text = v end
|
|
103
|
+
alias :wrapText= :wrap_text=
|
|
104
|
+
|
|
87
105
|
# @see indent
|
|
88
106
|
def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
|
|
107
|
+
|
|
89
108
|
# @see relativeIndent
|
|
90
|
-
def
|
|
109
|
+
def relative_indent=(v) Axlsx::validate_int v; @relative_indent = v end
|
|
110
|
+
alias :relativeIndent= :relative_indent=
|
|
111
|
+
|
|
91
112
|
# @see justifyLastLine
|
|
92
|
-
def
|
|
113
|
+
def justify_last_line=(v) Axlsx::validate_boolean v; @justify_last_line = v end
|
|
114
|
+
alias :justifyLastLine= :justify_last_line=
|
|
115
|
+
|
|
93
116
|
# @see shrinkToFit
|
|
94
|
-
def
|
|
117
|
+
def shrink_to_fit=(v) Axlsx::validate_boolean v; @shrink_to_fit = v end
|
|
118
|
+
alias :shrinkToFit= :shrink_to_fit=
|
|
119
|
+
|
|
95
120
|
# @see readingOrder
|
|
96
|
-
def
|
|
121
|
+
def reading_order=(v) Axlsx::validate_unsigned_int v; @reading_order = v end
|
|
122
|
+
alias :readingOrder= :reading_order=
|
|
97
123
|
|
|
98
124
|
# Serializes the object
|
|
99
125
|
# @param [String] str
|
|
100
126
|
# @return [String]
|
|
101
127
|
def to_xml_string(str = '')
|
|
102
128
|
str << '<alignment '
|
|
103
|
-
str
|
|
129
|
+
serialized_attributes str
|
|
104
130
|
str << '/>'
|
|
105
131
|
end
|
|
106
132
|
|
|
@@ -5,6 +5,11 @@ module Axlsx
|
|
|
5
5
|
# @see Styles#add_style
|
|
6
6
|
class CellProtection
|
|
7
7
|
|
|
8
|
+
include Axlsx::OptionsParser
|
|
9
|
+
include Axlsx::SerializedAttributes
|
|
10
|
+
|
|
11
|
+
serializable_attributes :hidden, :locked
|
|
12
|
+
|
|
8
13
|
# specifies locking for cells that have the style containing this protection
|
|
9
14
|
# @return [Boolean]
|
|
10
15
|
attr_reader :hidden
|
|
@@ -17,9 +22,7 @@ module Axlsx
|
|
|
17
22
|
# @option options [Boolean] hidden value for hidden protection
|
|
18
23
|
# @option options [Boolean] locked value for locked protection
|
|
19
24
|
def initialize(options={})
|
|
20
|
-
options
|
|
21
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
22
|
-
end
|
|
25
|
+
parse_options options
|
|
23
26
|
end
|
|
24
27
|
|
|
25
28
|
# @see hidden
|
|
@@ -32,7 +35,7 @@ module Axlsx
|
|
|
32
35
|
# @return [String]
|
|
33
36
|
def to_xml_string(str = '')
|
|
34
37
|
str << '<protection '
|
|
35
|
-
str
|
|
38
|
+
serialized_attributes str
|
|
36
39
|
str << '/>'
|
|
37
40
|
end
|
|
38
41
|
|
|
@@ -4,6 +4,23 @@ module Axlsx
|
|
|
4
4
|
# @note Using Styles#add_style is the recommended way to manage cell styling.
|
|
5
5
|
# @see Styles#add_style
|
|
6
6
|
class CellStyle
|
|
7
|
+
|
|
8
|
+
include Axlsx::OptionsParser
|
|
9
|
+
include Axlsx::SerializedAttributes
|
|
10
|
+
|
|
11
|
+
# Creats a new CellStyle object
|
|
12
|
+
# @option options [String] name
|
|
13
|
+
# @option options [Integer] xfId
|
|
14
|
+
# @option options [Integer] buildinId
|
|
15
|
+
# @option options [Integer] iLevel
|
|
16
|
+
# @option options [Boolean] hidden
|
|
17
|
+
# @option options [Boolean] customBuiltIn
|
|
18
|
+
def initialize(options={})
|
|
19
|
+
parse_options options
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
serializable_attributes :name, :xfId, :buildinId, :iLevel, :hidden, :customBuilin
|
|
23
|
+
|
|
7
24
|
# The name of this cell style
|
|
8
25
|
# @return [String]
|
|
9
26
|
attr_reader :name
|
|
@@ -30,19 +47,7 @@ module Axlsx
|
|
|
30
47
|
# @return [Boolean]
|
|
31
48
|
attr_reader :customBuiltin
|
|
32
49
|
|
|
33
|
-
|
|
34
|
-
# @option options [String] name
|
|
35
|
-
# @option options [Integer] xfId
|
|
36
|
-
# @option options [Integer] buildinId
|
|
37
|
-
# @option options [Integer] iLevel
|
|
38
|
-
# @option options [Boolean] hidden
|
|
39
|
-
# @option options [Boolean] customBuiltIn
|
|
40
|
-
def initialize(options={})
|
|
41
|
-
options.each do |o|
|
|
42
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
# @see name
|
|
50
|
+
# @see name
|
|
46
51
|
def name=(v) Axlsx::validate_string v; @name = v end
|
|
47
52
|
# @see xfId
|
|
48
53
|
def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
|
|
@@ -60,7 +65,7 @@ module Axlsx
|
|
|
60
65
|
# @return [String]
|
|
61
66
|
def to_xml_string(str = '')
|
|
62
67
|
str << '<cellStyle '
|
|
63
|
-
str
|
|
68
|
+
serialized_attributes str
|
|
64
69
|
str << '/>'
|
|
65
70
|
end
|
|
66
71
|
|