caxlsx 3.4.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
  7. data/lib/axlsx/content_type/content_type.rb +8 -6
  8. data/lib/axlsx/content_type/default.rb +7 -2
  9. data/lib/axlsx/content_type/override.rb +7 -2
  10. data/lib/axlsx/doc_props/app.rb +95 -26
  11. data/lib/axlsx/doc_props/core.rb +8 -6
  12. data/lib/axlsx/drawing/area_chart.rb +10 -8
  13. data/lib/axlsx/drawing/area_series.rb +20 -12
  14. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  15. data/lib/axlsx/drawing/axes.rb +6 -4
  16. data/lib/axlsx/drawing/axis.rb +42 -22
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  18. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  19. data/lib/axlsx/drawing/bar_series.rb +20 -9
  20. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  21. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  22. data/lib/axlsx/drawing/cat_axis.rb +29 -12
  23. data/lib/axlsx/drawing/chart.rb +46 -20
  24. data/lib/axlsx/drawing/d_lbls.rb +10 -8
  25. data/lib/axlsx/drawing/drawing.rb +59 -56
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  27. data/lib/axlsx/drawing/hyperlink.rb +19 -8
  28. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  29. data/lib/axlsx/drawing/line_chart.rb +10 -8
  30. data/lib/axlsx/drawing/line_series.rb +20 -12
  31. data/lib/axlsx/drawing/marker.rb +24 -7
  32. data/lib/axlsx/drawing/num_data.rb +9 -7
  33. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  34. data/lib/axlsx/drawing/num_val.rb +7 -5
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
  36. data/lib/axlsx/drawing/pic.rb +26 -15
  37. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +23 -9
  41. data/lib/axlsx/drawing/scaling.rb +25 -9
  42. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  43. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  44. data/lib/axlsx/drawing/ser_axis.rb +13 -5
  45. data/lib/axlsx/drawing/series.rb +13 -5
  46. data/lib/axlsx/drawing/series_title.rb +6 -4
  47. data/lib/axlsx/drawing/str_data.rb +7 -5
  48. data/lib/axlsx/drawing/str_val.rb +6 -4
  49. data/lib/axlsx/drawing/title.rb +13 -14
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  51. data/lib/axlsx/drawing/val_axis.rb +4 -2
  52. data/lib/axlsx/drawing/view_3D.rb +16 -8
  53. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  54. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  55. data/lib/axlsx/package.rb +73 -67
  56. data/lib/axlsx/rels/relationship.rb +21 -6
  57. data/lib/axlsx/rels/relationships.rb +6 -4
  58. data/lib/axlsx/stylesheet/border.rb +15 -4
  59. data/lib/axlsx/stylesheet/border_pr.rb +19 -6
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
  61. data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
  62. data/lib/axlsx/stylesheet/cell_style.rb +33 -8
  63. data/lib/axlsx/stylesheet/color.rb +15 -7
  64. data/lib/axlsx/stylesheet/dxf.rb +34 -9
  65. data/lib/axlsx/stylesheet/fill.rb +7 -2
  66. data/lib/axlsx/stylesheet/font.rb +65 -17
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
  69. data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
  71. data/lib/axlsx/stylesheet/styles.rb +124 -82
  72. data/lib/axlsx/stylesheet/table_style.rb +19 -6
  73. data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
  74. data/lib/axlsx/stylesheet/table_styles.rb +14 -5
  75. data/lib/axlsx/stylesheet/xf.rb +73 -18
  76. data/lib/axlsx/util/accessors.rb +10 -6
  77. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  78. data/lib/axlsx/util/constants.rb +117 -104
  79. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  80. data/lib/axlsx/util/options_parser.rb +3 -1
  81. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  82. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  83. data/lib/axlsx/util/storage.rb +11 -10
  84. data/lib/axlsx/util/validators.rb +101 -41
  85. data/lib/axlsx/util/zip_command.rb +10 -10
  86. data/lib/axlsx/version.rb +3 -1
  87. data/lib/axlsx/workbook/defined_name.rb +6 -4
  88. data/lib/axlsx/workbook/defined_names.rb +4 -2
  89. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  90. data/lib/axlsx/workbook/workbook.rb +94 -79
  91. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  92. data/lib/axlsx/workbook/workbook_views.rb +4 -2
  93. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  94. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  96. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  97. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  98. data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
  99. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  100. data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
  101. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  102. data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
  103. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  104. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  105. data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
  106. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  107. data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  109. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  110. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
  111. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
  112. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
  113. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  114. data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
  115. data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  117. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  118. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  119. data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
  120. data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
  121. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
  123. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
  125. data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
  126. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  127. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  128. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  130. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
  132. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  133. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
  134. data/lib/axlsx/workbook/worksheet/row.rb +11 -9
  135. data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
  136. data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  139. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  140. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  141. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
  142. data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
  143. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  144. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  145. data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
  147. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  148. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  149. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
  150. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
  151. data/lib/axlsx.rb +56 -42
  152. data/lib/caxlsx.rb +3 -1
  153. metadata +39 -71
