caxlsx 3.4.1 → 4.0.0
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 +16 -1
- data/README.md +9 -11
- data/Rakefile +7 -5
- data/lib/axlsx/content_type/abstract_content_type.rb +9 -4
- data/lib/axlsx/content_type/content_type.rb +7 -5
- data/lib/axlsx/content_type/default.rb +4 -2
- data/lib/axlsx/content_type/override.rb +4 -2
- data/lib/axlsx/doc_props/app.rb +26 -24
- data/lib/axlsx/doc_props/core.rb +8 -6
- data/lib/axlsx/drawing/area_chart.rb +10 -8
- data/lib/axlsx/drawing/area_series.rb +12 -10
- data/lib/axlsx/drawing/ax_data_source.rb +2 -0
- data/lib/axlsx/drawing/axes.rb +6 -4
- data/lib/axlsx/drawing/axis.rb +21 -19
- data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
- data/lib/axlsx/drawing/bar_chart.rb +13 -11
- data/lib/axlsx/drawing/bar_series.rb +8 -6
- data/lib/axlsx/drawing/bubble_chart.rb +6 -4
- data/lib/axlsx/drawing/bubble_series.rb +8 -6
- data/lib/axlsx/drawing/cat_axis.rb +12 -10
- data/lib/axlsx/drawing/chart.rb +20 -18
- data/lib/axlsx/drawing/d_lbls.rb +7 -5
- data/lib/axlsx/drawing/drawing.rb +58 -56
- data/lib/axlsx/drawing/graphic_frame.rb +6 -4
- data/lib/axlsx/drawing/hyperlink.rb +10 -8
- data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
- data/lib/axlsx/drawing/line_chart.rb +10 -8
- data/lib/axlsx/drawing/line_series.rb +12 -10
- data/lib/axlsx/drawing/marker.rb +9 -7
- data/lib/axlsx/drawing/num_data.rb +9 -7
- data/lib/axlsx/drawing/num_data_source.rb +9 -7
- data/lib/axlsx/drawing/num_val.rb +7 -5
- data/lib/axlsx/drawing/one_cell_anchor.rb +7 -5
- data/lib/axlsx/drawing/pic.rb +16 -14
- data/lib/axlsx/drawing/picture_locking.rb +3 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -3
- data/lib/axlsx/drawing/pie_series.rb +8 -6
- data/lib/axlsx/drawing/scaling.rb +8 -6
- data/lib/axlsx/drawing/scatter_chart.rb +7 -5
- data/lib/axlsx/drawing/scatter_series.rb +14 -12
- data/lib/axlsx/drawing/ser_axis.rb +7 -5
- data/lib/axlsx/drawing/series.rb +6 -4
- data/lib/axlsx/drawing/series_title.rb +6 -4
- data/lib/axlsx/drawing/str_data.rb +7 -5
- data/lib/axlsx/drawing/str_val.rb +6 -4
- data/lib/axlsx/drawing/title.rb +13 -14
- data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
- data/lib/axlsx/drawing/val_axis.rb +4 -2
- data/lib/axlsx/drawing/view_3D.rb +9 -7
- data/lib/axlsx/drawing/vml_drawing.rb +18 -16
- data/lib/axlsx/drawing/vml_shape.rb +24 -22
- data/lib/axlsx/package.rb +69 -66
- data/lib/axlsx/rels/relationship.rb +10 -5
- data/lib/axlsx/rels/relationships.rb +5 -3
- data/lib/axlsx/stylesheet/border.rb +6 -4
- data/lib/axlsx/stylesheet/border_pr.rb +5 -3
- data/lib/axlsx/stylesheet/cell_alignment.rb +12 -10
- data/lib/axlsx/stylesheet/cell_protection.rb +5 -3
- data/lib/axlsx/stylesheet/cell_style.rb +10 -8
- data/lib/axlsx/stylesheet/color.rb +9 -7
- data/lib/axlsx/stylesheet/dxf.rb +5 -3
- data/lib/axlsx/stylesheet/fill.rb +3 -1
- data/lib/axlsx/stylesheet/font.rb +18 -16
- data/lib/axlsx/stylesheet/gradient_fill.rb +6 -4
- data/lib/axlsx/stylesheet/gradient_stop.rb +6 -4
- data/lib/axlsx/stylesheet/num_fmt.rb +8 -10
- data/lib/axlsx/stylesheet/pattern_fill.rb +5 -3
- data/lib/axlsx/stylesheet/styles.rb +69 -71
- data/lib/axlsx/stylesheet/table_style.rb +7 -5
- data/lib/axlsx/stylesheet/table_style_element.rb +6 -4
- data/lib/axlsx/stylesheet/table_styles.rb +6 -4
- data/lib/axlsx/stylesheet/xf.rb +18 -16
- data/lib/axlsx/util/accessors.rb +4 -2
- data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
- data/lib/axlsx/util/constants.rb +117 -104
- data/lib/axlsx/util/mime_type_utils.rb +3 -5
- data/lib/axlsx/util/options_parser.rb +3 -1
- data/lib/axlsx/util/serialized_attributes.rb +42 -17
- data/lib/axlsx/util/simple_typed_list.rb +47 -47
- data/lib/axlsx/util/storage.rb +11 -10
- data/lib/axlsx/util/validators.rb +101 -41
- data/lib/axlsx/util/zip_command.rb +10 -10
- data/lib/axlsx/version.rb +3 -1
- data/lib/axlsx/workbook/defined_name.rb +6 -4
- data/lib/axlsx/workbook/defined_names.rb +3 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
- data/lib/axlsx/workbook/workbook.rb +78 -76
- data/lib/axlsx/workbook/workbook_view.rb +3 -1
- data/lib/axlsx/workbook/workbook_views.rb +3 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +7 -3
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
- data/lib/axlsx/workbook/worksheet/break.rb +3 -1
- data/lib/axlsx/workbook/worksheet/cell.rb +53 -54
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
- data/lib/axlsx/workbook/worksheet/cfvo.rb +5 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
- data/lib/axlsx/workbook/worksheet/col.rb +5 -3
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +5 -3
- data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
- data/lib/axlsx/workbook/worksheet/cols.rb +3 -1
- data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -4
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +18 -16
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
- data/lib/axlsx/workbook/worksheet/data_validation.rb +30 -28
- data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -1
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
- data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
- data/lib/axlsx/workbook/worksheet/icon_set.rb +23 -6
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +5 -5
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/page_margins.rb +15 -10
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/page_setup.rb +11 -9
- data/lib/axlsx/workbook/worksheet/pane.rb +11 -9
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +2 -0
- data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
- data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -3
- data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +16 -14
- data/lib/axlsx/workbook/worksheet/row.rb +6 -7
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +6 -4
- data/lib/axlsx/workbook/worksheet/selection.rb +9 -7
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +10 -8
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +15 -13
- data/lib/axlsx/workbook/worksheet/table.rb +9 -7
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
- data/lib/axlsx/workbook/worksheet/tables.rb +3 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -37
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +6 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -2
- data/lib/axlsx.rb +56 -42
- data/lib/caxlsx.rb +3 -1
- metadata +49 -43
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Axlsx
|
|
4
|
+
# The BufferedZipOutputStream buffers the output in order to avoid appending many small strings directly to the
|
|
5
|
+
# the `Zip::OutputStream`.
|
|
6
|
+
#
|
|
7
|
+
# The methods provided here mimic `Zip::OutputStream` so that this class can be used a drop-in replacement.
|
|
8
|
+
class BufferedZipOutputStream
|
|
9
|
+
# The 4_096 was chosen somewhat arbitrary, however, it was difficult to see any obvious improvement with larger
|
|
10
|
+
# buffer sizes.
|
|
11
|
+
BUFFER_SIZE = 4_096
|
|
12
|
+
|
|
13
|
+
def initialize(zos)
|
|
14
|
+
@zos = zos
|
|
15
|
+
@buffer = String.new(capacity: BUFFER_SIZE * 2)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Create a temporary directory for writing files to.
|
|
19
|
+
#
|
|
20
|
+
# The directory and its contents are removed at the end of the block.
|
|
21
|
+
def self.open(file_name, encrypter = nil)
|
|
22
|
+
Zip::OutputStream.open(file_name, encrypter) do |zos|
|
|
23
|
+
bzos = new(zos)
|
|
24
|
+
yield(bzos)
|
|
25
|
+
ensure
|
|
26
|
+
bzos.flush if bzos
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.write_buffer(io = ::StringIO.new, encrypter = nil)
|
|
31
|
+
Zip::OutputStream.write_buffer(io, encrypter) do |zos|
|
|
32
|
+
bzos = new(zos)
|
|
33
|
+
yield(bzos)
|
|
34
|
+
ensure
|
|
35
|
+
bzos.flush if bzos
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Closes the current entry and opens a new for writing.
|
|
40
|
+
def put_next_entry(entry)
|
|
41
|
+
flush
|
|
42
|
+
@zos.put_next_entry(entry)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Write to a buffer that will be written to the current entry
|
|
46
|
+
def write(content)
|
|
47
|
+
@buffer << content.to_s
|
|
48
|
+
flush if @buffer.size > BUFFER_SIZE
|
|
49
|
+
self
|
|
50
|
+
end
|
|
51
|
+
alias << write
|
|
52
|
+
|
|
53
|
+
def flush
|
|
54
|
+
return if @buffer.empty?
|
|
55
|
+
|
|
56
|
+
@zos << @buffer
|
|
57
|
+
@buffer.clear
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/axlsx/util/constants.rb
CHANGED
|
@@ -1,261 +1,263 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# XML Encoding
|
|
3
|
-
ENCODING = "UTF-8"
|
|
5
|
+
ENCODING = "UTF-8"
|
|
4
6
|
|
|
5
7
|
# spreadsheetML namespace
|
|
6
|
-
XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
|
8
|
+
XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
|
7
9
|
|
|
8
10
|
# content-types namespace
|
|
9
|
-
XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types"
|
|
11
|
+
XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types"
|
|
10
12
|
|
|
11
13
|
# extended-properties namespace
|
|
12
|
-
APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
|
|
14
|
+
APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
|
|
13
15
|
|
|
14
16
|
# doc props namespace
|
|
15
|
-
APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
|
|
17
|
+
APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
|
|
16
18
|
|
|
17
19
|
# core properties namespace
|
|
18
|
-
CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
|
|
20
|
+
CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
|
|
19
21
|
|
|
20
22
|
# dc elements (core) namespace
|
|
21
|
-
CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
|
|
23
|
+
CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
|
|
22
24
|
|
|
23
25
|
# dcmit (core) namespcace
|
|
24
|
-
CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
|
|
26
|
+
CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
|
|
25
27
|
|
|
26
28
|
# dc terms namespace
|
|
27
|
-
CORE_NS_DCT = "http://purl.org/dc/terms/"
|
|
29
|
+
CORE_NS_DCT = "http://purl.org/dc/terms/"
|
|
28
30
|
|
|
29
31
|
# xml schema namespace
|
|
30
|
-
CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
|
|
32
|
+
CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
|
|
31
33
|
|
|
32
34
|
# Digital signature namespace
|
|
33
|
-
DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"
|
|
35
|
+
DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"
|
|
34
36
|
|
|
35
37
|
# spreadsheet drawing namespace
|
|
36
|
-
XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
|
|
38
|
+
XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
|
|
37
39
|
|
|
38
40
|
# drawing namespace
|
|
39
|
-
XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
41
|
+
XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
40
42
|
|
|
41
43
|
# chart namespace
|
|
42
|
-
XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart"
|
|
44
|
+
XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart"
|
|
43
45
|
|
|
44
46
|
# relationships namespace
|
|
45
|
-
XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
|
47
|
+
XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
|
46
48
|
|
|
47
49
|
# relationships name space
|
|
48
|
-
RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
|
|
50
|
+
RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
|
|
49
51
|
|
|
50
52
|
# table rels namespace
|
|
51
|
-
TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
|
|
53
|
+
TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
|
|
52
54
|
|
|
53
55
|
# pivot table rels namespace
|
|
54
|
-
PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
|
|
56
|
+
PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
|
|
55
57
|
|
|
56
58
|
# pivot table cache definition namespace
|
|
57
|
-
PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
|
|
59
|
+
PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
|
|
58
60
|
|
|
59
61
|
# workbook rels namespace
|
|
60
|
-
WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
|
62
|
+
WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
|
61
63
|
|
|
62
64
|
# worksheet rels namespace
|
|
63
|
-
WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
|
|
65
|
+
WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
|
|
64
66
|
|
|
65
67
|
# app rels namespace
|
|
66
|
-
APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
|
|
68
|
+
APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
|
|
67
69
|
|
|
68
70
|
# core rels namespace
|
|
69
|
-
CORE_R = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
|
|
71
|
+
CORE_R = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
|
|
70
72
|
|
|
71
73
|
# digital signature rels namespace
|
|
72
|
-
DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"
|
|
74
|
+
DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"
|
|
73
75
|
|
|
74
76
|
# styles rels namespace
|
|
75
|
-
STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
|
|
77
|
+
STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
|
|
76
78
|
|
|
77
79
|
# shared strings namespace
|
|
78
|
-
SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
|
80
|
+
SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
|
79
81
|
|
|
80
82
|
# drawing rels namespace
|
|
81
|
-
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
|
|
83
|
+
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
|
|
82
84
|
|
|
83
85
|
# chart rels namespace
|
|
84
|
-
CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
|
|
86
|
+
CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
|
|
85
87
|
|
|
86
88
|
# image rels namespace
|
|
87
|
-
IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
|
89
|
+
IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
|
88
90
|
|
|
89
91
|
# hyperlink rels namespace
|
|
90
|
-
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
|
92
|
+
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
|
91
93
|
|
|
92
94
|
# comment rels namespace
|
|
93
|
-
COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
|
|
95
|
+
COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
|
|
94
96
|
|
|
95
97
|
# comment relation for nil target
|
|
96
|
-
COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
|
|
98
|
+
COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
|
|
97
99
|
|
|
98
100
|
# vml drawing relation namespace
|
|
99
101
|
VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'
|
|
100
102
|
|
|
101
103
|
# VML Drawing content type
|
|
102
|
-
VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
|
|
104
|
+
VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
|
|
103
105
|
|
|
104
106
|
# table content type
|
|
105
|
-
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
|
|
107
|
+
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
|
|
106
108
|
|
|
107
109
|
# pivot table content type
|
|
108
|
-
PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
|
|
110
|
+
PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
|
|
109
111
|
|
|
110
112
|
# pivot table cache definition content type
|
|
111
|
-
PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
|
|
113
|
+
PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
|
|
112
114
|
|
|
113
115
|
# workbook content type
|
|
114
|
-
WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
|
116
|
+
WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
|
115
117
|
|
|
116
118
|
# app content type
|
|
117
|
-
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
|
119
|
+
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
|
118
120
|
|
|
119
121
|
# rels content type
|
|
120
|
-
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
|
122
|
+
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
|
121
123
|
|
|
122
124
|
# styles content type
|
|
123
|
-
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
|
125
|
+
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
|
124
126
|
|
|
125
127
|
# xml content type
|
|
126
|
-
XML_CT = "application/xml"
|
|
128
|
+
XML_CT = "application/xml"
|
|
127
129
|
|
|
128
130
|
# worksheet content type
|
|
129
|
-
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
|
131
|
+
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
|
130
132
|
|
|
131
133
|
# shared strings content type
|
|
132
|
-
SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
|
134
|
+
SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
|
133
135
|
|
|
134
136
|
# core content type
|
|
135
|
-
CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
|
|
137
|
+
CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
|
|
136
138
|
|
|
137
139
|
# digital signature xml content type
|
|
138
|
-
DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
|
|
140
|
+
DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
|
|
139
141
|
|
|
140
142
|
# digital signature origin content type
|
|
141
|
-
DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
|
|
143
|
+
DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
|
|
142
144
|
|
|
143
145
|
# digital signature certificate content type
|
|
144
|
-
DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
|
|
146
|
+
DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
|
|
145
147
|
|
|
146
148
|
# chart content type
|
|
147
|
-
CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
|
|
149
|
+
CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
|
|
148
150
|
|
|
149
151
|
# comments content type
|
|
150
|
-
COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
|
|
152
|
+
COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
|
|
151
153
|
|
|
152
154
|
# jpeg content type
|
|
153
|
-
JPEG_CT = "image/jpeg"
|
|
155
|
+
JPEG_CT = "image/jpeg"
|
|
154
156
|
|
|
155
157
|
# gif content type
|
|
156
|
-
GIF_CT = "image/gif"
|
|
158
|
+
GIF_CT = "image/gif"
|
|
157
159
|
|
|
158
160
|
# png content type
|
|
159
|
-
PNG_CT = "image/png"
|
|
161
|
+
PNG_CT = "image/png"
|
|
160
162
|
|
|
161
163
|
# drawing content type
|
|
162
|
-
DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
|
|
164
|
+
DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
|
|
163
165
|
|
|
164
166
|
# xml content type extensions
|
|
165
|
-
XML_EX = "xml"
|
|
167
|
+
XML_EX = "xml"
|
|
166
168
|
|
|
167
|
-
# jpeg
|
|
168
|
-
|
|
169
|
+
# jpeg extensions
|
|
170
|
+
JPEG_EXS = ["jpeg", "jpg"].freeze
|
|
169
171
|
|
|
170
172
|
# gif extension
|
|
171
|
-
GIF_EX = "gif"
|
|
173
|
+
GIF_EX = "gif"
|
|
172
174
|
|
|
173
175
|
# png extension
|
|
174
|
-
PNG_EX = "png"
|
|
176
|
+
PNG_EX = "png"
|
|
175
177
|
|
|
176
178
|
# rels content type extension
|
|
177
|
-
RELS_EX = "rels"
|
|
179
|
+
RELS_EX = "rels"
|
|
178
180
|
|
|
179
181
|
# workbook part
|
|
180
|
-
WORKBOOK_PN = "xl/workbook.xml"
|
|
182
|
+
WORKBOOK_PN = "xl/workbook.xml"
|
|
181
183
|
|
|
182
184
|
# styles part
|
|
183
|
-
STYLES_PN = "styles.xml"
|
|
185
|
+
STYLES_PN = "styles.xml"
|
|
184
186
|
|
|
185
187
|
# shared_strings part
|
|
186
|
-
SHARED_STRINGS_PN = "sharedStrings.xml"
|
|
188
|
+
SHARED_STRINGS_PN = "sharedStrings.xml"
|
|
187
189
|
|
|
188
190
|
# app part
|
|
189
|
-
APP_PN = "docProps/app.xml"
|
|
191
|
+
APP_PN = "docProps/app.xml"
|
|
190
192
|
|
|
191
193
|
# core part
|
|
192
|
-
CORE_PN = "docProps/core.xml"
|
|
194
|
+
CORE_PN = "docProps/core.xml"
|
|
193
195
|
|
|
194
196
|
# content types part
|
|
195
|
-
CONTENT_TYPES_PN = "[Content_Types].xml"
|
|
197
|
+
CONTENT_TYPES_PN = "[Content_Types].xml"
|
|
196
198
|
|
|
197
199
|
# rels part
|
|
198
|
-
RELS_PN = "_rels/.rels"
|
|
200
|
+
RELS_PN = "_rels/.rels"
|
|
199
201
|
|
|
200
202
|
# workbook rels part
|
|
201
|
-
WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
|
|
203
|
+
WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
|
|
202
204
|
|
|
203
205
|
# worksheet part
|
|
204
|
-
WORKSHEET_PN = "worksheets/sheet%d.xml"
|
|
206
|
+
WORKSHEET_PN = "worksheets/sheet%d.xml"
|
|
205
207
|
|
|
206
208
|
# worksheet rels part
|
|
207
|
-
WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
|
|
209
|
+
WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
|
|
208
210
|
|
|
209
211
|
# drawing part
|
|
210
|
-
DRAWING_PN = "drawings/drawing%d.xml"
|
|
212
|
+
DRAWING_PN = "drawings/drawing%d.xml"
|
|
211
213
|
|
|
212
214
|
# drawing rels part
|
|
213
|
-
DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
|
|
215
|
+
DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
|
|
214
216
|
|
|
215
217
|
# vml drawing part
|
|
216
|
-
VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
|
|
218
|
+
VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
|
|
217
219
|
|
|
218
220
|
# drawing part
|
|
219
|
-
TABLE_PN = "tables/table%d.xml"
|
|
221
|
+
TABLE_PN = "tables/table%d.xml"
|
|
220
222
|
|
|
221
223
|
# pivot table parts
|
|
222
|
-
PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
|
|
224
|
+
PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
|
|
223
225
|
|
|
224
226
|
# pivot table cache definition part name
|
|
225
|
-
PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
|
|
227
|
+
PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
|
|
226
228
|
|
|
227
229
|
# pivot table rels parts
|
|
228
|
-
PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
|
|
230
|
+
PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
|
|
229
231
|
|
|
230
232
|
# chart part
|
|
231
|
-
CHART_PN = "charts/chart%d.xml"
|
|
233
|
+
CHART_PN = "charts/chart%d.xml"
|
|
232
234
|
|
|
233
235
|
# chart part
|
|
234
|
-
IMAGE_PN = "media/image%d.%s"
|
|
236
|
+
IMAGE_PN = "media/image%d.%s"
|
|
235
237
|
|
|
236
238
|
# comment part
|
|
237
|
-
COMMENT_PN = "comments%d.xml"
|
|
239
|
+
COMMENT_PN = "comments%d.xml"
|
|
238
240
|
|
|
239
241
|
# location of schema files for validation
|
|
240
|
-
SCHEMA_BASE =
|
|
242
|
+
SCHEMA_BASE = "#{File.dirname(__FILE__)}/../../schema/"
|
|
241
243
|
|
|
242
244
|
# App validation schema
|
|
243
|
-
APP_XSD =
|
|
245
|
+
APP_XSD = "#{SCHEMA_BASE}shared-documentPropertiesExtended.xsd"
|
|
244
246
|
|
|
245
247
|
# core validation schema
|
|
246
|
-
CORE_XSD =
|
|
248
|
+
CORE_XSD = "#{SCHEMA_BASE}opc-coreProperties.xsd"
|
|
247
249
|
|
|
248
250
|
# content types validation schema
|
|
249
|
-
CONTENT_TYPES_XSD =
|
|
251
|
+
CONTENT_TYPES_XSD = "#{SCHEMA_BASE}opc-contentTypes.xsd"
|
|
250
252
|
|
|
251
253
|
# rels validation schema
|
|
252
|
-
RELS_XSD =
|
|
254
|
+
RELS_XSD = "#{SCHEMA_BASE}opc-relationships.xsd"
|
|
253
255
|
|
|
254
256
|
# spreadsheetML validation schema
|
|
255
|
-
SML_XSD =
|
|
257
|
+
SML_XSD = "#{SCHEMA_BASE}sml.xsd"
|
|
256
258
|
|
|
257
259
|
# drawing validation schema
|
|
258
|
-
DRAWING_XSD =
|
|
260
|
+
DRAWING_XSD = "#{SCHEMA_BASE}dml-spreadsheetDrawing.xsd"
|
|
259
261
|
|
|
260
262
|
# number format id for pecentage formatting using the default formatting id.
|
|
261
263
|
NUM_FMT_PERCENT = 9
|
|
@@ -279,46 +281,46 @@ module Axlsx
|
|
|
279
281
|
WORKSHEET_NAME_FORBIDDEN_CHARS = '[]*/\?:'.chars.freeze
|
|
280
282
|
|
|
281
283
|
# error messages RestrictionValidor
|
|
282
|
-
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
|
284
|
+
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
|
283
285
|
|
|
284
286
|
# error message DataTypeValidator
|
|
285
|
-
ERR_TYPE = "Invalid Data %s for %s. must be %s."
|
|
287
|
+
ERR_TYPE = "Invalid Data %s for %s. must be %s."
|
|
286
288
|
|
|
287
289
|
# error message for RegexValidator
|
|
288
|
-
ERR_REGEX = "Invalid Data. %s does not match %s."
|
|
290
|
+
ERR_REGEX = "Invalid Data. %s does not match %s."
|
|
289
291
|
|
|
290
292
|
# error message for RangeValidator
|
|
291
|
-
ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
|
|
293
|
+
ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
|
|
292
294
|
|
|
293
295
|
# error message for sheets that use explicit empty string name
|
|
294
|
-
ERR_SHEET_NAME_EMPTY = "Your worksheet name is empty. Worksheet name can't be empty. Please assign name of your sheet or don't use name option at all."
|
|
296
|
+
ERR_SHEET_NAME_EMPTY = "Your worksheet name is empty. Worksheet name can't be empty. Please assign name of your sheet or don't use name option at all."
|
|
295
297
|
|
|
296
298
|
# error message for sheets that use a name which is longer than 31 bytes
|
|
297
|
-
ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be #{WORKSHEET_MAX_NAME_LENGTH} characters (bytes) or less"
|
|
299
|
+
ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be #{WORKSHEET_MAX_NAME_LENGTH} characters (bytes) or less"
|
|
298
300
|
|
|
299
301
|
# error message for sheets that use a name which include invalid characters
|
|
300
|
-
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."
|
|
302
|
+
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."
|
|
301
303
|
|
|
302
304
|
# error message for duplicate sheet names
|
|
303
|
-
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
|
|
305
|
+
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
|
|
304
306
|
|
|
305
307
|
# error message when user does not provide color and or style options for border in Style#add_sytle
|
|
306
|
-
ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
|
|
308
|
+
ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
|
|
307
309
|
|
|
308
310
|
# error message for invalid border id reference
|
|
309
|
-
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."
|
|
311
|
+
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."
|
|
310
312
|
|
|
311
313
|
# error message for invalid angles
|
|
312
|
-
ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"
|
|
314
|
+
ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"
|
|
313
315
|
|
|
314
316
|
# error message for non 'integerish' value
|
|
315
|
-
ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
|
|
317
|
+
ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
|
|
316
318
|
|
|
317
319
|
# error message for invalid cell reference
|
|
318
|
-
ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`"
|
|
320
|
+
ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`"
|
|
319
321
|
|
|
320
322
|
# error message for cell reference with last cell missing
|
|
321
|
-
ERR_CELL_REFERENCE_MISSING_CELL = "Missing cell `%s` for the specified range `%s`"
|
|
323
|
+
ERR_CELL_REFERENCE_MISSING_CELL = "Missing cell `%s` for the specified range `%s`"
|
|
322
324
|
|
|
323
325
|
# Regex to match forbidden control characters
|
|
324
326
|
# The following will be automatically stripped from worksheets.
|
|
@@ -354,7 +356,7 @@ module Axlsx
|
|
|
354
356
|
# x1F Information Separator One
|
|
355
357
|
#
|
|
356
358
|
# The following are not dealt with.
|
|
357
|
-
# If you have this in your data, expect
|
|
359
|
+
# If you have this in your data, expect Excel to blow up!
|
|
358
360
|
#
|
|
359
361
|
# x7F Delete
|
|
360
362
|
# x80 Control 0080
|
|
@@ -395,9 +397,8 @@ module Axlsx
|
|
|
395
397
|
# x0A Line Feed (Lf)
|
|
396
398
|
# x0D Carriage Return (Cr)
|
|
397
399
|
# x09 Character Tabulation
|
|
398
|
-
# @see
|
|
399
|
-
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
|
|
400
|
-
pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
|
|
400
|
+
# @see https://www.codetable.net/asciikeycodes
|
|
401
|
+
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F".encode(Encoding::UTF_8)
|
|
401
402
|
|
|
402
403
|
# The regular expression used to remove control characters from worksheets
|
|
403
404
|
CONTROL_CHARS = pattern.freeze
|
|
@@ -411,4 +412,16 @@ module Axlsx
|
|
|
411
412
|
|
|
412
413
|
# Numeric recognition
|
|
413
414
|
NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
|
|
415
|
+
|
|
416
|
+
# Leading characters that indicate a formula.
|
|
417
|
+
# See: https://owasp.org/www-community/attacks/CSV_Injection
|
|
418
|
+
FORMULA_PREFIX = '='
|
|
419
|
+
|
|
420
|
+
# Leading characters that indicate an array formula.
|
|
421
|
+
ARRAY_FORMULA_PREFIX = '{='
|
|
422
|
+
|
|
423
|
+
# Trailing character that indicates an array formula.
|
|
424
|
+
ARRAY_FORMULA_SUFFIX = '}'
|
|
425
|
+
|
|
426
|
+
BOOLEAN_VALUES = [true, false].freeze
|
|
414
427
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'open-uri'
|
|
2
4
|
|
|
3
5
|
module Axlsx
|
|
@@ -14,11 +16,7 @@ module Axlsx
|
|
|
14
16
|
# @param [String] v URI
|
|
15
17
|
# @return [String] File mime type
|
|
16
18
|
def self.get_mime_type_from_uri(v)
|
|
17
|
-
|
|
18
|
-
Marcel::MimeType.for(URI.open(v))
|
|
19
|
-
else
|
|
20
|
-
Marcel::MimeType.for(URI.parse(v).open)
|
|
21
|
-
end
|
|
19
|
+
Marcel::MimeType.for(URI.parse(v).open)
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# This module defines a single method for parsing options in class
|
|
3
5
|
# initializers.
|
|
@@ -8,7 +10,7 @@ module Axlsx
|
|
|
8
10
|
def parse_options(options = {})
|
|
9
11
|
options.each do |key, value|
|
|
10
12
|
key = :"#{key}="
|
|
11
|
-
|
|
13
|
+
send(key, value) if !value.nil? && respond_to?(key)
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# This module allows us to define a list of symbols defining which
|
|
3
5
|
# attributes will be serialized for a class.
|
|
@@ -13,11 +15,21 @@ module Axlsx
|
|
|
13
15
|
# which of the instance values are serializable
|
|
14
16
|
def serializable_attributes(*symbols)
|
|
15
17
|
@xml_attributes = symbols
|
|
18
|
+
@camel_xml_attributes = nil
|
|
19
|
+
@ivar_xml_attributes = nil
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
# a reader for those attributes
|
|
19
23
|
attr_reader :xml_attributes
|
|
20
24
|
|
|
25
|
+
def camel_xml_attributes
|
|
26
|
+
@camel_xml_attributes ||= @xml_attributes.map { |attr| Axlsx.camel(attr, false) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def ivar_xml_attributes
|
|
30
|
+
@ivar_xml_attributes ||= @xml_attributes.map { |attr| :"@#{attr}" }
|
|
31
|
+
end
|
|
32
|
+
|
|
21
33
|
# This helper registers the attributes that will be formatted as elements.
|
|
22
34
|
def serializable_element_attributes(*symbols)
|
|
23
35
|
@xml_element_attributes = symbols
|
|
@@ -29,13 +41,13 @@ module Axlsx
|
|
|
29
41
|
|
|
30
42
|
# creates a XML tag with serialized attributes
|
|
31
43
|
# @see SerializedAttributes#serialized_attributes
|
|
32
|
-
def serialized_tag(tagname, str, additional_attributes = {}
|
|
33
|
-
str <<
|
|
44
|
+
def serialized_tag(tagname, str, additional_attributes = {})
|
|
45
|
+
str << '<' << tagname << ' '
|
|
34
46
|
serialized_attributes(str, additional_attributes)
|
|
35
47
|
if block_given?
|
|
36
48
|
str << '>'
|
|
37
49
|
yield
|
|
38
|
-
str <<
|
|
50
|
+
str << '</' << tagname << '>'
|
|
39
51
|
else
|
|
40
52
|
str << '/>'
|
|
41
53
|
end
|
|
@@ -47,21 +59,34 @@ module Axlsx
|
|
|
47
59
|
# serialization to.
|
|
48
60
|
# @param [Hash] additional_attributes An option key value hash for
|
|
49
61
|
# defining values that are not serializable attributes list.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
# @param [Boolean] camelize_value Should the attribute values be camelized
|
|
63
|
+
def serialized_attributes(str = +'', additional_attributes = {}, camelize_value = true)
|
|
64
|
+
camel_xml_attributes = self.class.camel_xml_attributes
|
|
65
|
+
ivar_xml_attributes = self.class.ivar_xml_attributes
|
|
66
|
+
|
|
67
|
+
self.class.xml_attributes.each_with_index do |attr, index|
|
|
68
|
+
next if additional_attributes.key?(attr)
|
|
69
|
+
next unless instance_variable_defined?(ivar_xml_attributes[index])
|
|
70
|
+
|
|
71
|
+
value = instance_variable_get(ivar_xml_attributes[index])
|
|
72
|
+
next if value.nil?
|
|
73
|
+
|
|
74
|
+
value = Axlsx.booleanize(value)
|
|
75
|
+
value = Axlsx.camel(value, false) if camelize_value
|
|
76
|
+
|
|
77
|
+
str << camel_xml_attributes[index] << '="' << value.to_s << '" '
|
|
54
78
|
end
|
|
55
|
-
str
|
|
56
|
-
end
|
|
57
79
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
additional_attributes.each do |attr, value|
|
|
81
|
+
next if value.nil?
|
|
82
|
+
|
|
83
|
+
value = Axlsx.booleanize(value)
|
|
84
|
+
value = Axlsx.camel(value, false) if camelize_value
|
|
85
|
+
|
|
86
|
+
str << Axlsx.camel(attr, false) << '="' << value.to_s << '" '
|
|
64
87
|
end
|
|
88
|
+
|
|
89
|
+
str
|
|
65
90
|
end
|
|
66
91
|
|
|
67
92
|
# serialized instance values at text nodes on a camelized element of the
|
|
@@ -71,7 +96,7 @@ module Axlsx
|
|
|
71
96
|
# @param [String] str The string instance to which serialized data is appended
|
|
72
97
|
# @param [Array] additional_attributes An array of additional attribute names.
|
|
73
98
|
# @return [String] The serialized output.
|
|
74
|
-
def serialized_element_attributes(str = '', additional_attributes = []
|
|
99
|
+
def serialized_element_attributes(str = +'', additional_attributes = [])
|
|
75
100
|
attrs = self.class.xml_element_attributes + additional_attributes
|
|
76
101
|
values = Axlsx.instance_values_for(self)
|
|
77
102
|
attrs.each do |attribute_name|
|
|
@@ -80,7 +105,7 @@ module Axlsx
|
|
|
80
105
|
|
|
81
106
|
value = yield value if block_given?
|
|
82
107
|
element_name = Axlsx.camel(attribute_name, false)
|
|
83
|
-
str <<
|
|
108
|
+
str << '<' << element_name << '>' << value << '</' << element_name << '>'
|
|
84
109
|
end
|
|
85
110
|
str
|
|
86
111
|
end
|