axlsx 1.0.18 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -3
- data/README.md +93 -18
- data/examples/example.csv +1000 -0
- data/examples/example.rb +97 -5
- data/examples/example.xlsx +0 -0
- 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.rb +30 -9
- data/lib/axlsx/content_type/content_type.rb +9 -9
- data/lib/axlsx/content_type/default.rb +9 -6
- data/lib/axlsx/content_type/override.rb +12 -8
- data/lib/axlsx/doc_props/app.rb +37 -40
- data/lib/axlsx/doc_props/core.rb +12 -17
- data/lib/axlsx/drawing/axis.rb +38 -19
- data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
- data/lib/axlsx/drawing/bar_series.rb +13 -14
- data/lib/axlsx/drawing/cat_axis.rb +15 -14
- data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
- data/lib/axlsx/drawing/chart.rb +37 -38
- data/lib/axlsx/drawing/drawing.rb +15 -12
- data/lib/axlsx/drawing/graphic_frame.rb +21 -21
- data/lib/axlsx/drawing/hyperlink.rb +12 -11
- data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
- data/lib/axlsx/drawing/line_series.rb +11 -11
- data/lib/axlsx/drawing/marker.rb +10 -8
- data/lib/axlsx/drawing/named_axis_data.rb +36 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
- data/lib/axlsx/drawing/pic.rb +24 -37
- data/lib/axlsx/drawing/picture_locking.rb +21 -18
- data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
- data/lib/axlsx/drawing/pie_series.rb +15 -12
- data/lib/axlsx/drawing/scaling.rb +10 -10
- data/lib/axlsx/drawing/scatter_chart.rb +69 -0
- data/lib/axlsx/drawing/scatter_series.rb +39 -0
- data/lib/axlsx/drawing/ser_axis.rb +10 -10
- data/lib/axlsx/drawing/series.rb +15 -15
- data/lib/axlsx/drawing/series_title.rb +14 -14
- data/lib/axlsx/drawing/title.rb +26 -26
- data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
- data/lib/axlsx/drawing/val_axis.rb +8 -7
- data/lib/axlsx/drawing/val_axis_data.rb +17 -17
- data/lib/axlsx/drawing/view_3D.rb +22 -20
- data/lib/axlsx/package.rb +32 -15
- data/lib/axlsx/rels/relationship.rb +9 -6
- data/lib/axlsx/rels/relationships.rb +7 -1
- data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
- data/lib/axlsx/stylesheet/border.rb +27 -23
- data/lib/axlsx/stylesheet/border_pr.rb +16 -15
- data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
- data/lib/axlsx/stylesheet/cell_style.rb +8 -5
- data/lib/axlsx/stylesheet/color.rb +20 -14
- data/lib/axlsx/stylesheet/fill.rb +7 -5
- data/lib/axlsx/stylesheet/font.rb +14 -14
- data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
- data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
- data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
- data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
- data/lib/axlsx/stylesheet/styles.rb +41 -32
- data/lib/axlsx/stylesheet/table_style.rb +9 -4
- data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
- data/lib/axlsx/stylesheet/table_styles.rb +11 -8
- data/lib/axlsx/stylesheet/xf.rb +29 -25
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +18 -9
- data/lib/axlsx/util/validators.rb +13 -6
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
- data/lib/axlsx/workbook/workbook.rb +43 -19
- data/lib/axlsx/workbook/worksheet/cell.rb +93 -91
- data/lib/axlsx/workbook/worksheet/col.rb +114 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table.rb +96 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +152 -118
- data/lib/schema/dc.xsd +5 -5
- data/lib/schema/dcmitype.xsd +5 -3
- data/lib/schema/dcterms.xsd +15 -15
- data/lib/schema/opc-coreProperties.xsd +6 -2
- data/lib/schema/xml.xsd +7 -8
- data/test/#benchmark.txt# +7 -0
- data/test/#tc_helper.rb# +3 -0
- data/test/benchmark.rb +81 -0
- data/test/benchmark.rb~ +0 -0
- data/test/benchmark.txt +6 -0
- data/test/benchmark.txt~ +6 -0
- data/test/content_type/tc_content_type.rb +30 -32
- data/test/content_type/tc_default.rb +8 -23
- data/test/content_type/tc_override.rb +7 -21
- data/test/doc_props/tc_app.rb +2 -8
- data/test/doc_props/tc_core.rb +6 -7
- data/test/drawing/tc_axis.rb +7 -3
- data/test/drawing/tc_bar_3D_chart.rb +6 -7
- data/test/drawing/tc_bar_series.rb +4 -5
- data/test/drawing/tc_cat_axis.rb +2 -3
- data/test/drawing/tc_cat_axis_data.rb +2 -3
- data/test/drawing/tc_chart.rb +11 -12
- data/test/drawing/tc_drawing.rb +7 -8
- data/test/drawing/tc_graphic_frame.rb +3 -4
- data/test/drawing/tc_hyperlink.rb +2 -3
- data/test/drawing/tc_line_3d_chart.rb +5 -6
- data/test/drawing/tc_line_series.rb +3 -4
- data/test/drawing/tc_marker.rb +3 -4
- data/test/drawing/tc_one_cell_anchor.rb +6 -7
- data/test/drawing/tc_pic.rb +8 -9
- data/test/drawing/tc_picture_locking.rb +2 -3
- data/test/drawing/tc_pie_3D_chart.rb +5 -6
- data/test/drawing/tc_pie_series.rb +4 -5
- data/test/drawing/tc_scaling.rb +3 -4
- data/test/drawing/tc_scatter_chart.rb +43 -0
- data/test/drawing/tc_scatter_series.rb +20 -0
- data/test/drawing/tc_ser_axis.rb +2 -3
- data/test/drawing/tc_series.rb +4 -5
- data/test/drawing/tc_series_title.rb +4 -5
- data/test/drawing/tc_title.rb +4 -5
- data/test/drawing/tc_two_cell_anchor.rb +4 -5
- data/test/drawing/tc_val_axis.rb +2 -3
- data/test/drawing/tc_val_axis_data.rb +2 -3
- data/test/drawing/tc_view_3D.rb +6 -7
- data/test/example.csv +1000 -0
- data/test/example.xlsx +0 -0
- data/test/example_streamed.xlsx +0 -0
- data/test/profile.rb +33 -0
- data/test/rels/tc_relationship.rb +5 -6
- data/test/rels/tc_relationships.rb +4 -5
- data/test/stylesheet/tc_border.rb +3 -4
- data/test/stylesheet/tc_border_pr.rb +3 -4
- data/test/stylesheet/tc_cell_alignment.rb +4 -5
- data/test/stylesheet/tc_cell_protection.rb +2 -3
- data/test/stylesheet/tc_cell_style.rb +2 -3
- data/test/stylesheet/tc_color.rb +2 -3
- data/test/stylesheet/tc_fill.rb +1 -2
- data/test/stylesheet/tc_font.rb +5 -6
- data/test/stylesheet/tc_gradient_fill.rb +1 -2
- data/test/stylesheet/tc_gradient_stop.rb +1 -2
- data/test/stylesheet/tc_num_fmt.rb +1 -2
- data/test/stylesheet/tc_pattern_fill.rb +3 -4
- data/test/stylesheet/tc_styles.rb +15 -9
- data/test/stylesheet/tc_table_style.rb +2 -3
- data/test/stylesheet/tc_table_style_element.rb +2 -3
- data/test/stylesheet/tc_table_styles.rb +3 -4
- data/test/stylesheet/tc_xf.rb +16 -17
- data/test/tc_axlsx.rb +39 -0
- data/test/tc_axlsx.rb~ +0 -0
- data/test/tc_helper.rb +3 -0
- data/test/tc_helper.rb~ +3 -0
- data/test/tc_package.rb +13 -10
- data/test/util/tc_simple_typed_list.rb +8 -9
- data/test/util/tc_validators.rb +7 -8
- data/test/workbook/tc_shared_strings_table.rb +5 -6
- data/test/workbook/tc_workbook.rb +24 -6
- data/test/workbook/worksheet/table/tc_table.rb +71 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
- data/test/workbook/worksheet/tc_cell.rb +24 -10
- data/test/workbook/worksheet/tc_col.rb +59 -0
- data/test/workbook/worksheet/tc_col.rb~ +10 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +1 -2
- data/test/workbook/worksheet/tc_page_margins.rb +6 -9
- data/test/workbook/worksheet/tc_row.rb +26 -12
- data/test/workbook/worksheet/tc_worksheet.rb +134 -68
- metadata +150 -90
- data/test/drawing/tc_hyperlink.rb~ +0 -71
- data/test/workbook/tc_shared_strings_table.rb~ +0 -8
- data/test/workbook/worksheet/tc_date_time_converter.rb~ +0 -69
@@ -4,8 +4,9 @@ module Axlsx
|
|
4
4
|
require 'axlsx/drawing/series_title.rb'
|
5
5
|
require 'axlsx/drawing/series.rb'
|
6
6
|
require 'axlsx/drawing/pie_series.rb'
|
7
|
-
require 'axlsx/drawing/bar_series.rb'
|
8
|
-
require 'axlsx/drawing/line_series.rb'
|
7
|
+
require 'axlsx/drawing/bar_series.rb'
|
8
|
+
require 'axlsx/drawing/line_series.rb'
|
9
|
+
require 'axlsx/drawing/scatter_series.rb'
|
9
10
|
|
10
11
|
require 'axlsx/drawing/scaling.rb'
|
11
12
|
require 'axlsx/drawing/axis.rb'
|
@@ -15,9 +16,10 @@ module Axlsx
|
|
15
16
|
|
16
17
|
require 'axlsx/drawing/cat_axis_data.rb'
|
17
18
|
require 'axlsx/drawing/val_axis_data.rb'
|
19
|
+
require 'axlsx/drawing/named_axis_data.rb'
|
18
20
|
|
19
21
|
require 'axlsx/drawing/marker.rb'
|
20
|
-
|
22
|
+
|
21
23
|
require 'axlsx/drawing/one_cell_anchor.rb'
|
22
24
|
require 'axlsx/drawing/two_cell_anchor.rb'
|
23
25
|
require 'axlsx/drawing/graphic_frame.rb'
|
@@ -27,6 +29,7 @@ module Axlsx
|
|
27
29
|
require 'axlsx/drawing/pie_3D_chart.rb'
|
28
30
|
require 'axlsx/drawing/bar_3D_chart.rb'
|
29
31
|
require 'axlsx/drawing/line_3D_chart.rb'
|
32
|
+
require 'axlsx/drawing/scatter_chart.rb'
|
30
33
|
|
31
34
|
require 'axlsx/drawing/picture_locking.rb'
|
32
35
|
require 'axlsx/drawing/pic.rb'
|
@@ -43,7 +46,7 @@ module Axlsx
|
|
43
46
|
# The worksheet that owns the drawing
|
44
47
|
# @return [Worksheet]
|
45
48
|
attr_reader :worksheet
|
46
|
-
|
49
|
+
|
47
50
|
# A collection of anchors for this drawing
|
48
51
|
# only TwoCellAnchors are supported in this version
|
49
52
|
# @return [SimpleTypedList]
|
@@ -135,15 +138,15 @@ module Axlsx
|
|
135
138
|
r
|
136
139
|
end
|
137
140
|
|
138
|
-
# Serializes the
|
141
|
+
# Serializes the object
|
142
|
+
# @param [String] str
|
139
143
|
# @return [String]
|
140
|
-
def
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
builder.to_xml(:save_with => 0)
|
144
|
+
def to_xml_string(str = '')
|
145
|
+
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
146
|
+
str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '" xmlns:c="' << XML_NS_C << '">'
|
147
|
+
anchors.each { |anchor| anchor.to_xml_string(str) }
|
148
|
+
str << '</xdr:wsDr>'
|
147
149
|
end
|
150
|
+
|
148
151
|
end
|
149
152
|
end
|
@@ -17,37 +17,37 @@ module Axlsx
|
|
17
17
|
# @param [TwoCellAnchor] anchor
|
18
18
|
# @param [Class] chart_type
|
19
19
|
def initialize(anchor, chart_type, options)
|
20
|
-
DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
|
20
|
+
DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
|
21
21
|
@anchor = anchor
|
22
22
|
@chart = chart_type.new(self, options)
|
23
23
|
end
|
24
24
|
|
25
25
|
# The relationship id for this graphic
|
26
26
|
# @return [String]
|
27
|
-
def rId
|
27
|
+
def rId
|
28
28
|
"rId#{@anchor.index+1}"
|
29
29
|
end
|
30
30
|
|
31
|
-
# Serializes the
|
32
|
-
# @param [
|
31
|
+
# Serializes the object
|
32
|
+
# @param [String] str
|
33
33
|
# @return [String]
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
def to_xml_string(str = '')
|
35
|
+
str << '<xdr:graphicFrame>'
|
36
|
+
str << '<xdr:nvGraphicFramePr>'
|
37
|
+
str << '<xdr:cNvPr id="2" name="' << chart.title.text << '"/>'
|
38
|
+
str << '<xdr:cNvGraphicFramePr/>'
|
39
|
+
str << '</xdr:nvGraphicFramePr>'
|
40
|
+
str << '<xdr:xfrm>'
|
41
|
+
str << '<a:off x="0" y="0"/>'
|
42
|
+
str << '<a:ext cx="0" cy="0"/>'
|
43
|
+
str << '</xdr:xfrm>'
|
44
|
+
str << '<a:graphic>'
|
45
|
+
str << '<a:graphicData uri="' << XML_NS_C << '">'
|
46
|
+
str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId.to_s << '"/>'
|
47
|
+
str << '</a:graphicData>'
|
48
|
+
str << '</a:graphic>'
|
49
|
+
str << '</xdr:graphicFrame>'
|
51
50
|
end
|
51
|
+
|
52
52
|
end
|
53
53
|
end
|
@@ -31,12 +31,12 @@ module Axlsx
|
|
31
31
|
# indicates that the link has already been clicked.
|
32
32
|
# @return [Boolean]
|
33
33
|
attr_reader :highlightClick
|
34
|
-
|
34
|
+
|
35
35
|
# @see highlightClick
|
36
36
|
# @param [Boolean] v The value to assign
|
37
37
|
def highlightClick=(v) Axlsx::validate_boolean(v); @highlightClick = v end
|
38
38
|
|
39
|
-
# From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
|
39
|
+
# From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
|
40
40
|
# @return [Boolean]
|
41
41
|
attr_reader :history
|
42
42
|
|
@@ -52,12 +52,12 @@ module Axlsx
|
|
52
52
|
# @return [String]
|
53
53
|
attr_accessor :tooltip
|
54
54
|
|
55
|
-
#Creates a hyperlink object
|
55
|
+
#Creates a hyperlink object
|
56
56
|
# parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
|
57
57
|
# @param [Pic] parent
|
58
58
|
# @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
|
59
59
|
# @option options [String] tgtFrame Target frame for opening hyperlink
|
60
|
-
# @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
|
60
|
+
# @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
|
61
61
|
# @option options [String] href the target resource this hyperlink links to.
|
62
62
|
# @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
|
63
63
|
# @option options [Boolean] endSnd terminate any sound events when processing this link
|
@@ -70,22 +70,23 @@ module Axlsx
|
|
70
70
|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
71
71
|
end
|
72
72
|
yield self if block_given?
|
73
|
-
|
74
|
-
end
|
75
73
|
|
74
|
+
end
|
76
75
|
|
77
|
-
# Serializes the
|
78
|
-
# @param [
|
76
|
+
# Serializes the object
|
77
|
+
# @param [String] str
|
79
78
|
# @return [String]
|
80
|
-
def
|
79
|
+
def to_xml_string(str = '')
|
81
80
|
h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
|
82
81
|
h.delete('href')
|
83
82
|
h.delete('parent')
|
84
|
-
|
83
|
+
str << '<a:hlinkClick '
|
84
|
+
str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
85
|
+
str << '/>'
|
85
86
|
end
|
86
87
|
|
87
88
|
private
|
88
|
-
# The relational ID for this hyperlink
|
89
|
+
# The relational ID for this hyperlink
|
89
90
|
# @return [Integer]
|
90
91
|
def id
|
91
92
|
@parent.anchor.drawing.charts.size + @parent.anchor.drawing.images.size + @parent.anchor.drawing.hyperlinks.index(self) + 1
|
@@ -44,11 +44,11 @@ module Axlsx
|
|
44
44
|
|
45
45
|
# validation regex for gap amount percent
|
46
46
|
GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
|
47
|
-
|
47
|
+
|
48
48
|
# Creates a new line chart object
|
49
49
|
# @param [GraphicFrame] frame The workbook that owns this chart.
|
50
50
|
# @option options [Cell, String] title
|
51
|
-
# @option options [Boolean] show_legend
|
51
|
+
# @option options [Boolean] show_legend
|
52
52
|
# @option options [Symbol] grouping
|
53
53
|
# @option options [String] gapDepth
|
54
54
|
# @option options [Integer] rotX
|
@@ -68,7 +68,7 @@ module Axlsx
|
|
68
68
|
@catAxis = CatAxis.new(@catAxId, @valAxId)
|
69
69
|
@valAxis = ValAxis.new(@valAxId, @catAxId)
|
70
70
|
@serAxis = SerAxis.new(@serAxId, @valAxId)
|
71
|
-
super(frame, options)
|
71
|
+
super(frame, options)
|
72
72
|
@series_type = LineSeries
|
73
73
|
@view3D = View3D.new({:perspective=>30}.merge(options))
|
74
74
|
end
|
@@ -85,31 +85,33 @@ module Axlsx
|
|
85
85
|
@gapDepth=(v)
|
86
86
|
end
|
87
87
|
|
88
|
-
# Serializes the
|
88
|
+
# Serializes the object
|
89
|
+
# @param [String] str
|
89
90
|
# @return [String]
|
90
|
-
def
|
91
|
-
super() do |
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
@catAxis.
|
110
|
-
@valAxis.
|
111
|
-
@serAxis.
|
91
|
+
def to_xml_string(str = '')
|
92
|
+
super(str) do |str_inner|
|
93
|
+
str_inner << '<c:line3DChart>'
|
94
|
+
str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
|
95
|
+
str_inner << '<c:varyColors val="1"/>'
|
96
|
+
@series.each { |ser| ser.to_xml_string(str_inner) }
|
97
|
+
str_inner << '<c:dLbls>'
|
98
|
+
str_inner << '<c:showLegendKey val="0"/>'
|
99
|
+
str_inner << '<c:showVal val="0"/>'
|
100
|
+
str_inner << '<c:showCatName val="0"/>'
|
101
|
+
str_inner << '<c:showSerName val="0"/>'
|
102
|
+
str_inner << '<c:showPercent val="0"/>'
|
103
|
+
str_inner << '<c:showBubbleSize val="0"/>'
|
104
|
+
str_inner << '</c:dLbls>'
|
105
|
+
str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
|
106
|
+
str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
|
107
|
+
str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
|
108
|
+
str_inner << '<c:axId val="' << @serAxId.to_s << '"/>'
|
109
|
+
str_inner << '</c:line3DChart>'
|
110
|
+
@catAxis.to_xml_string str_inner
|
111
|
+
@valAxis.to_xml_string str_inner
|
112
|
+
@serAxis.to_xml_string str_inner
|
112
113
|
end
|
113
|
-
end
|
114
|
-
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
115
117
|
end
|
@@ -5,8 +5,8 @@ module Axlsx
|
|
5
5
|
# @see Worksheet#add_chart
|
6
6
|
# @see Chart#add_series
|
7
7
|
class LineSeries < Series
|
8
|
-
|
9
|
-
# The data for this series.
|
8
|
+
|
9
|
+
# The data for this series.
|
10
10
|
# @return [ValAxisData]
|
11
11
|
attr_reader :data
|
12
12
|
|
@@ -23,19 +23,19 @@ module Axlsx
|
|
23
23
|
super(chart, options)
|
24
24
|
@labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
|
25
25
|
@data = ValAxisData.new(options[:data]) unless options[:data].nil?
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
|
-
# Serializes the
|
29
|
-
# @param [
|
28
|
+
# Serializes the object
|
29
|
+
# @param [String] str
|
30
30
|
# @return [String]
|
31
|
-
def
|
32
|
-
super(
|
33
|
-
@labels.
|
34
|
-
@data.
|
35
|
-
end
|
31
|
+
def to_xml_string(str = '')
|
32
|
+
super(str) do
|
33
|
+
@labels.to_xml_string(str) unless @labels.nil?
|
34
|
+
@data.to_xml_string(str) unless @data.nil?
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
|
-
private
|
38
|
+
private
|
39
39
|
|
40
40
|
# assigns the data for this series
|
41
41
|
def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
|
data/lib/axlsx/drawing/marker.rb
CHANGED
@@ -30,9 +30,9 @@ module Axlsx
|
|
30
30
|
@col, @colOff, @row, @rowOff = 0, 0, 0, 0
|
31
31
|
options.each do |o|
|
32
32
|
self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
|
33
|
-
end
|
33
|
+
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# @see col
|
37
37
|
def col=(v) Axlsx::validate_unsigned_int v; @col = v end
|
38
38
|
# @see colOff
|
@@ -41,7 +41,7 @@ module Axlsx
|
|
41
41
|
def row=(v) Axlsx::validate_unsigned_int v; @row = v end
|
42
42
|
# @see rowOff
|
43
43
|
def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
|
44
|
-
|
44
|
+
|
45
45
|
# shortcut to set the column, row position for this marker
|
46
46
|
# @param col the column for the marker
|
47
47
|
# @param row the row of the marker
|
@@ -49,14 +49,16 @@ module Axlsx
|
|
49
49
|
self.col = col
|
50
50
|
self.row = row
|
51
51
|
end
|
52
|
-
|
53
|
-
#
|
52
|
+
|
53
|
+
# Serializes the object
|
54
|
+
# @param [String] str
|
54
55
|
# @return [String]
|
55
|
-
def
|
56
|
+
def to_xml_string(str = '')
|
56
57
|
[:col, :colOff, :row, :rowOff].each do |k|
|
57
|
-
|
58
|
-
end
|
58
|
+
str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
|
59
|
+
end
|
59
60
|
end
|
61
|
+
|
60
62
|
end
|
61
63
|
|
62
64
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# TODO: review cat, val and named access data to extend this and reduce replicated code.
|
3
|
+
module Axlsx
|
4
|
+
# The ValAxisData class manages the values for a chart value series.
|
5
|
+
class NamedAxisData < CatAxisData
|
6
|
+
|
7
|
+
# creates a new NamedAxisData Object
|
8
|
+
# @param [String] name The serialized node name for the axis data object
|
9
|
+
# @param [Array] The data to associate with the axis data object
|
10
|
+
def initialize(name, data=[])
|
11
|
+
super(data)
|
12
|
+
@name = name
|
13
|
+
end
|
14
|
+
|
15
|
+
# Serializes the object
|
16
|
+
# @param [String] str
|
17
|
+
# @return [String]
|
18
|
+
def to_xml_string(str = '')
|
19
|
+
str << '<c:' << @name.to_s << '>'
|
20
|
+
str << '<c:numRef>'
|
21
|
+
str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
|
22
|
+
str << '<c:numCache>'
|
23
|
+
str << '<c:formatCode>General</c:formatCode>'
|
24
|
+
str << '<c:ptCount val="' << size.to_s << '"/>'
|
25
|
+
each_with_index do |item, index|
|
26
|
+
v = item.is_a?(Cell) ? item.value.to_s : item
|
27
|
+
str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
|
28
|
+
end
|
29
|
+
str << '</c:numCache>'
|
30
|
+
str << '</c:numRef>'
|
31
|
+
str << '</c:' << @name.to_s << '>'
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -33,15 +33,15 @@ module Axlsx
|
|
33
33
|
# @param [Drawing] drawing
|
34
34
|
# @option options [Array] start_at the col, row to start at
|
35
35
|
# @option options [Integer] width
|
36
|
-
# @option options [Integer] height
|
36
|
+
# @option options [Integer] height
|
37
37
|
# @option options [String] image_src the file location of the image you will render
|
38
38
|
# @option options [String] name the name attribute for the rendered image
|
39
|
-
# @option options [String] descr the description of the image rendered
|
39
|
+
# @option options [String] descr the description of the image rendered
|
40
40
|
def initialize(drawing, options={})
|
41
41
|
@drawing = drawing
|
42
42
|
@width = 0
|
43
43
|
@height = 0
|
44
|
-
drawing.anchors << self
|
44
|
+
drawing.anchors << self
|
45
45
|
@from = Marker.new
|
46
46
|
options.each do |o|
|
47
47
|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
@@ -61,23 +61,24 @@ module Axlsx
|
|
61
61
|
@drawing.anchors.index(self)
|
62
62
|
end
|
63
63
|
|
64
|
-
|
65
|
-
#
|
64
|
+
|
65
|
+
# Serializes the object
|
66
|
+
# @param [String] str
|
66
67
|
# @return [String]
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
68
|
+
def to_xml_string(str = '')
|
69
|
+
str << '<xdr:oneCellAnchor>'
|
70
|
+
str << '<xdr:from>'
|
71
|
+
from.to_xml_string(str)
|
72
|
+
str << '</xdr:from>'
|
73
|
+
str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
|
74
|
+
@object.to_xml_string(str)
|
75
|
+
str << '<xdr:clientData/>'
|
76
|
+
str << '</xdr:oneCellAnchor>'
|
77
|
+
end
|
77
78
|
|
78
79
|
private
|
79
80
|
|
80
|
-
# converts the pixel width and height to EMU units and returns a hash of
|
81
|
+
# converts the pixel width and height to EMU units and returns a hash of
|
81
82
|
# !{:cx=>[Integer], :cy=>[Integer]
|
82
83
|
# @return [Hash]
|
83
84
|
def ext
|
data/lib/axlsx/drawing/pic.rb
CHANGED
@@ -28,7 +28,7 @@ module Axlsx
|
|
28
28
|
|
29
29
|
# The picture locking attributes for this picture
|
30
30
|
attr_reader :picture_locking
|
31
|
-
|
31
|
+
|
32
32
|
# Creates a new Pic(ture) object
|
33
33
|
# @param [Anchor] anchor the anchor that holds this image
|
34
34
|
# @option options [String] name
|
@@ -50,7 +50,7 @@ module Axlsx
|
|
50
50
|
end
|
51
51
|
|
52
52
|
attr_reader :hyperlink
|
53
|
-
|
53
|
+
|
54
54
|
# sets or updates a hyperlink for this image.
|
55
55
|
# @param [String] v The href value for the hyper link
|
56
56
|
# @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
|
@@ -66,7 +66,7 @@ module Axlsx
|
|
66
66
|
@hyperlink
|
67
67
|
end
|
68
68
|
|
69
|
-
def image_src=(v)
|
69
|
+
def image_src=(v)
|
70
70
|
Axlsx::validate_string(v)
|
71
71
|
RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v).delete('.')
|
72
72
|
raise ArgumentError, "File does not exist" unless File.exist?(v)
|
@@ -84,8 +84,8 @@ module Axlsx
|
|
84
84
|
# @return [String]
|
85
85
|
def file_name
|
86
86
|
File.basename(image_src) unless image_src.nil?
|
87
|
-
end
|
88
|
-
|
87
|
+
end
|
88
|
+
|
89
89
|
# returns the extension of image_src without the preceeding '.'
|
90
90
|
# @return [String]
|
91
91
|
def extname
|
@@ -93,7 +93,7 @@ module Axlsx
|
|
93
93
|
end
|
94
94
|
|
95
95
|
# The index of this image in the workbooks images collections
|
96
|
-
# @return [Index]
|
96
|
+
# @return [Index]
|
97
97
|
def index
|
98
98
|
@anchor.drawing.worksheet.workbook.images.index(self)
|
99
99
|
end
|
@@ -120,7 +120,7 @@ module Axlsx
|
|
120
120
|
def width=(v)
|
121
121
|
@anchor.width = v
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
# providing access to update the anchor's height attribute
|
125
125
|
# @param [Integer] v
|
126
126
|
# @see OneCellAnchor.width
|
@@ -144,37 +144,24 @@ module Axlsx
|
|
144
144
|
@anchor.from.row = y
|
145
145
|
end
|
146
146
|
|
147
|
-
# Serializes the
|
148
|
-
# @param [
|
147
|
+
# Serializes the object
|
148
|
+
# @param [String] str
|
149
149
|
# @return [String]
|
150
|
-
def
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
xml[:a].stretch {
|
165
|
-
xml.fillRect
|
166
|
-
}
|
167
|
-
}
|
168
|
-
xml.spPr {
|
169
|
-
xml[:a].xfrm {
|
170
|
-
xml.off :x=>0, :y=>0
|
171
|
-
xml.ext :cx=>2336800, :cy=>2161540
|
172
|
-
}
|
173
|
-
xml[:a].prstGeom(:prst=>:rect) {
|
174
|
-
xml.avLst
|
175
|
-
}
|
176
|
-
}
|
177
|
-
}
|
150
|
+
def to_xml_string(str = '')
|
151
|
+
str << '<xdr:pic>'
|
152
|
+
str << '<xdr:nvPicPr>'
|
153
|
+
str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
|
154
|
+
@hyperlink.to_xml_string(str) if @hyperlink.is_a?(Hyperlink)
|
155
|
+
str << '</xdr:cNvPr><xdr:cNvPicPr>'
|
156
|
+
picture_locking.to_xml_string(str)
|
157
|
+
str << '</xdr:cNvPicPr></xdr:nvPicPr>'
|
158
|
+
str << '<xdr:blipFill>'
|
159
|
+
str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="rId' << id.to_s << '"/>'
|
160
|
+
str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'
|
161
|
+
str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>'
|
162
|
+
str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
|
163
|
+
|
178
164
|
end
|
165
|
+
|
179
166
|
end
|
180
167
|
end
|