@@ -1,261 +1,263 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # XML Encoding
3
- ENCODING = "UTF-8".freeze
5
+ ENCODING = "UTF-8"
4
6
 
5
7
  # spreadsheetML namespace
6
- XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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/".freeze
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/".freeze
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/".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
125
+ STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
124
126
 
125
127
  # xml content type
126
- XML_CT = "application/xml".freeze
128
+ XML_CT = "application/xml"
127
129
 
128
130
  # worksheet content type
129
- WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
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".freeze
152
+ COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
151
153
 
152
154
  # jpeg content type
153
- JPEG_CT = "image/jpeg".freeze
155
+ JPEG_CT = "image/jpeg"
154
156
 
155
157
  # gif content type
156
- GIF_CT = "image/gif".freeze
158
+ GIF_CT = "image/gif"
157
159
 
158
160
  # png content type
159
- PNG_CT = "image/png".freeze
161
+ PNG_CT = "image/png"
160
162
 
161
163
  # drawing content type
162
- DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml".freeze
164
+ DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
163
165
 
164
166
  # xml content type extensions
165
- XML_EX = "xml".freeze
167
+ XML_EX = "xml"
166
168
 
167
- # jpeg extension
168
- JPEG_EX = "jpeg".freeze
169
+ # jpeg extensions
170
+ JPEG_EXS = ["jpeg", "jpg"].freeze
169
171
 
170
172
  # gif extension
171
- GIF_EX = "gif".freeze
173
+ GIF_EX = "gif"
172
174
 
173
175
  # png extension
174
- PNG_EX = "png".freeze
176
+ PNG_EX = "png"
175
177
 
176
178
  # rels content type extension
177
- RELS_EX = "rels".freeze
179
+ RELS_EX = "rels"
178
180
 
179
181
  # workbook part
180
- WORKBOOK_PN = "xl/workbook.xml".freeze
182
+ WORKBOOK_PN = "xl/workbook.xml"
181
183
 
182
184
  # styles part
183
- STYLES_PN = "styles.xml".freeze
185
+ STYLES_PN = "styles.xml"
184
186
 
185
187
  # shared_strings part
186
- SHARED_STRINGS_PN = "sharedStrings.xml".freeze
188
+ SHARED_STRINGS_PN = "sharedStrings.xml"
187
189
 
188
190
  # app part
189
- APP_PN = "docProps/app.xml".freeze
191
+ APP_PN = "docProps/app.xml"
190
192
 
191
193
  # core part
192
- CORE_PN = "docProps/core.xml".freeze
194
+ CORE_PN = "docProps/core.xml"
193
195
 
194
196
  # content types part
195
- CONTENT_TYPES_PN = "[Content_Types].xml".freeze
197
+ CONTENT_TYPES_PN = "[Content_Types].xml"
196
198
 
197
199
  # rels part
198
- RELS_PN = "_rels/.rels".freeze
200
+ RELS_PN = "_rels/.rels"
199
201
 
200
202
  # workbook rels part
201
- WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels".freeze
203
+ WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
202
204
 
203
205
  # worksheet part
204
- WORKSHEET_PN = "worksheets/sheet%d.xml".freeze
206
+ WORKSHEET_PN = "worksheets/sheet%d.xml"
205
207
 
