caxlsx 3.3.0 → 4.5.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.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -1,265 +1,277 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # XML Encoding
4
- ENCODING = "UTF-8".freeze
5
+ ENCODING = "UTF-8"
5
6
 
6
7
  # spreadsheetML namespace
7
- XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main".freeze
8
+ XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
8
9
 
9
10
  # content-types namespace
10
- XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types".freeze
11
+ XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types"
11
12
 
12
13
  # extended-properties namespace
13
- APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties".freeze
14
+ APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
14
15
 
15
16
  # doc props namespace
16
- APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes".freeze
17
+ APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
17
18
 
18
19
  # core properties namespace
19
- CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties".freeze
20
+ CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
20
21
 
21
22
  # dc elements (core) namespace
22
- CORE_NS_DC = "http://purl.org/dc/elements/1.1/".freeze
23
+ CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
23
24
 
24
25
  # dcmit (core) namespcace
25
- CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/".freeze
26
+ CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
26
27
 
27
28
  # dc terms namespace
28
- CORE_NS_DCT = "http://purl.org/dc/terms/".freeze
29
+ CORE_NS_DCT = "http://purl.org/dc/terms/"
29
30
 
30
31
  # xml schema namespace
31
- CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance".freeze
32
+ CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
32
33
 
33
34
  # Digital signature namespace
34
- DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature".freeze
35
+ DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"
35
36
 
36
37
  # spreadsheet drawing namespace
37
- XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing".freeze
38
+ XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
38
39
 
39
40
  # drawing namespace
40
- XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main".freeze
41
+ XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
41
42
 
42
43
  # chart namespace
43
- XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart".freeze
44
+ XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart"
44
45
 
45
46
  # relationships namespace
46
- XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships".freeze
47
+ XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
47
48
 
48
49
  # relationships name space
49
- RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships".freeze
50
+ RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
50
51
 
51
52
  # table rels namespace
52
- TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table".freeze
53
+ TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
53
54
 
54
55
  # pivot table rels namespace
55
- PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable".freeze
56
+ PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
56
57
 
57
58
  # pivot table cache definition namespace
58
- 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"
59
60
 
60
61
  # workbook rels namespace
61
- WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument".freeze
62
+ WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
62
63
 
63
64
  # worksheet rels namespace
64
- WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet".freeze
65
+ WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
65
66
 
66
67
  # app rels namespace
67
- APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties".freeze
68
+ APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
68
69
 
69
70
  # core rels namespace
70
- 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"
71
72
 
72
73
  # digital signature rels namespace
73
- 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"
74
75
 
75
76
  # styles rels namespace
76
- STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles".freeze
77
+ STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
77
78
 
78
79
  # shared strings namespace
79
- SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings".freeze
80
+ SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
81
+
82
+ # theme rels namespace
83
+ THEME_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"
80
84
 
81
85
  # drawing rels namespace
82
- DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing".freeze
86
+ DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
83
87
 
84
88
  # chart rels namespace
85
- CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart".freeze
89
+ CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
86
90
 
87
91
  # image rels namespace
88
- IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image".freeze
92
+ IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
89
93
 
90
94
  # hyperlink rels namespace
91
- HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink".freeze
95
+ HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
92
96
 
93
97
  # comment rels namespace
94
- COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments".freeze
98
+ COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
95
99
 
96
100
  # comment relation for nil target
97
- COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments".freeze
101
+ COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
98
102
 
99
- #vml drawing relation namespace
103
+ # vml drawing relation namespace
100
104
  VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'
101
105
 
102
106
  # VML Drawing content type
103
- VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing".freeze
107
+ VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
104
108
 
105
109
  # table content type
106
- TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml".freeze
110
+ TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
107
111
 
108
112
  # pivot table content type
109
- PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml".freeze
113
+ PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
110
114
 
111
115
  # pivot table cache definition content type
