summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util/constants.rb
blob: 1c5c00335b90bfc97cbc39241e56c81834dbe055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# frozen_string_literal: true

module Axlsx
  # XML Encoding
  ENCODING = "UTF-8"

  # spreadsheetML namespace
  XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"

  # content-types namespace
  XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types"

  # extended-properties namespace
  APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"

  # doc props namespace
  APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"

  # core properties namespace
  CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"

  # dc elements (core) namespace
  CORE_NS_DC = "http://purl.org/dc/elements/1.1/"

  # dcmit (core) namespcace
  CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"

  # dc terms namespace
  CORE_NS_DCT = "http://purl.org/dc/terms/"

  # xml schema namespace
  CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"

  # Digital signature namespace
  DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"

  # spreadsheet drawing namespace
  XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"

  # drawing namespace
  XML_NS_A  = "http://schemas.openxmlformats.org/drawingml/2006/main"

  # chart namespace
  XML_NS_C  = "http://schemas.openxmlformats.org/drawingml/2006/chart"

  # relationships namespace
  XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"

  # relationships name space
  RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"

  # table rels namespace
  TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"

  # pivot table rels namespace
  PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"

  # pivot table cache definition namespace
  PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"

  # workbook rels namespace
  WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"

  # worksheet rels namespace
  WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"

  # app rels namespace
  APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"

  # core rels namespace
  CORE_R = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"

  # digital signature rels namespace
  DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"

  # styles rels namespace
  STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"

  # shared strings namespace
  SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"

  # drawing rels namespace
  DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"

  # chart rels namespace
  CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"

  # image rels namespace
  IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"

  # hyperlink rels namespace
  HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"

  # comment rels namespace
  COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"

  # comment relation for nil target
  COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"

  # vml drawing relation namespace
  VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'

  # VML Drawing content type
  VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"

  # table content type
  TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"

  # pivot table content type
  PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"

  # pivot table cache definition content type
  PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"

  # workbook content type
  WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"

  # app content type
  APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"

  # rels content type
  RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"

  # styles content type
  STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"

  # xml content type
  XML_CT = "application/xml"

  # worksheet content type
  WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"

  # shared strings content type
  SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"

  # core content type
  CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"

  # digital signature xml content type
  DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"

  # digital signature origin content type
  DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"

  # digital signature certificate content type
  DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"

  # chart content type
  CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"

  # comments content type
  COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"

  # jpeg content type
  JPEG_CT = "image/jpeg"

  # gif content type
  GIF_CT = "image/gif"

  # png content type
  PNG_CT = "image/png"

  # drawing content type
  DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"

  # xml content type extensions
  XML_EX = "xml"

  # jpeg extensions
  JPEG_EXS = ["jpeg", "jpg"].freeze

  # gif extension
  GIF_EX = "gif"

  # png extension
  PNG_EX = "png"

  # rels content type extension
  RELS_EX = "rels"

  # workbook part
  WORKBOOK_PN = "xl/workbook.xml"

  # styles part
  STYLES_PN = "styles.xml"

  # shared_strings  part
  SHARED_STRINGS_PN = "sharedStrings.xml"

  # app part
  APP_PN = "docProps/app.xml"

  # core part
  CORE_PN = "docProps/core.xml"

  # content types part
  CONTENT_TYPES_PN = "[Content_Types].xml"

  # rels part
  RELS_PN = "_rels/.rels"

  # workbook rels part
  WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"

  # worksheet part
  WORKSHEET_PN = "worksheets/sheet%d.xml"

  # worksheet rels part
  WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"

  # drawing part
  DRAWING_PN = "drawings/drawing%d.xml"

  # drawing rels part
  DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"

  # vml drawing part
  VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"

  # drawing part
  TABLE_PN = "tables/table%d.xml"

  # pivot table parts
  PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"

  # pivot table cache definition part name
  PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"

  # pivot table rels parts
  PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"

  # chart part
  CHART_PN = "charts/chart%d.xml"

  # chart part
  IMAGE_PN = "media/image%d.%s"

  # comment part
  COMMENT_PN = "comments%d.xml"

  # location of schema files for validation
  SCHEMA_BASE = "#{File.dirname(__FILE__)}/../../schema/"

  # App validation schema
  APP_XSD = "#{SCHEMA_BASE}shared-documentPropertiesExtended.xsd"

  # core validation schema
  CORE_XSD = "#{SCHEMA_BASE}opc-coreProperties.xsd"

  # content types validation schema
  CONTENT_TYPES_XSD = "#{SCHEMA_BASE}opc-contentTypes.xsd"

  # rels validation schema
  RELS_XSD = "#{SCHEMA_BASE}opc-relationships.xsd"

  # spreadsheetML validation schema
  SML_XSD = "#{SCHEMA_BASE}sml.xsd"

  # drawing validation schema
  DRAWING_XSD = "#{SCHEMA_BASE}dml-spreadsheetDrawing.xsd"

  # number format id for pecentage formatting using the default formatting id.
  NUM_FMT_PERCENT = 9

  # number format id for date format like 2011/11/13
  NUM_FMT_YYYYMMDD = 100

  # number format id for time format the creates 2011/11/13 12:23:10
  NUM_FMT_YYYYMMDDHHMMSS = 101

  # cellXfs id for thin borders around the cell
  STYLE_THIN_BORDER = 1

  # cellXfs id for default date styling
  STYLE_DATE = 2

  # worksheet maximum name length
  WORKSHEET_MAX_NAME_LENGTH = 31

  # worksheet name forbidden characters
  WORKSHEET_NAME_FORBIDDEN_CHARS = '[]*/\?:'.chars.freeze

  # error messages RestrictionValidor
  ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."

  # error message DataTypeValidator
  ERR_TYPE = "Invalid Data %s for %s. must be %s."

  # error message for RegexValidator
  ERR_REGEX = "Invalid Data. %s does not match %s."

  # error message for RangeValidator
  ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"

  # error message for sheets that use explicit empty string name
  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."

  # error message for sheets that use a name which is longer than 31 bytes
  ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be #{WORKSHEET_MAX_NAME_LENGTH} characters (bytes) or less"

  # error message for sheets that use a name which include invalid characters
  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."

  # error message for duplicate sheet names
  ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"

  # error message when user does not provide color and or style options for border in Style#add_sytle
  ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"

  # error message for invalid border id reference
  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."

  # error message for invalid angles
  ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"

  # error message for non 'integerish' value
  ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"

  # error message for invalid cell reference
  ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`"

  # error message for cell reference with last cell missing
  ERR_CELL_REFERENCE_MISSING_CELL = "Missing cell `%s` for the specified range `%s`"

  # Regex to match forbidden control characters
  # The following will be automatically stripped from worksheets.
  #
  # x00 Null
  # x01 Start Of Heading
  # x02 Start Of Text
  # x03End Of Text
  # x04 End Of Transmission
  # x05 Enquiry
  # x06 Acknowledge
  # x07 Bell
  # x08 Backspace
  # x0B Line Tabulation
  # x0C Form Feed
  # x0E Shift Out
  # x0F Shift In
  # x10 Data Link Escape
  # x11 Device Control One
  # x12 Device Control Two
  # x13 Device Control Three
  # x14 Device Control Four
  # x15 Negative Acknowledge
  # x16 Synchronous Idle
  # x17 End Of Transmission Block
  # x18 Cancel
  # x19 End Of Medium
  # x1A Substitute
  # x1B Escape
  # x1C Information Separator Four
  # x1D Information Separator Three
  # x1E Information Separator Two
  # x1F Information Separator One
  #
  # The following are not dealt with.
  # If you have this in your data, expect Excel to blow up!
  #
  # x7F	Delete
  # x80	Control 0080
  # x81	Control 0081
  # x82	Break Permitted Here
  # x83	No Break Here
  # x84	Control 0084
  # x85	Next Line (Nel)
  # x86	Start Of Selected Area
  # x87	End Of Selected Area
  # x88	Character Tabulation Set
  # x89	Character Tabulation With Justification
  # x8A	Line Tabulation Set
  # x8B	Partial Line Forward
  # x8C	Partial Line Backward
  # x8D	Reverse Line Feed
  # x8E	Single Shift Two
  # x8F	Single Shift Three
  # x90	Device Control String
  # x91	Private Use One
  # x92	Private Use Two
  # x93	Set Transmit State
  # x94	Cancel Character
  # x95	Message Waiting
  # x96	Start Of Guarded Area
  # x97	End Of Guarded Area
  # x98	Start Of String
  # x99	Control 0099
  # x9A	Single Character Introducer
  # x9B	Control Sequence Introducer
  # x9C	String Terminator
  # x9D	Operating System Command
  # x9E	Privacy Message
  # x9F	Application Program Command
  #
  # The following are allowed:
  #
  # x0A Line Feed (Lf)
  # x0D Carriage Return (Cr)
  # x09 Character Tabulation
  # @see https://www.codetable.net/asciikeycodes
  pattern = "\x0-\x08\x0B\x0C\x0E-\x1F".encode('UTF-8')

  # The regular expression used to remove control characters from worksheets
  CONTROL_CHARS = pattern.freeze

  # ISO 8601 date recognition
  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

  # FLOAT recognition
  SAFE_FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]{1,2})?\Z/.freeze
  MAYBE_FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+[eE](?<exp>[-+]?[0-9]{3})\Z/.freeze

  # Numeric recognition
  NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze

  # Leading characters that indicate a formula.
  # See: https://owasp.org/www-community/attacks/CSV_Injection
  FORMULA_PREFIX = '='

  # Leading characters that indicate an array formula.
  ARRAY_FORMULA_PREFIX = '{='

  # Trailing character that indicates an array formula.
  ARRAY_FORMULA_SUFFIX = '}'

  BOOLEAN_VALUES = [true, false].freeze
end