206
208
  # worksheet rels part
207
- WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels".freeze
209
+ WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
208
210
 
209
211
  # drawing part
210
- DRAWING_PN = "drawings/drawing%d.xml".freeze
212
+ DRAWING_PN = "drawings/drawing%d.xml"
211
213
 
212
214
  # drawing rels part
213
- DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels".freeze
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".freeze
218
+ VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
217
219
 
218
220
  # drawing part
219
- TABLE_PN = "tables/table%d.xml".freeze
221
+ TABLE_PN = "tables/table%d.xml"
220
222
 
221
223
  # pivot table parts
222
- PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml".freeze
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".freeze
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".freeze
230
+ PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
229
231
 
230
232
  # chart part
231
- CHART_PN = "charts/chart%d.xml".freeze
233
+ CHART_PN = "charts/chart%d.xml"
232
234
 
233
235
  # chart part
234
- IMAGE_PN = "media/image%d.%s".freeze
236
+ IMAGE_PN = "media/image%d.%s"
235
237
 
236
238
  # comment part
237
- COMMENT_PN = "comments%d.xml".freeze
239
+ COMMENT_PN = "comments%d.xml"
238
240
 
239
241
  # location of schema files for validation
240
- SCHEMA_BASE = (File.dirname(__FILE__) + '/../../schema/').freeze
242
+ SCHEMA_BASE = "#{File.dirname(__FILE__)}/../../schema/"
241
243
 
242
244
  # App validation schema
243
- APP_XSD = (SCHEMA_BASE + "shared-documentPropertiesExtended.xsd").freeze
245
+ APP_XSD = "#{SCHEMA_BASE}shared-documentPropertiesExtended.xsd"
244
246
 
245
247
  # core validation schema
246
- CORE_XSD = (SCHEMA_BASE + "opc-coreProperties.xsd").freeze
248
+ CORE_XSD = "#{SCHEMA_BASE}opc-coreProperties.xsd"
247
249
 
248
250
  # content types validation schema
249
- CONTENT_TYPES_XSD = (SCHEMA_BASE + "opc-contentTypes.xsd").freeze
251
+ CONTENT_TYPES_XSD = "#{SCHEMA_BASE}opc-contentTypes.xsd"
250
252
 
251
253
  # rels validation schema
252
- RELS_XSD = (SCHEMA_BASE + "opc-relationships.xsd").freeze
254
+ RELS_XSD = "#{SCHEMA_BASE}opc-relationships.xsd"
253
255
 
254
256
  # spreadsheetML validation schema
255
- SML_XSD = (SCHEMA_BASE + "sml.xsd").freeze
257
+ SML_XSD = "#{SCHEMA_BASE}sml.xsd"
256
258
 
257
259
  # drawing validation schema
258
- DRAWING_XSD = (SCHEMA_BASE + "dml-spreadsheetDrawing.xsd").freeze
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.".freeze
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.".freeze
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.".freeze
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".freeze
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.".freeze
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".freeze
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.".freeze
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".freeze
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".freeze
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.".freeze
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".freeze
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".freeze
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`".freeze
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`".freeze
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 excel to blow up!
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 http://www.codetable.net/asciikeycodes
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
- if URI.respond_to?(:open)
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
- self.send(key, value) if !value.nil? && self.respond_to?(key)
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 = {}, &block)
33
- str << "<#{tagname} "
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 << "</#{tagname}>"
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
- def serialized_attributes(str = '', additional_attributes = {})
51
- attributes = declared_attributes.merge! additional_attributes
52
- attributes.each do |key, value|
53
- str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" "
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
- # A hash of instance variables that have been declared with
59
- # seraialized_attributes and are not nil.
60
- # This requires ruby 1.9.3 or higher
61
- def declared_attributes
62
- Axlsx.instance_values_for(self).select do |key, value|
63
- value != nil && self.class.xml_attributes.include?(key.to_sym)
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 = [], &block)
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 << "<#{element_name}>#{value}</#{element_name}>"
108
+ str << '<' << element_name << '>' << value << '</' << element_name << '>'
84
109
  end
85
110
  str
86
111
  end