112
- PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml".freeze
116
+ PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
113
117
 
114
118
  # workbook content type
115
- WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml".freeze
119
+ WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
116
120
 
117
121
  # app content type
118
- APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml".freeze
122
+ APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
119
123
 
120
124
  # rels content type
121
- RELS_CT = "application/vnd.openxmlformats-package.relationships+xml".freeze
125
+ RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
122
126
 
123
127
  # styles content type
124
- STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml".freeze
128
+ STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
125
129
 
126
130
  # xml content type
127
- XML_CT = "application/xml".freeze
131
+ XML_CT = "application/xml"
128
132
 
129
133
  # worksheet content type
130
- WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml".freeze
134
+ WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
131
135
 
132
136
  # shared strings content type
133
- SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml".freeze
137
+ SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
138
+
139
+ # theme content type
140
+ THEME_CT = "application/vnd.openxmlformats-officedocument.theme+xml"
134
141
 
135
142
  # core content type
136
- CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml".freeze
143
+ CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
137
144
 
138
145
  # digital signature xml content type
139
- DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml".freeze
146
+ DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
140
147
 
141
148
  # digital signature origin content type
142
- DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin".freeze
149
+ DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
143
150
 
144
151
  # digital signature certificate content type
145
- DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate".freeze
152
+ DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
146
153
 
147
154
  # chart content type
148
- CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml".freeze
155
+ CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
149
156
 
150
157
  # comments content type
151
- COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml".freeze
158
+ COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
152
159
 
153
160
  # jpeg content type
154
- JPEG_CT = "image/jpeg".freeze
161
+ JPEG_CT = "image/jpeg"
155
162
 
156
163
  # gif content type
157
- GIF_CT = "image/gif".freeze
164
+ GIF_CT = "image/gif"
158
165
 
159
166
  # png content type
160
- PNG_CT = "image/png".freeze
161
-
162
- #drawing content type
163
- DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml".freeze
167
+ PNG_CT = "image/png"
164
168
 
169
+ # drawing content type
170
+ DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
165
171
 
166
172
  # xml content type extensions
167
- XML_EX = "xml".freeze
173
+ XML_EX = "xml"
168
174
 
169
- # jpeg extension
170
- JPEG_EX = "jpeg".freeze
175
+ # jpeg extensions
176
+ JPEG_EXS = ["jpeg", "jpg"].freeze
171
177
 
172
178
  # gif extension
173
- GIF_EX = "gif".freeze
179
+ GIF_EX = "gif"
174
180
 
175
181
  # png extension
176
- PNG_EX = "png".freeze
182
+ PNG_EX = "png"
177
183
 
178
184
  # rels content type extension
179
- RELS_EX = "rels".freeze
185
+ RELS_EX = "rels"
180
186
 
181
187
  # workbook part
182
- WORKBOOK_PN = "xl/workbook.xml".freeze
188
+ WORKBOOK_PN = "xl/workbook.xml"
183
189
 
184
190
  # styles part
185
- STYLES_PN = "styles.xml".freeze
191
+ STYLES_PN = "styles.xml"
186
192
 
187
193
  # shared_strings part
188
- SHARED_STRINGS_PN = "sharedStrings.xml".freeze
194
+ SHARED_STRINGS_PN = "sharedStrings.xml"
195
+
196
+ # theme part
197
+ THEME_PN = "theme/theme1.xml"
189
198
 
190
199
  # app part
191
- APP_PN = "docProps/app.xml".freeze
200
+ APP_PN = "docProps/app.xml"
192
201
 
193
202
  # core part
194
- CORE_PN = "docProps/core.xml".freeze
203
+ CORE_PN = "docProps/core.xml"
195
204
 
196
205
  # content types part
197
- CONTENT_TYPES_PN = "[Content_Types].xml".freeze
206
+ CONTENT_TYPES_PN = "[Content_Types].xml"
198
207
 
199
208
  # rels part
