axlsx 2.0.1 → 3.0.0.pre
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +23 -23
- data/Rakefile +9 -11
- data/examples/auto_filter.rb +10 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
- data/examples/example.rb +102 -4
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/split.rb +16 -0
- data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +5 -5
- data/lib/axlsx/drawing/area_chart.rb +99 -0
- data/lib/axlsx/drawing/area_series.rb +110 -0
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +12 -9
- data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
- data/lib/axlsx/drawing/bar_chart.rb +143 -0
- data/lib/axlsx/drawing/bar_series.rb +9 -9
- data/lib/axlsx/drawing/bubble_chart.rb +59 -0
- data/lib/axlsx/drawing/bubble_series.rb +63 -0
- data/lib/axlsx/drawing/cat_axis.rb +5 -5
- data/lib/axlsx/drawing/chart.rb +52 -8
- data/lib/axlsx/drawing/d_lbls.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +6 -1
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +1 -3
- data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
- data/lib/axlsx/drawing/line_chart.rb +10 -10
- data/lib/axlsx/drawing/line_series.rb +32 -3
- data/lib/axlsx/drawing/marker.rb +1 -1
- data/lib/axlsx/drawing/num_data.rb +4 -4
- data/lib/axlsx/drawing/num_data_source.rb +6 -6
- data/lib/axlsx/drawing/num_val.rb +3 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
- data/lib/axlsx/drawing/pic.rb +25 -19
- data/lib/axlsx/drawing/picture_locking.rb +1 -3
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
- data/lib/axlsx/drawing/pie_series.rb +6 -6
- data/lib/axlsx/drawing/scaling.rb +6 -6
- data/lib/axlsx/drawing/scatter_chart.rb +10 -10
- data/lib/axlsx/drawing/scatter_series.rb +40 -7
- data/lib/axlsx/drawing/ser_axis.rb +2 -2
- data/lib/axlsx/drawing/series.rb +3 -3
- data/lib/axlsx/drawing/series_title.rb +2 -2
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +3 -1
- data/lib/axlsx/drawing/title.rb +22 -4
- data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
- data/lib/axlsx/drawing/val_axis.rb +1 -1
- data/lib/axlsx/drawing/view_3D.rb +2 -2
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +34 -32
- data/lib/axlsx/rels/relationship.rb +1 -1
- data/lib/axlsx/rels/relationships.rb +7 -4
- data/lib/axlsx/stylesheet/border_pr.rb +2 -2
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
- data/lib/axlsx/stylesheet/cell_style.rb +1 -3
- data/lib/axlsx/stylesheet/color.rb +1 -3
- data/lib/axlsx/stylesheet/font.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
- data/lib/axlsx/stylesheet/styles.rb +7 -7
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/constants.rb +107 -99
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +2 -1
- data/lib/axlsx/util/parser.rb +4 -4
- data/lib/axlsx/util/serialized_attributes.rb +16 -6
- data/lib/axlsx/util/simple_typed_list.rb +28 -52
- data/lib/axlsx/util/storage.rb +4 -4
- data/lib/axlsx/util/validators.rb +29 -17
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +11 -12
- data/lib/axlsx/workbook/defined_names.rb +2 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
- data/lib/axlsx/workbook/workbook.rb +36 -11
- data/lib/axlsx/workbook/workbook_view.rb +80 -0
- data/lib/axlsx/workbook/workbook_views.rb +22 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
- data/lib/axlsx/workbook/worksheet/break.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
- data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
- data/lib/axlsx/workbook/worksheet/col.rb +7 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
- data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
- data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
- data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
- data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
- data/lib/axlsx/workbook/worksheet/row.rb +40 -51
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/table.rb +6 -6
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
- data/lib/axlsx.rb +34 -15
- data/test/drawing/tc_area_chart.rb +39 -0
- data/test/drawing/tc_area_series.rb +71 -0
- data/test/drawing/tc_axis.rb +27 -0
- data/test/drawing/tc_bar_chart.rb +71 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_chart.rb +23 -10
- data/test/drawing/tc_data_source.rb +6 -0
- data/test/drawing/tc_drawing.rb +2 -2
- data/test/drawing/tc_line_chart.rb +5 -5
- data/test/drawing/tc_line_series.rb +47 -6
- data/test/drawing/tc_pic.rb +11 -15
- data/test/drawing/tc_scatter_series.rb +36 -1
- data/test/drawing/tc_str_val.rb +9 -0
- data/test/drawing/tc_title.rb +5 -0
- data/test/stylesheet/tc_styles.rb +2 -2
- data/test/tc_axlsx.rb +31 -0
- data/test/tc_helper.rb +2 -0
- data/test/tc_package.rb +19 -1
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_simple_typed_list.rb +2 -3
- data/test/util/tc_validators.rb +34 -10
- data/test/workbook/tc_defined_name.rb +12 -4
- data/test/workbook/tc_shared_strings_table.rb +16 -1
- data/test/workbook/tc_workbook.rb +38 -3
- data/test/workbook/tc_workbook_view.rb +50 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
- data/test/workbook/worksheet/tc_break.rb +1 -1
- data/test/workbook/worksheet/tc_cell.rb +76 -8
- data/test/workbook/worksheet/tc_col.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
- data/test/workbook/worksheet/tc_data_bar.rb +1 -1
- data/test/workbook/worksheet/tc_data_validation.rb +11 -11
- data/test/workbook/worksheet/tc_header_footer.rb +2 -2
- data/test/workbook/worksheet/tc_icon_set.rb +1 -1
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_page_setup.rb +3 -3
- data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
- data/test/workbook/worksheet/tc_print_options.rb +1 -1
- data/test/workbook/worksheet/tc_rich_text.rb +44 -0
- data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
- data/test/workbook/worksheet/tc_row.rb +7 -2
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
- data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
- data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
- data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
- data/test/workbook/worksheet/tc_table.rb +2 -3
- data/test/workbook/worksheet/tc_worksheet.rb +99 -45
- metadata +142 -64
@@ -128,7 +128,7 @@ module Axlsx
|
|
128
128
|
# @option options [Boolean] i Indicates if the text should be italicised
|
129
129
|
# @option options [Boolean] u Indicates if the text should be underlined
|
130
130
|
# @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
|
131
|
-
# @option options [Boolean]
|
131
|
+
# @option options [Boolean] shadow Indicates if the text should be rendered with a shadow
|
132
132
|
# @option options [Integer] charset The character set to use.
|
133
133
|
# @option options [Integer] family The font family to use.
|
134
134
|
# @option options [String] font_name The name of the font to use
|
@@ -151,7 +151,7 @@ module Axlsx
|
|
151
151
|
# ws = p.workbook.add_worksheet
|
152
152
|
#
|
153
153
|
# # black text on a white background at 14pt with thin borders!
|
154
|
-
# title = ws.
|
154
|
+
# title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
|
155
155
|
#
|
156
156
|
# ws.add_row ["Least Popular Pets"]
|
157
157
|
# ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
|
@@ -168,18 +168,18 @@ module Axlsx
|
|
168
168
|
# ws = p.workbook.add_worksheet
|
169
169
|
#
|
170
170
|
# # define your styles
|
171
|
-
# title = ws.
|
171
|
+
# title = ws.styles.add_style(:bg_color => "FFFF0000",
|
172
172
|
# :fg_color=>"#FF000000",
|
173
173
|
# :border=>Axlsx::STYLE_THIN_BORDER,
|
174
174
|
# :alignment=>{:horizontal => :center})
|
175
175
|
#
|
176
|
-
# date_time = ws.
|
176
|
+
# date_time = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
|
177
177
|
# :border=>Axlsx::STYLE_THIN_BORDER)
|
178
178
|
#
|
179
|
-
# percent = ws.
|
179
|
+
# percent = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
|
180
180
|
# :border=>Axlsx::STYLE_THIN_BORDER)
|
181
181
|
#
|
182
|
-
# currency = ws.
|
182
|
+
# currency = ws.styles.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
|
183
183
|
# :border=>Axlsx::STYLE_THIN_BORDER)
|
184
184
|
#
|
185
185
|
# # build your rows
|
@@ -362,7 +362,7 @@ module Axlsx
|
|
362
362
|
# @param [String] str
|
363
363
|
# @return [String]
|
364
364
|
def to_xml_string(str = '')
|
365
|
-
str << '<styleSheet xmlns="' << XML_NS << '">'
|
365
|
+
str << ('<styleSheet xmlns="' << XML_NS << '">')
|
366
366
|
[:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
|
367
367
|
self.instance_values[key.to_s].to_xml_string(str) unless self.instance_values[key.to_s].nil?
|
368
368
|
end
|
data/lib/axlsx/util/accessors.rb
CHANGED
@@ -19,7 +19,7 @@ module Axlsx
|
|
19
19
|
# @param [Array] symbols An array of symbols representing the
|
20
20
|
# names of the attributes you will add to your class.
|
21
21
|
def string_attr_accessor(*symbols)
|
22
|
-
validated_attr_accessor(symbols,
|
22
|
+
validated_attr_accessor(symbols, :validate_string)
|
23
23
|
end
|
24
24
|
|
25
25
|
|
@@ -27,25 +27,25 @@ module Axlsx
|
|
27
27
|
# @param [Array] symbols An array of symbols representing the
|
28
28
|
# names of the attributes you will add to your class
|
29
29
|
def unsigned_int_attr_accessor(*symbols)
|
30
|
-
validated_attr_accessor(symbols,
|
30
|
+
validated_attr_accessor(symbols, :validate_unsigned_int)
|
31
31
|
end
|
32
32
|
|
33
33
|
# Creates one or more float (double?) attr_accessors
|
34
34
|
# @param [Array] symbols An array of symbols representing the
|
35
35
|
# names of the attributes you will add to your class
|
36
36
|
def float_attr_accessor(*symbols)
|
37
|
-
validated_attr_accessor(symbols,
|
37
|
+
validated_attr_accessor(symbols, :validate_float)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Creates on or more boolean validated attr_accessors
|
41
41
|
# @param [Array] symbols An array of symbols representing the
|
42
42
|
# names of the attributes you will add to your class.
|
43
43
|
def boolean_attr_accessor(*symbols)
|
44
|
-
validated_attr_accessor(symbols,
|
44
|
+
validated_attr_accessor(symbols, :validate_boolean)
|
45
45
|
end
|
46
46
|
|
47
47
|
# Template for defining validated write accessors
|
48
|
-
SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
|
48
|
+
SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end".freeze
|
49
49
|
|
50
50
|
# Creates the reader and writer access methods
|
51
51
|
# @param [Array] symbols The names of the attributes to create
|
@@ -55,7 +55,7 @@ module Axlsx
|
|
55
55
|
def validated_attr_accessor(symbols, validator)
|
56
56
|
symbols.each do |symbol|
|
57
57
|
attr_reader symbol
|
58
|
-
module_eval(SETTER % [symbol
|
58
|
+
module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/lib/axlsx/util/constants.rb
CHANGED
@@ -1,263 +1,263 @@
|
|
1
1
|
module Axlsx
|
2
2
|
|
3
3
|
# XML Encoding
|
4
|
-
ENCODING = "UTF-8"
|
4
|
+
ENCODING = "UTF-8".freeze
|
5
5
|
|
6
6
|
# spreadsheetML namespace
|
7
|
-
XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
7
|
+
XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main".freeze
|
8
8
|
|
9
9
|
# content-types namespace
|
10
|
-
XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types"
|
10
|
+
XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types".freeze
|
11
11
|
|
12
12
|
# extended-properties namespace
|
13
|
-
APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
|
13
|
+
APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties".freeze
|
14
14
|
|
15
15
|
# doc props namespace
|
16
|
-
APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
|
16
|
+
APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes".freeze
|
17
17
|
|
18
18
|
# core properties namespace
|
19
|
-
CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
|
19
|
+
CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties".freeze
|
20
20
|
|
21
21
|
# dc elements (core) namespace
|
22
|
-
CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
|
22
|
+
CORE_NS_DC = "http://purl.org/dc/elements/1.1/".freeze
|
23
23
|
|
24
24
|
# dcmit (core) namespcace
|
25
|
-
CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
|
25
|
+
CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/".freeze
|
26
26
|
|
27
27
|
# dc terms namespace
|
28
|
-
CORE_NS_DCT = "http://purl.org/dc/terms/"
|
28
|
+
CORE_NS_DCT = "http://purl.org/dc/terms/".freeze
|
29
29
|
|
30
30
|
# xml schema namespace
|
31
|
-
CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
|
31
|
+
CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance".freeze
|
32
32
|
|
33
33
|
# Digital signature namespace
|
34
|
-
DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"
|
34
|
+
DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature".freeze
|
35
35
|
|
36
36
|
# spreadsheet drawing namespace
|
37
|
-
XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
|
37
|
+
XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing".freeze
|
38
38
|
|
39
39
|
# drawing namespace
|
40
|
-
XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
40
|
+
XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main".freeze
|
41
41
|
|
42
42
|
# chart namespace
|
43
|
-
XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart"
|
43
|
+
XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart".freeze
|
44
44
|
|
45
45
|
# relationships namespace
|
46
|
-
XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
46
|
+
XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships".freeze
|
47
47
|
|
48
48
|
# relationships name space
|
49
|
-
RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
|
49
|
+
RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships".freeze
|
50
50
|
|
51
51
|
# table rels namespace
|
52
|
-
TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
|
52
|
+
TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table".freeze
|
53
53
|
|
54
54
|
# pivot table rels namespace
|
55
|
-
PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
|
55
|
+
PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable".freeze
|
56
56
|
|
57
57
|
# pivot table cache definition namespace
|
58
|
-
PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
|
58
|
+
PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition".freeze
|
59
59
|
|
60
60
|
# workbook rels namespace
|
61
|
-
WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
61
|
+
WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument".freeze
|
62
62
|
|
63
63
|
# worksheet rels namespace
|
64
|
-
WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
|
64
|
+
WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet".freeze
|
65
65
|
|
66
66
|
# app rels namespace
|
67
|
-
APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
|
67
|
+
APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties".freeze
|
68
68
|
|
69
69
|
# core rels namespace
|
70
|
-
CORE_R = "http://schemas.openxmlformats.org/
|
70
|
+
CORE_R = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties".freeze
|
71
71
|
|
72
72
|
# digital signature rels namespace
|
73
|
-
DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"
|
73
|
+
DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature".freeze
|
74
74
|
|
75
75
|
# styles rels namespace
|
76
|
-
STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
|
76
|
+
STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles".freeze
|
77
77
|
|
78
78
|
# shared strings namespace
|
79
|
-
SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
79
|
+
SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings".freeze
|
80
80
|
|
81
81
|
# drawing rels namespace
|
82
|
-
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
|
82
|
+
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing".freeze
|
83
83
|
|
84
84
|
# chart rels namespace
|
85
|
-
CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
|
85
|
+
CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart".freeze
|
86
86
|
|
87
87
|
# image rels namespace
|
88
|
-
IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
88
|
+
IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image".freeze
|
89
89
|
|
90
90
|
# hyperlink rels namespace
|
91
|
-
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
91
|
+
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink".freeze
|
92
92
|
|
93
93
|
# comment rels namespace
|
94
|
-
COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
|
94
|
+
COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments".freeze
|
95
95
|
|
96
96
|
# comment relation for nil target
|
97
|
-
COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
|
97
|
+
COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments".freeze
|
98
98
|
|
99
99
|
#vml drawing relation namespace
|
100
100
|
VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'
|
101
101
|
|
102
102
|
# VML Drawing content type
|
103
|
-
VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
|
103
|
+
VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing".freeze
|
104
104
|
|
105
105
|
# table content type
|
106
|
-
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
|
106
|
+
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml".freeze
|
107
107
|
|
108
108
|
# pivot table content type
|
109
|
-
PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
|
109
|
+
PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml".freeze
|
110
110
|
|
111
111
|
# pivot table cache definition content type
|
112
|
-
PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
|
112
|
+
PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml".freeze
|
113
113
|
|
114
114
|
# workbook content type
|
115
|
-
WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
115
|
+
WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml".freeze
|
116
116
|
|
117
117
|
# app content type
|
118
|
-
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
118
|
+
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml".freeze
|
119
119
|
|
120
120
|
# rels content type
|
121
|
-
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
121
|
+
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml".freeze
|
122
122
|
|
123
123
|
# styles content type
|
124
|
-
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
124
|
+
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml".freeze
|
125
125
|
|
126
126
|
# xml content type
|
127
|
-
XML_CT = "application/xml"
|
127
|
+
XML_CT = "application/xml".freeze
|
128
128
|
|
129
129
|
# worksheet content type
|
130
|
-
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
130
|
+
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml".freeze
|
131
131
|
|
132
132
|
# shared strings content type
|
133
|
-
SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
133
|
+
SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml".freeze
|
134
134
|
|
135
135
|
# core content type
|
136
|
-
CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
|
136
|
+
CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml".freeze
|
137
137
|
|
138
138
|
# digital signature xml content type
|
139
|
-
DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
|
139
|
+
DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml".freeze
|
140
140
|
|
141
141
|
# digital signature origin content type
|
142
|
-
DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
|
142
|
+
DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin".freeze
|
143
143
|
|
144
144
|
# digital signature certificate content type
|
145
|
-
DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
|
145
|
+
DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate".freeze
|
146
146
|
|
147
147
|
# chart content type
|
148
|
-
CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
|
148
|
+
CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml".freeze
|
149
149
|
|
150
150
|
# comments content type
|
151
|
-
COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
|
151
|
+
COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml".freeze
|
152
152
|
|
153
153
|
# jpeg content type
|
154
|
-
JPEG_CT = "image/jpeg"
|
154
|
+
JPEG_CT = "image/jpeg".freeze
|
155
155
|
|
156
156
|
# gif content type
|
157
|
-
GIF_CT = "image/gif"
|
157
|
+
GIF_CT = "image/gif".freeze
|
158
158
|
|
159
159
|
# png content type
|
160
|
-
PNG_CT = "image/png"
|
160
|
+
PNG_CT = "image/png".freeze
|
161
161
|
|
162
162
|
#drawing content type
|
163
|
-
DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
|
163
|
+
DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml".freeze
|
164
164
|
|
165
165
|
|
166
166
|
# xml content type extensions
|
167
|
-
XML_EX = "xml"
|
167
|
+
XML_EX = "xml".freeze
|
168
168
|
|
169
169
|
# jpeg extension
|
170
|
-
JPEG_EX = "jpeg"
|
170
|
+
JPEG_EX = "jpeg".freeze
|
171
171
|
|
172
172
|
# gif extension
|
173
|
-
GIF_EX = "gif"
|
173
|
+
GIF_EX = "gif".freeze
|
174
174
|
|
175
175
|
# png extension
|
176
|
-
PNG_EX = "png"
|
176
|
+
PNG_EX = "png".freeze
|
177
177
|
|
178
178
|
# rels content type extension
|
179
|
-
RELS_EX = "rels"
|
179
|
+
RELS_EX = "rels".freeze
|
180
180
|
|
181
181
|
# workbook part
|
182
|
-
WORKBOOK_PN = "xl/workbook.xml"
|
182
|
+
WORKBOOK_PN = "xl/workbook.xml".freeze
|
183
183
|
|
184
184
|
# styles part
|
185
|
-
STYLES_PN = "styles.xml"
|
185
|
+
STYLES_PN = "styles.xml".freeze
|
186
186
|
|
187
187
|
# shared_strings part
|
188
|
-
SHARED_STRINGS_PN = "sharedStrings.xml"
|
188
|
+
SHARED_STRINGS_PN = "sharedStrings.xml".freeze
|
189
189
|
|
190
190
|
# app part
|
191
|
-
APP_PN = "docProps/app.xml"
|
191
|
+
APP_PN = "docProps/app.xml".freeze
|
192
192
|
|
193
193
|
# core part
|
194
|
-
CORE_PN = "docProps/core.xml"
|
194
|
+
CORE_PN = "docProps/core.xml".freeze
|
195
195
|
|
196
196
|
# content types part
|
197
|
-
CONTENT_TYPES_PN = "[Content_Types].xml"
|
197
|
+
CONTENT_TYPES_PN = "[Content_Types].xml".freeze
|
198
198
|
|
199
199
|
# rels part
|
200
|
-
RELS_PN = "_rels/.rels"
|
200
|
+
RELS_PN = "_rels/.rels".freeze
|
201
201
|
|
202
202
|
# workbook rels part
|
203
|
-
WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
|
203
|
+
WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels".freeze
|
204
204
|
|
205
205
|
# worksheet part
|
206
|
-
WORKSHEET_PN = "worksheets/sheet%d.xml"
|
206
|
+
WORKSHEET_PN = "worksheets/sheet%d.xml".freeze
|
207
207
|
|
208
208
|
# worksheet rels part
|
209
|
-
WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
|
209
|
+
WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels".freeze
|
210
210
|
|
211
211
|
# drawing part
|
212
|
-
DRAWING_PN = "drawings/drawing%d.xml"
|
212
|
+
DRAWING_PN = "drawings/drawing%d.xml".freeze
|
213
213
|
|
214
214
|
# drawing rels part
|
215
|
-
DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
|
215
|
+
DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels".freeze
|
216
216
|
|
217
217
|
# vml drawing part
|
218
|
-
VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
|
218
|
+
VML_DRAWING_PN = "drawings/vmlDrawing%d.vml".freeze
|
219
219
|
|
220
220
|
# drawing part
|
221
|
-
TABLE_PN = "tables/table%d.xml"
|
221
|
+
TABLE_PN = "tables/table%d.xml".freeze
|
222
222
|
|
223
223
|
# pivot table parts
|
224
|
-
PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
|
224
|
+
PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml".freeze
|
225
225
|
|
226
226
|
# pivot table cache definition part name
|
227
|
-
PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
|
227
|
+
PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml".freeze
|
228
228
|
|
229
229
|
# pivot table rels parts
|
230
|
-
PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
|
230
|
+
PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels".freeze
|
231
231
|
|
232
232
|
# chart part
|
233
|
-
CHART_PN = "charts/chart%d.xml"
|
233
|
+
CHART_PN = "charts/chart%d.xml".freeze
|
234
234
|
|
235
235
|
# chart part
|
236
|
-
IMAGE_PN = "media/image%d.%s"
|
236
|
+
IMAGE_PN = "media/image%d.%s".freeze
|
237
237
|
|
238
238
|
# comment part
|
239
|
-
COMMENT_PN = "comments%d.xml"
|
239
|
+
COMMENT_PN = "comments%d.xml".freeze
|
240
240
|
|
241
241
|
# location of schema files for validation
|
242
|
-
SCHEMA_BASE = File.dirname(__FILE__)+'/../../schema/'
|
242
|
+
SCHEMA_BASE = (File.dirname(__FILE__)+'/../../schema/').freeze
|
243
243
|
|
244
244
|
# App validation schema
|
245
|
-
APP_XSD = SCHEMA_BASE + "shared-documentPropertiesExtended.xsd"
|
245
|
+
APP_XSD = (SCHEMA_BASE + "shared-documentPropertiesExtended.xsd").freeze
|
246
246
|
|
247
247
|
# core validation schema
|
248
|
-
CORE_XSD = SCHEMA_BASE + "opc-coreProperties.xsd"
|
248
|
+
CORE_XSD = (SCHEMA_BASE + "opc-coreProperties.xsd").freeze
|
249
249
|
|
250
250
|
# content types validation schema
|
251
|
-
CONTENT_TYPES_XSD = SCHEMA_BASE + "opc-contentTypes.xsd"
|
251
|
+
CONTENT_TYPES_XSD = (SCHEMA_BASE + "opc-contentTypes.xsd").freeze
|
252
252
|
|
253
253
|
# rels validation schema
|
254
|
-
RELS_XSD = SCHEMA_BASE + "opc-relationships.xsd"
|
254
|
+
RELS_XSD = (SCHEMA_BASE + "opc-relationships.xsd").freeze
|
255
255
|
|
256
256
|
# spreadsheetML validation schema
|
257
|
-
SML_XSD = SCHEMA_BASE + "sml.xsd"
|
257
|
+
SML_XSD = (SCHEMA_BASE + "sml.xsd").freeze
|
258
258
|
|
259
259
|
# drawing validation schema
|
260
|
-
DRAWING_XSD = SCHEMA_BASE + "dml-spreadsheetDrawing.xsd"
|
260
|
+
DRAWING_XSD = (SCHEMA_BASE + "dml-spreadsheetDrawing.xsd").freeze
|
261
261
|
|
262
262
|
# number format id for pecentage formatting using the default formatting id.
|
263
263
|
NUM_FMT_PERCENT = 9
|
@@ -275,37 +275,37 @@ module Axlsx
|
|
275
275
|
STYLE_DATE = 2
|
276
276
|
|
277
277
|
# error messages RestrictionValidor
|
278
|
-
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
278
|
+
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s.".freeze
|
279
279
|
|
280
280
|
# error message DataTypeValidator
|
281
|
-
ERR_TYPE = "Invalid Data %s for %s. must be %s."
|
281
|
+
ERR_TYPE = "Invalid Data %s for %s. must be %s.".freeze
|
282
282
|
|
283
283
|
# error message for RegexValidator
|
284
|
-
ERR_REGEX = "Invalid Data. %s does not match %s."
|
284
|
+
ERR_REGEX = "Invalid Data. %s does not match %s.".freeze
|
285
285
|
|
286
286
|
# error message for RangeValidator
|
287
|
-
ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
|
287
|
+
ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s".freeze
|
288
288
|
|
289
289
|
# error message for sheets that use a name which is longer than 31 bytes
|
290
|
-
ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
|
290
|
+
ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less".freeze
|
291
291
|
|
292
292
|
# error message for sheets that use a name which include invalid characters
|
293
|
-
ERR_SHEET_NAME_CHARACTER_FORBIDDEN = "Your worksheet name '%s' contains a character which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
|
293
|
+
ERR_SHEET_NAME_CHARACTER_FORBIDDEN = "Your worksheet name '%s' contains a character which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet.".freeze
|
294
294
|
|
295
295
|
# error message for duplicate sheet names
|
296
|
-
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
|
296
|
+
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name".freeze
|
297
297
|
|
298
298
|
# error message when user does not provide color and or style options for border in Style#add_sytle
|
299
|
-
ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
|
299
|
+
ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s".freeze
|
300
300
|
|
301
301
|
# error message for invalid border id reference
|
302
|
-
ERR_INVALID_BORDER_ID = "The border id you specified (%s) does not exist. Please add a border with Style#add_style before referencing its index."
|
302
|
+
ERR_INVALID_BORDER_ID = "The border id you specified (%s) does not exist. Please add a border with Style#add_style before referencing its index.".freeze
|
303
303
|
|
304
304
|
# error message for invalid angles
|
305
|
-
ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"
|
305
|
+
ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s".freeze
|
306
306
|
|
307
307
|
# error message for non 'integerish' value
|
308
|
-
ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
|
308
|
+
ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s".freeze
|
309
309
|
|
310
310
|
# Regex to match forbidden control characters
|
311
311
|
# The following will be automatically stripped from worksheets.
|
@@ -383,10 +383,18 @@ module Axlsx
|
|
383
383
|
# x0D Carriage Return (Cr)
|
384
384
|
# x09 Character Tabulation
|
385
385
|
# @see http://www.codetable.net/asciikeycodes
|
386
|
-
pattern = "
|
387
|
-
pattern= pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
|
386
|
+
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
|
387
|
+
pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
|
388
388
|
|
389
389
|
# The regular expression used to remove control characters from worksheets
|
390
|
-
|
390
|
+
CONTROL_CHARS = pattern.freeze
|
391
391
|
|
392
|
+
# ISO 8601 date recognition
|
393
|
+
ISO_8601_REGEX = /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/.freeze
|
394
|
+
|
395
|
+
# FLOAT recognition
|
396
|
+
FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/.freeze
|
397
|
+
|
398
|
+
# Numeric recognition
|
399
|
+
NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
|
392
400
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# This module defines some utils related with mime type detection
|
3
|
+
module MimeTypeUtils
|
4
|
+
# Detect a file mime type
|
5
|
+
# @param [String] v File path
|
6
|
+
# @return [String] File mime type
|
7
|
+
def self.get_mime_type(v)
|
8
|
+
MimeMagic.by_magic(File.open(v)).to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -8,7 +8,8 @@ module Axlsx
|
|
8
8
|
# @param [Hash] options Options to parse.
|
9
9
|
def parse_options(options={})
|
10
10
|
options.each do |key, value|
|
11
|
-
|
11
|
+
key = :"#{key}="
|
12
|
+
self.send(key, value) if !value.nil? && self.respond_to?(key)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
data/lib/axlsx/util/parser.rb
CHANGED
@@ -9,28 +9,28 @@ module Axlsx
|
|
9
9
|
|
10
10
|
# parse and assign string attribute
|
11
11
|
def parse_string attr_name, xpath
|
12
|
-
send("#{attr_name
|
12
|
+
send("#{attr_name}=", parse_value(xpath))
|
13
13
|
end
|
14
14
|
|
15
15
|
# parse convert and assign node text to symbol
|
16
16
|
def parse_symbol attr_name, xpath
|
17
17
|
v = parse_value xpath
|
18
18
|
v = v.to_sym unless v.nil?
|
19
|
-
send("#{attr_name
|
19
|
+
send("#{attr_name}=", v)
|
20
20
|
end
|
21
21
|
|
22
22
|
# parse, convert and assign note text to integer
|
23
23
|
def parse_integer attr_name, xpath
|
24
24
|
v = parse_value xpath
|
25
25
|
v = v.to_i if v.respond_to?(:to_i)
|
26
|
-
send("#{attr_name
|
26
|
+
send("#{attr_name}=", v)
|
27
27
|
end
|
28
28
|
|
29
29
|
# parse, convert and assign node text to float
|
30
30
|
def parse_float attr_name, xpath
|
31
31
|
v = parse_value xpath
|
32
32
|
v = v.to_f if v.respond_to?(:to_f)
|
33
|
-
send("#{attr_name
|
33
|
+
send("#{attr_name}=", v)
|
34
34
|
end
|
35
35
|
|
36
36
|
# return node text based on xpath
|
@@ -18,9 +18,7 @@ module Axlsx
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# a reader for those attributes
|
21
|
-
|
22
|
-
@xml_attributes
|
23
|
-
end
|
21
|
+
attr_reader :xml_attributes
|
24
22
|
|
25
23
|
# This helper registers the attributes that will be formatted as elements.
|
26
24
|
def serializable_element_attributes(*symbols)
|
@@ -28,8 +26,20 @@ module Axlsx
|
|
28
26
|
end
|
29
27
|
|
30
28
|
# attr reader for element attributes
|
31
|
-
|
32
|
-
|
29
|
+
attr_reader :xml_element_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
# creates a XML tag with serialized attributes
|
33
|
+
# @see SerializedAttributes#serialized_attributes
|
34
|
+
def serialized_tag(tagname, str, additional_attributes = {}, &block)
|
35
|
+
str << "<#{tagname} "
|
36
|
+
serialized_attributes(str, additional_attributes)
|
37
|
+
if block_given?
|
38
|
+
str << '>'
|
39
|
+
yield
|
40
|
+
str << "</#{tagname}>"
|
41
|
+
else
|
42
|
+
str << '/>'
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
@@ -42,7 +52,7 @@ module Axlsx
|
|
42
52
|
def serialized_attributes(str = '', additional_attributes = {})
|
43
53
|
attributes = declared_attributes.merge! additional_attributes
|
44
54
|
attributes.each do |key, value|
|
45
|
-
str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(value, false)}\" "
|
55
|
+
str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" "
|
46
56
|
end
|
47
57
|
str
|
48
58
|
end
|