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
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Axlsx
|
3
3
|
# The GradientStop object represents a color point in a gradient.
|
4
|
-
# @see Open Office XML Part 1 §18.8.24
|
4
|
+
# @see Open Office XML Part 1 §18.8.24
|
5
5
|
class GradientStop
|
6
6
|
# The color for this gradient stop
|
7
7
|
# @return [Color]
|
@@ -23,11 +23,15 @@ module Axlsx
|
|
23
23
|
# @see color
|
24
24
|
def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color=v end
|
25
25
|
# @see position
|
26
|
-
def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
|
26
|
+
def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
|
27
27
|
|
28
|
-
# Serializes the
|
29
|
-
# @param [
|
28
|
+
# Serializes the object
|
29
|
+
# @param [String] str
|
30
30
|
# @return [String]
|
31
|
-
def
|
31
|
+
def to_xml_string(str = '')
|
32
|
+
str << '<stop position="' << position.to_s << '">'
|
33
|
+
self.color.to_xml_string(str)
|
34
|
+
str << '</stop>'
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Axlsx
|
3
|
-
# A NumFmt object defines an identifier and formatting code for data in cells.
|
3
|
+
# A NumFmt object defines an identifier and formatting code for data in cells.
|
4
4
|
# @note The recommended way to manage styles is Styles#add_style
|
5
5
|
class NumFmt
|
6
6
|
# @return [Integer] An unsinged integer referencing a standard or custom number format.
|
7
7
|
# @note
|
8
|
-
# These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
|
8
|
+
# These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
|
9
9
|
# 1 0
|
10
10
|
# 2 0.00
|
11
11
|
# 3 #,##0
|
@@ -40,7 +40,7 @@ module Axlsx
|
|
40
40
|
# @see Axlsx
|
41
41
|
attr_reader :numFmtId
|
42
42
|
|
43
|
-
# @return [String] The formatting to use for this number format.
|
43
|
+
# @return [String] The formatting to use for this number format.
|
44
44
|
# @see http://support.microsoft.com/kb/264372
|
45
45
|
attr_reader :formatCode
|
46
46
|
def initialize(options={})
|
@@ -56,9 +56,15 @@ module Axlsx
|
|
56
56
|
# @see formatCode
|
57
57
|
def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
|
58
58
|
|
59
|
-
|
60
|
-
#
|
61
|
-
|
59
|
+
|
60
|
+
# Serializes the object
|
61
|
+
# @param [String] str
|
62
|
+
# @return [String]
|
63
|
+
def to_xml_string(str = '')
|
64
|
+
str << '<numFmt '
|
65
|
+
str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
66
|
+
str << '/>'
|
67
|
+
end
|
62
68
|
|
63
69
|
end
|
64
70
|
end
|
@@ -7,15 +7,15 @@ module Axlsx
|
|
7
7
|
|
8
8
|
# The color to use for the the background in solid fills.
|
9
9
|
# @return [Color]
|
10
|
-
attr_reader :fgColor
|
10
|
+
attr_reader :fgColor
|
11
11
|
|
12
12
|
# The color to use for the background of the fill when the type is not solid.
|
13
13
|
# @return [Color]
|
14
14
|
attr_reader :bgColor
|
15
15
|
|
16
16
|
# The pattern type to use
|
17
|
-
# @note
|
18
|
-
# patternType must be one of
|
17
|
+
# @note
|
18
|
+
# patternType must be one of
|
19
19
|
# :none
|
20
20
|
# :solid
|
21
21
|
# :mediumGray
|
@@ -53,15 +53,30 @@ module Axlsx
|
|
53
53
|
# @see bgColor
|
54
54
|
def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
|
55
55
|
# @see patternType
|
56
|
-
def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
|
56
|
+
def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
|
57
57
|
|
58
|
-
# Serializes the
|
59
|
-
# @param [
|
58
|
+
# Serializes the object
|
59
|
+
# @param [String] str
|
60
60
|
# @return [String]
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
def to_xml_string(str = '')
|
62
|
+
str << '<patternFill patternType="' << patternType.to_s << '">'
|
63
|
+
if fgColor.is_a?(Color)
|
64
|
+
str << "<fgColor "
|
65
|
+
fgColor.instance_values.each do |key, value|
|
66
|
+
str << key.to_s << '="' << value.to_s << '" '
|
67
|
+
end
|
68
|
+
str << "/>"
|
69
|
+
end
|
70
|
+
|
71
|
+
if bgColor.is_a?(Color)
|
72
|
+
str << "<bgColor "
|
73
|
+
bgColor.instance_values.each do |key, value|
|
74
|
+
str << key.to_s << '="' << value.to_s << '" '
|
75
|
+
end
|
76
|
+
str << "/>"
|
77
|
+
end
|
78
|
+
str << '</patternFill>'
|
65
79
|
end
|
80
|
+
|
66
81
|
end
|
67
82
|
end
|
@@ -120,7 +120,7 @@ module Axlsx
|
|
120
120
|
end
|
121
121
|
|
122
122
|
# Drastically simplifies style creation and management.
|
123
|
-
# @return [Integer]
|
123
|
+
# @return [Integer]
|
124
124
|
# @option options [String] fg_color The text color
|
125
125
|
# @option options [Integer] sz The text size
|
126
126
|
# @option options [Boolean] b Indicates if the text should be bold
|
@@ -133,13 +133,13 @@ module Axlsx
|
|
133
133
|
# @option options [String] font_name The name of the font to use
|
134
134
|
# @option options [Integer] num_fmt The number format to apply
|
135
135
|
# @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
|
136
|
-
# @option options [Integer] border The border style to use.
|
136
|
+
# @option options [Integer] border The border style to use.
|
137
137
|
# @option options [String] bg_color The background color to apply to the cell
|
138
138
|
# @option options [Boolean] hidden Indicates if the cell should be hidden
|
139
139
|
# @option options [Boolean] locked Indicates if the cell should be locked
|
140
140
|
# @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
|
141
141
|
# @see CellAlignment
|
142
|
-
#
|
142
|
+
#
|
143
143
|
# @example You Got Style
|
144
144
|
# require "rubygems" # if that is your preferred way to manage gems!
|
145
145
|
# require "axlsx"
|
@@ -148,7 +148,7 @@ module Axlsx
|
|
148
148
|
# ws = p.workbook.add_worksheet
|
149
149
|
#
|
150
150
|
# # black text on a white background at 14pt with thin borders!
|
151
|
-
# title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>
|
151
|
+
# title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
|
152
152
|
#
|
153
153
|
# ws.add_row :values => ["Least Popular Pets"]
|
154
154
|
# ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
|
@@ -165,15 +165,15 @@ module Axlsx
|
|
165
165
|
# ws = p.workbook.add_worksheet
|
166
166
|
#
|
167
167
|
# # define your styles
|
168
|
-
# title = ws.style.add_style(:bg_color => "FFFF0000",
|
168
|
+
# title = ws.style.add_style(:bg_color => "FFFF0000",
|
169
169
|
# :fg_color=>"#FF000000",
|
170
|
-
# :border=>Axlsx::STYLE_THIN_BORDER,
|
170
|
+
# :border=>Axlsx::STYLE_THIN_BORDER,
|
171
171
|
# :alignment=>{:horizontal => :center})
|
172
172
|
#
|
173
173
|
# date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
|
174
174
|
# :border=>Axlsx::STYLE_THIN_BORDER)
|
175
175
|
#
|
176
|
-
# percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
|
176
|
+
# percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
|
177
177
|
# :border=>Axlsx::STYLE_THIN_BORDER)
|
178
178
|
#
|
179
179
|
# currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
|
@@ -190,7 +190,7 @@ module Axlsx
|
|
190
190
|
# f = File.open('example_you_got_style.xlsx', 'w')
|
191
191
|
# p.serialize(f)
|
192
192
|
def add_style(options={})
|
193
|
-
|
193
|
+
|
194
194
|
numFmtId = if options[:format_code]
|
195
195
|
n = @numFmts.map{ |f| f.numFmtId }.max + 1
|
196
196
|
numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code])
|
@@ -198,19 +198,29 @@ module Axlsx
|
|
198
198
|
else
|
199
199
|
options[:num_fmt] || 0
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
borderId = options[:border] || 0
|
203
203
|
|
204
|
+
if borderId.is_a?(Hash)
|
205
|
+
raise ArgumentError, "border hash definitions must include both style and color" unless borderId.keys.include?(:style) && borderId.keys.include?(:color)
|
206
|
+
|
207
|
+
s = borderId.delete :style
|
208
|
+
c = borderId.delete :color
|
209
|
+
border = Border.new
|
210
|
+
[:left, :right, :top, :bottom].each {|pr| border.prs << BorderPr.new(:name => pr, :style=>s, :color => Color.new(:rgb => c))}
|
211
|
+
borderId = self.borders << border
|
212
|
+
end
|
213
|
+
|
204
214
|
raise ArgumentError, "Invalid borderId" unless borderId < borders.size
|
205
|
-
|
215
|
+
|
206
216
|
fill = if options[:bg_color]
|
207
217
|
color = Color.new(:rgb=>options[:bg_color])
|
208
218
|
pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
|
209
|
-
fills << Fill.new(pattern)
|
219
|
+
fills << Fill.new(pattern)
|
210
220
|
else
|
211
221
|
0
|
212
222
|
end
|
213
|
-
|
223
|
+
|
214
224
|
fontId = if (options.values_at(:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name).length)
|
215
225
|
font = Font.new()
|
216
226
|
[:b, :i, :u, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
|
@@ -218,42 +228,41 @@ module Axlsx
|
|
218
228
|
font.name = options[:font_name] unless options[:font_name].nil?
|
219
229
|
fonts << font
|
220
230
|
else
|
221
|
-
0
|
231
|
+
0
|
222
232
|
end
|
223
|
-
|
233
|
+
|
224
234
|
applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0
|
225
|
-
|
235
|
+
|
226
236
|
xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
|
227
237
|
|
228
238
|
xf.applyNumberFormat = true if xf.numFmtId > 0
|
229
239
|
xf.applyBorder = true if borderId > 0
|
230
|
-
|
240
|
+
|
231
241
|
if options[:alignment]
|
232
242
|
xf.alignment = CellAlignment.new(options[:alignment])
|
243
|
+
xf.applyAlignment = true
|
233
244
|
end
|
234
|
-
|
245
|
+
|
235
246
|
if applyProtection
|
236
247
|
xf.protection = CellProtection.new(options)
|
237
248
|
end
|
238
|
-
|
249
|
+
|
239
250
|
cellXfs << xf
|
240
251
|
end
|
241
|
-
|
242
|
-
# Serializes the
|
252
|
+
|
253
|
+
# Serializes the object
|
254
|
+
# @param [String] str
|
243
255
|
# @return [String]
|
244
|
-
def
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
self.instance_values[key.to_s].to_xml(xml) unless self.instance_values[key.to_s].nil?
|
249
|
-
end
|
250
|
-
}
|
256
|
+
def to_xml_string(str = '')
|
257
|
+
str << '<styleSheet xmlns="' << XML_NS << '">'
|
258
|
+
[:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
|
259
|
+
self.instance_values[key.to_s].to_xml_string(str) unless self.instance_values[key.to_s].nil?
|
251
260
|
end
|
252
|
-
|
261
|
+
str << '</styleSheet>'
|
253
262
|
end
|
254
263
|
|
255
264
|
private
|
256
|
-
# Creates the default set of styles the exel requires to be valid as well as setting up the
|
265
|
+
# Creates the default set of styles the exel requires to be valid as well as setting up the
|
257
266
|
# Axlsx::STYLE_THIN_BORDER
|
258
267
|
def load_default_styles
|
259
268
|
@numFmts = SimpleTypedList.new NumFmt, 'numFmts'
|
@@ -274,8 +283,8 @@ module Axlsx
|
|
274
283
|
@borders = SimpleTypedList.new Border, 'borders'
|
275
284
|
@borders << Border.new
|
276
285
|
black_border = Border.new
|
277
|
-
[:left, :right, :top, :bottom].each do |item|
|
278
|
-
black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
|
286
|
+
[:left, :right, :top, :bottom].each do |item|
|
287
|
+
black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
|
279
288
|
end
|
280
289
|
@borders << black_border
|
281
290
|
@borders.lock
|
@@ -300,4 +309,4 @@ module Axlsx
|
|
300
309
|
end
|
301
310
|
end
|
302
311
|
end
|
303
|
-
|
312
|
+
|
@@ -36,13 +36,18 @@ module Axlsx
|
|
36
36
|
# @see table
|
37
37
|
def table=(v) Axlsx::validate_boolean v; @table=v end
|
38
38
|
|
39
|
-
# Serializes the
|
40
|
-
# @param [
|
39
|
+
# Serializes the object
|
40
|
+
# @param [String] str
|
41
41
|
# @return [String]
|
42
|
-
def
|
42
|
+
def to_xml_string(str = '')
|
43
43
|
attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
|
44
44
|
attr[:count] = self.size
|
45
|
-
|
45
|
+
str << '<tableStyle '
|
46
|
+
str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
47
|
+
str << '>'
|
48
|
+
each { |table_style_el| table_style_el.to_xml_string(str) }
|
49
|
+
str << '</tableStyle>'
|
46
50
|
end
|
51
|
+
|
47
52
|
end
|
48
53
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Axlsx
|
3
|
-
# an element of style that belongs to a table style.
|
4
|
-
# @note tables and table styles are not supported in this version. This class exists in preparation for that support.
|
3
|
+
# an element of style that belongs to a table style.
|
4
|
+
# @note tables and table styles are not supported in this version. This class exists in preparation for that support.
|
5
5
|
class TableStyleElement
|
6
6
|
# The type of style element. The following type are allowed
|
7
7
|
# :wholeTable
|
@@ -39,7 +39,7 @@ module Axlsx
|
|
39
39
|
# @return [Integer]
|
40
40
|
attr_reader :size
|
41
41
|
|
42
|
-
# The dxfId this style element points to
|
42
|
+
# The dxfId this style element points to
|
43
43
|
# @return [Integer]
|
44
44
|
attr_reader :dxfId
|
45
45
|
|
@@ -62,11 +62,14 @@ module Axlsx
|
|
62
62
|
# @see dxfId
|
63
63
|
def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
|
64
64
|
|
65
|
-
# Serializes the
|
66
|
-
# @param [
|
65
|
+
# Serializes the object
|
66
|
+
# @param [String] str
|
67
67
|
# @return [String]
|
68
|
-
def
|
69
|
-
|
68
|
+
def to_xml_string(str = '')
|
69
|
+
str << '<tableStyleElement '
|
70
|
+
str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
71
|
+
str << '/>'
|
70
72
|
end
|
73
|
+
|
71
74
|
end
|
72
75
|
end
|
@@ -11,13 +11,13 @@ module Axlsx
|
|
11
11
|
# The default pivot table style. The default value is 'PivotStyleLight6'
|
12
12
|
# @return [String]
|
13
13
|
attr_reader :defaultPivotStyle
|
14
|
-
|
14
|
+
|
15
15
|
# Creates a new TableStyles object that is a container for TableStyle objects
|
16
16
|
# @option options [String] defaultTableStyle
|
17
17
|
# @option options [String] defaultPivotStyle
|
18
18
|
def initialize(options={})
|
19
19
|
@defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
|
20
|
-
@defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
|
20
|
+
@defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
|
21
21
|
super TableStyle
|
22
22
|
end
|
23
23
|
# @see defaultTableStyle
|
@@ -25,16 +25,19 @@ module Axlsx
|
|
25
25
|
# @see defaultPivotStyle
|
26
26
|
def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
|
27
27
|
|
28
|
-
# Serializes the
|
29
|
-
# @param [
|
28
|
+
# Serializes the object
|
29
|
+
# @param [String] str
|
30
30
|
# @return [String]
|
31
|
-
def
|
31
|
+
def to_xml_string(str = '')
|
32
32
|
attr = self.instance_values.reject {|k, v| ![:defaultTableStyle, :defaultPivotStyle].include?(k.to_sym) }
|
33
33
|
attr[:count] = self.size
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
str << '<tableStyles '
|
35
|
+
str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
36
|
+
str << '>'
|
37
|
+
each { |table_style| table_style.to_xml_string(str) }
|
38
|
+
str << '</tableStyles>'
|
37
39
|
end
|
40
|
+
|
38
41
|
end
|
39
42
|
|
40
43
|
end
|
data/lib/axlsx/stylesheet/xf.rb
CHANGED
@@ -22,7 +22,7 @@ module Axlsx
|
|
22
22
|
# index (0 based) of the font to be used in this style
|
23
23
|
# @return [Integer]
|
24
24
|
attr_reader :fontId
|
25
|
-
|
25
|
+
|
26
26
|
# index (0 based) of the fill to be used in this style
|
27
27
|
# @return [Integer]
|
28
28
|
attr_reader :fillId
|
@@ -50,7 +50,7 @@ module Axlsx
|
|
50
50
|
# indicates if the fontId should be applied
|
51
51
|
# @return [Boolean]
|
52
52
|
attr_reader :applyFont
|
53
|
-
|
53
|
+
|
54
54
|
# indicates if the fillId should be applied
|
55
55
|
# @return [Boolean]
|
56
56
|
attr_reader :applyFill
|
@@ -75,7 +75,7 @@ module Axlsx
|
|
75
75
|
# @option options [Integer] xfId
|
76
76
|
# @option options [Boolean] quotePrefix
|
77
77
|
# @option options [Boolean] pivotButton
|
78
|
-
# @option options [Boolean] applyNumberFormat
|
78
|
+
# @option options [Boolean] applyNumberFormat
|
79
79
|
# @option options [Boolean] applyFont
|
80
80
|
# @option options [Boolean] applyFill
|
81
81
|
# @option options [Boolean] applyBorder
|
@@ -87,8 +87,8 @@ module Axlsx
|
|
87
87
|
options.each do |o|
|
88
88
|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
89
89
|
end
|
90
|
-
end
|
91
|
-
|
90
|
+
end
|
91
|
+
|
92
92
|
# @see Xf#alignment
|
93
93
|
def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
|
94
94
|
|
@@ -96,44 +96,48 @@ module Axlsx
|
|
96
96
|
def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
|
97
97
|
|
98
98
|
# @see numFmtId
|
99
|
-
def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
|
99
|
+
def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
|
100
100
|
|
101
101
|
# @see fontId
|
102
|
-
def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
|
102
|
+
def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
|
103
103
|
# @see fillId
|
104
|
-
def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
|
104
|
+
def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
|
105
105
|
# @see borderId
|
106
|
-
def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
|
106
|
+
def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
|
107
107
|
# @see xfId
|
108
|
-
def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
|
108
|
+
def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
|
109
109
|
# @see quotePrefix
|
110
|
-
def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
|
110
|
+
def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
|
111
111
|
# @see pivotButton
|
112
|
-
def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
|
112
|
+
def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
|
113
113
|
# @see applyNumberFormat
|
114
|
-
def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
|
114
|
+
def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
|
115
115
|
# @see applyFont
|
116
|
-
def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
|
116
|
+
def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
|
117
117
|
# @see applyFill
|
118
|
-
def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
|
118
|
+
def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
|
119
119
|
|
120
120
|
# @see applyBorder
|
121
|
-
def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
|
121
|
+
def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
|
122
122
|
|
123
123
|
# @see applyAlignment
|
124
|
-
def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
|
124
|
+
def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
|
125
125
|
|
126
126
|
# @see applyProtection
|
127
|
-
def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
|
127
|
+
def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
|
128
128
|
|
129
|
-
# Serializes the
|
130
|
-
# @param [
|
129
|
+
# Serializes the object
|
130
|
+
# @param [String] str
|
131
131
|
# @return [String]
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
def to_xml_string(str = '')
|
133
|
+
str << '<xf '
|
134
|
+
h = instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}
|
135
|
+
str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
|
136
|
+
str << '>'
|
137
|
+
alignment.to_xml_string(str) if self.alignment
|
138
|
+
protection.to_xml_string(str) if self.protection
|
139
|
+
str << '</xf>'
|
137
140
|
end
|
141
|
+
|
138
142
|
end
|
139
143
|
end
|