200
- RELS_PN = "_rels/.rels".freeze
209
+ RELS_PN = "_rels/.rels"
201
210
 
202
211
  # workbook rels part
203
- WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels".freeze
212
+ WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
204
213
 
205
214
  # worksheet part
206
- WORKSHEET_PN = "worksheets/sheet%d.xml".freeze
215
+ WORKSHEET_PN = "worksheets/sheet%d.xml"
207
216
 
208
217
  # worksheet rels part
209
- WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels".freeze
218
+ WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
210
219
 
211
220
  # drawing part
212
- DRAWING_PN = "drawings/drawing%d.xml".freeze
221
+ DRAWING_PN = "drawings/drawing%d.xml"
213
222
 
214
223
  # drawing rels part
215
- DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels".freeze
224
+ DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
216
225
 
217
226
  # vml drawing part
218
- VML_DRAWING_PN = "drawings/vmlDrawing%d.vml".freeze
227
+ VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
219
228
 
220
229
  # drawing part
221
- TABLE_PN = "tables/table%d.xml".freeze
230
+ TABLE_PN = "tables/table%d.xml"
222
231
 
223
232
  # pivot table parts
224
- PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml".freeze
233
+ PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
225
234
 
226
235
  # pivot table cache definition part name
227
- PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml".freeze
236
+ PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
228
237
 
229
238
  # pivot table rels parts
230
- PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels".freeze
239
+ PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
231
240
 
232
241
  # chart part
233
- CHART_PN = "charts/chart%d.xml".freeze
242
+ CHART_PN = "charts/chart%d.xml"
234
243
 
235
244
  # chart part
236
- IMAGE_PN = "media/image%d.%s".freeze
245
+ IMAGE_PN = "media/image%d.%s"
237
246
 
238
247
  # comment part
239
- COMMENT_PN = "comments%d.xml".freeze
248
+ COMMENT_PN = "comments%d.xml"
240
249
 
241
250
  # location of schema files for validation
242
- SCHEMA_BASE = (File.dirname(__FILE__)+'/../../schema/').freeze
251
+ SCHEMA_BASE = "#{File.dirname(__FILE__)}/../../schema/"
243
252
 
244
253
  # App validation schema
245
- APP_XSD = (SCHEMA_BASE + "shared-documentPropertiesExtended.xsd").freeze
254
+ APP_XSD = "#{SCHEMA_BASE}shared-documentPropertiesExtended.xsd"
246
255
 
247
256
  # core validation schema
248
- CORE_XSD = (SCHEMA_BASE + "opc-coreProperties.xsd").freeze
257
+ CORE_XSD = "#{SCHEMA_BASE}opc-coreProperties.xsd"
249
258
 
250
259
  # content types validation schema
251
- CONTENT_TYPES_XSD = (SCHEMA_BASE + "opc-contentTypes.xsd").freeze
260
+ CONTENT_TYPES_XSD = "#{SCHEMA_BASE}opc-contentTypes.xsd"
252
261
 
253
262
  # rels validation schema
254
- RELS_XSD = (SCHEMA_BASE + "opc-relationships.xsd").freeze
263
+ RELS_XSD = "#{SCHEMA_BASE}opc-relationships.xsd"
255
264
 
256
265
  # spreadsheetML validation schema
257
- SML_XSD = (SCHEMA_BASE + "sml.xsd").freeze
266
+ SML_XSD = "#{SCHEMA_BASE}sml.xsd"
258
267
 
259
268
  # drawing validation schema
260
- DRAWING_XSD = (SCHEMA_BASE + "dml-spreadsheetDrawing.xsd").freeze
269
+ DRAWING_XSD = "#{SCHEMA_BASE}dml-spreadsheetDrawing.xsd"
261
270
 
262
- # number format id for pecentage formatting using the default formatting id.
271
+ # theme validation schema
272
+ THEME_XSD = "#{SCHEMA_BASE}dml-main.xsd"
273
+
274
+ # number format id for percentage formatting using the default formatting id.
263
275
  NUM_FMT_PERCENT = 9
264
276
 
265
277
  # number format id for date format like 2011/11/13
@@ -281,46 +293,46 @@ module Axlsx
281
293
  WORKSHEET_NAME_FORBIDDEN_CHARS = '[]*/\?:'.chars.freeze
282
294
 
283
295
  # error messages RestrictionValidor
284
- ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s.".freeze
296
+ ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
285
297
 
286
298
  # error message DataTypeValidator
287
- ERR_TYPE = "Invalid Data %s for %s. must be %s.".freeze
299
+ ERR_TYPE = "Invalid Data %s for %s. must be %s."
288
300
 
289
301
  # error message for RegexValidator
290
- ERR_REGEX = "Invalid Data. %s does not match %s.".freeze
302
+ ERR_REGEX = "Invalid Data. %s does not match %s."
291
303
 
292
304
  # error message for RangeValidator
293
- ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s".freeze
305
+ ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
294
306
 
295
307
  # error message for sheets that use explicit empty string name
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.".freeze
308
+ 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."
297
309
 
298
310
  # error message for sheets that use a name which is longer than 31 bytes
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".freeze
311
+ ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be #{WORKSHEET_MAX_NAME_LENGTH} characters (bytes) or less"
300
312
 
301
313
  # error message for sheets that use a name which include invalid characters
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.".freeze
314
+ 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."
303
315
 
304
316
  # error message for duplicate sheet names
305
- ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name".freeze
317
+ ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
306
318
 
307
319
  # error message when user does not provide color and or style options for border in Style#add_sytle
308
- ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s".freeze
320
+ ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
309
321
 
310
322
  # error message for invalid border id reference
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.".freeze
323
+ 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."
312
324
 
313
325
  # error message for invalid angles
314
- ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s".freeze
326
+ ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"
315
327
 
316
328
  # error message for non 'integerish' value
317
- ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s".freeze
329
+ ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
318
330
 
319
331
  # error message for invalid cell reference
320
- ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`".freeze
332
+ ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`"
321
333
 
322
334
  # error message for cell reference with last cell missing
323
- ERR_CELL_REFERENCE_MISSING_CELL = "Missing cell `%s` for the specified range `%s`".freeze
335
+ ERR_CELL_REFERENCE_MISSING_CELL = "Missing cell `%s` for the specified range `%s`"
324
336
 
325
337
  # Regex to match forbidden control characters
326
338
  # The following will be automatically stripped from worksheets.
@@ -356,7 +368,7 @@ module Axlsx
356
368
  # x1F Information Separator One
357
369
  #
358
370
  # The following are not dealt with.
359
- # If you have this in your data, expect excel to blow up!
371
+ # If you have this in your data, expect Excel to blow up!
360
372
  #
361
373
  # x7F Delete
362
374
  # x80 Control 0080
@@ -397,15 +409,14 @@ module Axlsx
397
409
  # x0A Line Feed (Lf)
398
410
  # x0D Carriage Return (Cr)
399
411
  # x09 Character Tabulation
400
- # @see http://www.codetable.net/asciikeycodes
401
- pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
402
- pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
412
+ # @see https://www.codetable.net/asciikeycodes
413
+ pattern = "\x0-\x08\x0B\x0C\x0E-\x1F".encode(Encoding::UTF_8)
403
414
 
404
415
  # The regular expression used to remove control characters from worksheets
405
416
  CONTROL_CHARS = pattern.freeze
406
417
 
407
418
  # ISO 8601 date recognition
408
- 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
419
+ 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/.freeze
409
420
 
410
421
  # FLOAT recognition
411
422
  SAFE_FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]{1,2})?\Z/.freeze
@@ -413,4 +424,16 @@ module Axlsx
413
424
 
414
425
  # Numeric recognition
415
426
  NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
427
+
428
+ # Leading characters that indicate a formula.
429
+ # See: https://owasp.org/www-community/attacks/CSV_Injection
430
+ FORMULA_PREFIX = '='
431
+
432
+ # Leading characters that indicate an array formula.
433
+ ARRAY_FORMULA_PREFIX = '{='
434
+
435
+ # Trailing character that indicates an array formula.
436
+ ARRAY_FORMULA_SUFFIX = '}'
437
+
438
+ BOOLEAN_VALUES = [true, false].freeze
416
439
  end
@@ -1,11 +1,81 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This module defines some utils related with mime type detection
3
5
  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
- Marcel::MimeType.for(Pathname.new(v))
6
+ # Extension to MIME type mapping for Windows fallback
7
+ EXTENSION_FALLBACKS = {
8
+ '.jpg' => 'image/jpeg',
9
+ '.jpeg' => 'image/jpeg',
10
+ '.png' => 'image/png',
11
+ '.gif' => 'image/gif'
12
+ }.freeze
13
+
14
+ class << self
15
+ # Detect a file mime type
16
+ # @param [String] v File path
17
+ # @return [String] File mime type
18
+ def get_mime_type(v)
19
+ mime_type = Marcel::MimeType.for(Pathname.new(v))
20
+
21
+ # Windows fallback: Marcel sometimes returns application/octet-stream for valid image files
22
+ if mime_type == 'application/octet-stream' && windows_platform?
23
+ extension = File.extname(v).downcase
24
+ # Verify it's actually an image by checking the file header
25
+ if EXTENSION_FALLBACKS.key?(extension) && File.exist?(v) && valid_image_file?(v, extension)
26
+ mime_type = EXTENSION_FALLBACKS[extension]
27
+ end
28
+ end
29
+
30
+ mime_type
31
+ end
32
+
33
+ # Detect a file mime type from URI
34
+ # @param [String] v URI
35
+ # @return [String] File mime type
36
+ def get_mime_type_from_uri(v)
37
+ uri = URI.parse(v)
38
+
39
+ unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
40
+ raise URI::InvalidURIError, "Only HTTP/HTTPS URIs are supported"
41
+ end
42
+
43
+ response = UriUtils.fetch_headers(uri)
44
+ mime_type = response&.[]('content-type')&.split(';')&.first&.strip
45
+
46
+ if mime_type.nil? || mime_type.empty?
47
+ raise ArgumentError, "Unable to determine MIME type from response"
48
+ end
49
+
50
+ mime_type
51
+ end
52
+
53
+ private
54
+
55
+ def windows_platform?
56
+ RUBY_PLATFORM =~ /mswin|mingw|cygwin/
57
+ end
58
+
59
+ def valid_image_file?(file_path, extension)
60
+ return false unless File.exist?(file_path)
61
+
62
+ # Check magic bytes for common image formats
63
+ begin
64
+ header = File.binread(file_path, 10)
65
+ case extension
66
+ when '.jpg', '.jpeg'
67
+ header[0..2].bytes == [0xFF, 0xD8, 0xFF] # JPEG magic bytes
68
+ when '.png'
69
+ header[0..7].bytes == [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A] # PNG magic bytes
70
+ when '.gif'
71
+ header[0..2] == 'GIF' # GIF magic bytes
72
+ else
73
+ false
74
+ end
75
+ rescue StandardError
76
+ false
77
+ end
78
+ end
9
79
  end
10
80
  end
11
81
  end
@@ -1,15 +1,16 @@
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.
4
6
  module OptionsParser
5
-
6
7
  # Parses an options hash by calling any defined method by the same
7
8
  # name of the key postfixed with an '='
8
9
  # @param [Hash] options Options to parse.
9
- def parse_options(options={})
10
+ def parse_options(options = {})
10
11
  options.each do |key, value|
11
12
  key = :"#{key}="
12
- self.send(key, value) if !value.nil? && self.respond_to?(key)
13
+ send(key, value) if !value.nil? && respond_to?(key)
13
14
  end
14
15
  end
15
16
  end