caxlsx 3.3.0 → 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 +25 -0
- data/README.md +25 -7
- data/Rakefile +7 -6
- data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
- data/lib/axlsx/content_type/content_type.rb +7 -9
- data/lib/axlsx/content_type/default.rb +4 -6
- data/lib/axlsx/content_type/override.rb +3 -5
- data/lib/axlsx/doc_props/app.rb +27 -30
- data/lib/axlsx/doc_props/core.rb +9 -12
- data/lib/axlsx/drawing/area_chart.rb +13 -14
- data/lib/axlsx/drawing/area_series.rb +13 -14
- data/lib/axlsx/drawing/ax_data_source.rb +3 -6
- data/lib/axlsx/drawing/axes.rb +10 -9
- data/lib/axlsx/drawing/axis.rb +27 -30
- data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
- data/lib/axlsx/drawing/bar_chart.rb +16 -17
- data/lib/axlsx/drawing/bar_series.rb +9 -13
- data/lib/axlsx/drawing/bubble_chart.rb +8 -9
- data/lib/axlsx/drawing/bubble_series.rb +9 -10
- data/lib/axlsx/drawing/cat_axis.rb +14 -17
- data/lib/axlsx/drawing/chart.rb +25 -28
- data/lib/axlsx/drawing/d_lbls.rb +29 -26
- data/lib/axlsx/drawing/drawing.rb +60 -62
- data/lib/axlsx/drawing/graphic_frame.rb +6 -7
- data/lib/axlsx/drawing/hyperlink.rb +12 -13
- data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
- data/lib/axlsx/drawing/line_chart.rb +13 -14
- data/lib/axlsx/drawing/line_series.rb +13 -14
- data/lib/axlsx/drawing/marker.rb +14 -16
- data/lib/axlsx/drawing/num_data.rb +13 -16
- data/lib/axlsx/drawing/num_data_source.rb +11 -13
- data/lib/axlsx/drawing/num_val.rb +9 -10
- data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
- data/lib/axlsx/drawing/pic.rb +57 -22
- data/lib/axlsx/drawing/picture_locking.rb +6 -7
- data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
- data/lib/axlsx/drawing/pie_series.rb +9 -12
- data/lib/axlsx/drawing/scaling.rb +9 -10
- data/lib/axlsx/drawing/scatter_chart.rb +9 -10
- data/lib/axlsx/drawing/scatter_series.rb +15 -16
- data/lib/axlsx/drawing/ser_axis.rb +9 -11
- data/lib/axlsx/drawing/series.rb +8 -8
- data/lib/axlsx/drawing/series_title.rb +6 -6
- data/lib/axlsx/drawing/str_data.rb +10 -13
- data/lib/axlsx/drawing/str_val.rb +8 -9
- data/lib/axlsx/drawing/title.rb +23 -27
- data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
- data/lib/axlsx/drawing/val_axis.rb +5 -6
- data/lib/axlsx/drawing/view_3D.rb +32 -30
- data/lib/axlsx/drawing/vml_drawing.rb +19 -20
- data/lib/axlsx/drawing/vml_shape.rb +25 -26
- data/lib/axlsx/package.rb +81 -79
- data/lib/axlsx/rels/relationship.rb +30 -28
- data/lib/axlsx/rels/relationships.rb +7 -8
- data/lib/axlsx/stylesheet/border.rb +7 -8
- data/lib/axlsx/stylesheet/border_pr.rb +8 -8
- data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
- data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
- data/lib/axlsx/stylesheet/cell_style.rb +12 -14
- data/lib/axlsx/stylesheet/color.rb +15 -12
- data/lib/axlsx/stylesheet/dxf.rb +7 -9
- data/lib/axlsx/stylesheet/fill.rb +3 -5
- data/lib/axlsx/stylesheet/font.rb +24 -21
- data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
- data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
- data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
- data/lib/axlsx/stylesheet/styles.rb +104 -98
- data/lib/axlsx/stylesheet/table_style.rb +8 -9
- data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
- data/lib/axlsx/stylesheet/table_styles.rb +8 -10
- data/lib/axlsx/stylesheet/xf.rb +21 -22
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
- data/lib/axlsx/util/constants.rb +119 -108
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +4 -3
- data/lib/axlsx/util/serialized_attributes.rb +45 -21
- data/lib/axlsx/util/simple_typed_list.rb +58 -57
- data/lib/axlsx/util/storage.rb +38 -41
- data/lib/axlsx/util/validators.rb +107 -44
- data/lib/axlsx/util/zip_command.rb +10 -12
- data/lib/axlsx/version.rb +3 -2
- data/lib/axlsx/workbook/defined_name.rb +11 -8
- data/lib/axlsx/workbook/defined_names.rb +4 -3
- data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
- data/lib/axlsx/workbook/workbook.rb +121 -114
- data/lib/axlsx/workbook/workbook_view.rb +8 -11
- data/lib/axlsx/workbook/workbook_views.rb +4 -4
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
- 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 +30 -25
- data/lib/axlsx/workbook/worksheet/break.rb +4 -5
- data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
- data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
- data/lib/axlsx/workbook/worksheet/col.rb +9 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
- data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
- data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
- data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
- data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
- data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
- data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
- data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
- data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
- data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
- data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
- data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
- data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
- data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
- data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
- data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
- data/lib/axlsx/workbook/worksheet/row.rb +30 -22
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
- data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
- data/lib/axlsx/workbook/worksheet/table.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
- data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
- data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
- data/lib/axlsx.rb +75 -47
- data/lib/caxlsx.rb +3 -2
- metadata +50 -44
data/lib/axlsx/util/accessors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# This module defines some of the more common validating attribute
|
3
5
|
# accessors that we use in Axlsx
|
@@ -14,7 +16,6 @@ module Axlsx
|
|
14
16
|
|
15
17
|
# Defines the class level xxx_attr_accessor methods
|
16
18
|
module ClassMethods
|
17
|
-
|
18
19
|
# Creates one or more string validated attr_accessors
|
19
20
|
# @param [Array] symbols An array of symbols representing the
|
20
21
|
# names of the attributes you will add to your class.
|
@@ -22,7 +23,6 @@ module Axlsx
|
|
22
23
|
validated_attr_accessor(symbols, :validate_string)
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
26
|
# Creates one or more usigned integer attr_accessors
|
27
27
|
# @param [Array] symbols An array of symbols representing the
|
28
28
|
# names of the attributes you will add to your class
|
@@ -45,20 +45,20 @@ module Axlsx
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Template for defining validated write accessors
|
48
|
-
SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
|
48
|
+
SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
|
49
49
|
|
50
50
|
# Creates the reader and writer access methods
|
51
51
|
# @param [Array] symbols The names of the attributes to create
|
52
52
|
# @param [String] validator The axlsx validation method to use when
|
53
53
|
# validating assignation.
|
54
|
-
# @see lib/axlsx/util/validators.rb
|
54
|
+
# @see lib/axlsx/util/validators.rb
|
55
55
|
def validated_attr_accessor(symbols, validator)
|
56
56
|
symbols.each do |symbol|
|
57
57
|
attr_reader symbol
|
58
|
-
|
58
|
+
|
59
|
+
module_eval(format(SETTER, symbol, validator, symbol), __FILE__, __LINE__)
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
64
|
-
|
@@ -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,263 +1,263 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Axlsx
|
3
4
|
# XML Encoding
|
4
|
-
ENCODING = "UTF-8"
|
5
|
+
ENCODING = "UTF-8"
|
5
6
|
|
6
7
|
# spreadsheetML namespace
|
7
|
-
XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
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"
|
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"
|
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"
|
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"
|
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/"
|
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/"
|
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/"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
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"
|
80
|
+
SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
80
81
|
|
81
82
|
# drawing rels namespace
|
82
|
-
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
|
83
|
+
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
|
83
84
|
|
84
85
|
# chart rels namespace
|
85
|
-
CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
|
86
|
+
CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
|
86
87
|
|
87
88
|
# image rels namespace
|
88
|
-
IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
89
|
+
IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
89
90
|
|
90
91
|
# hyperlink rels namespace
|
91
|
-
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
92
|
+
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
92
93
|
|
93
94
|
# comment rels namespace
|
94
|
-
COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
|
95
|
+
COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
|
95
96
|
|
96
97
|
# comment relation for nil target
|
97
|
-
COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
|
98
|
+
COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
|
98
99
|
|
99
|
-
#vml drawing relation namespace
|
100
|
+
# vml drawing relation namespace
|
100
101
|
VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'
|
101
102
|
|
102
103
|
# VML Drawing content type
|
103
|
-
VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
|
104
|
+
VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
|
104
105
|
|
105
106
|
# table content type
|
106
|
-
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
|
107
|
+
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
|
107
108
|
|
108
109
|
# pivot table content type
|
109
|
-
PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
|
110
|
+
PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
|
110
111
|
|
111
112
|
# pivot table cache definition content type
|
112
|
-
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"
|
113
114
|
|
114
115
|
# workbook content type
|
115
|
-
WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
116
|
+
WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
116
117
|
|
117
118
|
# app content type
|
118
|
-
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
119
|
+
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
119
120
|
|
120
121
|
# rels content type
|
121
|
-
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
122
|
+
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
122
123
|
|
123
124
|
# styles content type
|
124
|
-
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
125
|
+
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
125
126
|
|
126
127
|
# xml content type
|
127
|
-
XML_CT = "application/xml"
|
128
|
+
XML_CT = "application/xml"
|
128
129
|
|
129
130
|
# worksheet content type
|
130
|
-
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
131
|
+
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
131
132
|
|
132
133
|
# shared strings content type
|
133
|
-
SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
134
|
+
SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
134
135
|
|
135
136
|
# core content type
|
136
|
-
CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
|
137
|
+
CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
|
137
138
|
|
138
139
|
# digital signature xml content type
|
139
|
-
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"
|
140
141
|
|
141
142
|
# digital signature origin content type
|
142
|
-
DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
|
143
|
+
DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
|
143
144
|
|
144
145
|
# digital signature certificate content type
|
145
|
-
DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
|
146
|
+
DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
|
146
147
|
|
147
148
|
# chart content type
|
148
|
-
CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
|
149
|
+
CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
|
149
150
|
|
150
151
|
# comments content type
|
151
|
-
COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
|
152
|
+
COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
|
152
153
|
|
153
154
|
# jpeg content type
|
154
|
-
JPEG_CT = "image/jpeg"
|
155
|
+
JPEG_CT = "image/jpeg"
|
155
156
|
|
156
157
|
# gif content type
|
157
|
-
GIF_CT = "image/gif"
|
158
|
+
GIF_CT = "image/gif"
|
158
159
|
|
159
160
|
# png content type
|
160
|
-
PNG_CT = "image/png"
|
161
|
-
|
162
|
-
#drawing content type
|
163
|
-
DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml".freeze
|
161
|
+
PNG_CT = "image/png"
|
164
162
|
|
163
|
+
# drawing content type
|
164
|
+
DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
|
165
165
|
|
166
166
|
# xml content type extensions
|
167
|
-
XML_EX = "xml"
|
167
|
+
XML_EX = "xml"
|
168
168
|
|
169
|
-
# jpeg
|
170
|
-
|
169
|
+
# jpeg extensions
|
170
|
+
JPEG_EXS = ["jpeg", "jpg"].freeze
|
171
171
|
|
172
172
|
# gif extension
|
173
|
-
GIF_EX = "gif"
|
173
|
+
GIF_EX = "gif"
|
174
174
|
|
175
175
|
# png extension
|
176
|
-
PNG_EX = "png"
|
176
|
+
PNG_EX = "png"
|
177
177
|
|
178
178
|
# rels content type extension
|
179
|
-
RELS_EX = "rels"
|
179
|
+
RELS_EX = "rels"
|
180
180
|
|
181
181
|
# workbook part
|
182
|
-
WORKBOOK_PN = "xl/workbook.xml"
|
182
|
+
WORKBOOK_PN = "xl/workbook.xml"
|
183
183
|
|
184
184
|
# styles part
|
185
|
-
STYLES_PN = "styles.xml"
|
185
|
+
STYLES_PN = "styles.xml"
|
186
186
|
|
187
187
|
# shared_strings part
|
188
|
-
SHARED_STRINGS_PN = "sharedStrings.xml"
|
188
|
+
SHARED_STRINGS_PN = "sharedStrings.xml"
|
189
189
|
|
190
190
|
# app part
|
191
|
-
APP_PN = "docProps/app.xml"
|
191
|
+
APP_PN = "docProps/app.xml"
|
192
192
|
|
193
193
|
# core part
|
194
|
-
CORE_PN = "docProps/core.xml"
|
194
|
+
CORE_PN = "docProps/core.xml"
|
195
195
|
|
196
196
|
# content types part
|
197
|
-
CONTENT_TYPES_PN = "[Content_Types].xml"
|
197
|
+
CONTENT_TYPES_PN = "[Content_Types].xml"
|
198
198
|
|
199
199
|
# rels part
|
200
|
-
RELS_PN = "_rels/.rels"
|
200
|
+
RELS_PN = "_rels/.rels"
|
201
201
|
|
202
202
|
# workbook rels part
|
203
|
-
WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
|
203
|
+
WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
|
204
204
|
|
205
205
|
# worksheet part
|
206
|
-
WORKSHEET_PN = "worksheets/sheet%d.xml"
|
206
|
+
WORKSHEET_PN = "worksheets/sheet%d.xml"
|
207
207
|
|
208
208
|
# worksheet rels part
|
209
|
-
WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
|
209
|
+
WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
|
210
210
|
|
211
211
|
# drawing part
|
212
|
-
DRAWING_PN = "drawings/drawing%d.xml"
|
212
|
+
DRAWING_PN = "drawings/drawing%d.xml"
|
213
213
|
|
214
214
|
# drawing rels part
|
215
|
-
DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
|
215
|
+
DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
|
216
216
|
|
217
217
|
# vml drawing part
|
218
|
-
VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
|
218
|
+
VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
|
219
219
|
|
220
220
|
# drawing part
|
221
|
-
TABLE_PN = "tables/table%d.xml"
|
221
|
+
TABLE_PN = "tables/table%d.xml"
|
222
222
|
|
223
223
|
# pivot table parts
|
224
|
-
PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
|
224
|
+
PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
|
225
225
|
|
226
226
|
# pivot table cache definition part name
|
227
|
-
PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
|
227
|
+
PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
|
228
228
|
|
229
229
|
# pivot table rels parts
|
230
|
-
PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
|
230
|
+
PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
|
231
231
|
|
232
232
|
# chart part
|
233
|
-
CHART_PN = "charts/chart%d.xml"
|
233
|
+
CHART_PN = "charts/chart%d.xml"
|
234
234
|
|
235
235
|
# chart part
|
236
|
-
IMAGE_PN = "media/image%d.%s"
|
236
|
+
IMAGE_PN = "media/image%d.%s"
|
237
237
|
|
238
238
|
# comment part
|
239
|
-
COMMENT_PN = "comments%d.xml"
|
239
|
+
COMMENT_PN = "comments%d.xml"
|
240
240
|
|
241
241
|
# location of schema files for validation
|
242
|
-
SCHEMA_BASE =
|
242
|
+
SCHEMA_BASE = "#{File.dirname(__FILE__)}/../../schema/"
|
243
243
|
|
244
244
|
# App validation schema
|
245
|
-
APP_XSD =
|
245
|
+
APP_XSD = "#{SCHEMA_BASE}shared-documentPropertiesExtended.xsd"
|
246
246
|
|
247
247
|
# core validation schema
|
248
|
-
CORE_XSD =
|
248
|
+
CORE_XSD = "#{SCHEMA_BASE}opc-coreProperties.xsd"
|
249
249
|
|
250
250
|
# content types validation schema
|
251
|
-
CONTENT_TYPES_XSD =
|
251
|
+
CONTENT_TYPES_XSD = "#{SCHEMA_BASE}opc-contentTypes.xsd"
|
252
252
|
|
253
253
|
# rels validation schema
|
254
|
-
RELS_XSD =
|
254
|
+
RELS_XSD = "#{SCHEMA_BASE}opc-relationships.xsd"
|
255
255
|
|
256
256
|
# spreadsheetML validation schema
|
257
|
-
SML_XSD =
|
257
|
+
SML_XSD = "#{SCHEMA_BASE}sml.xsd"
|
258
258
|
|
259
259
|
# drawing validation schema
|
260
|
-
DRAWING_XSD =
|
260
|
+
DRAWING_XSD = "#{SCHEMA_BASE}dml-spreadsheetDrawing.xsd"
|
261
261
|
|
262
262
|
# number format id for pecentage formatting using the default formatting id.
|
263
263
|
NUM_FMT_PERCENT = 9
|
@@ -281,46 +281,46 @@ module Axlsx
|
|
281
281
|
WORKSHEET_NAME_FORBIDDEN_CHARS = '[]*/\?:'.chars.freeze
|
282
282
|
|
283
283
|
# error messages RestrictionValidor
|
284
|
-
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
284
|
+
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
285
285
|
|
286
286
|
# error message DataTypeValidator
|
287
|
-
ERR_TYPE = "Invalid Data %s for %s. must be %s."
|
287
|
+
ERR_TYPE = "Invalid Data %s for %s. must be %s."
|
288
288
|
|
289
289
|
# error message for RegexValidator
|
290
|
-
ERR_REGEX = "Invalid Data. %s does not match %s."
|
290
|
+
ERR_REGEX = "Invalid Data. %s does not match %s."
|
291
291
|
|
292
292
|
# error message for RangeValidator
|
293
|
-
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"
|
294
294
|
|
295
295
|
# 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."
|
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."
|
297
297
|
|
298
298
|
# 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"
|
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"
|
300
300
|
|
301
301
|
# 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."
|
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."
|
303
303
|
|
304
304
|
# 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"
|
305
|
+
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
|
306
306
|
|
307
307
|
# 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"
|
308
|
+
ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
|
309
309
|
|
310
310
|
# 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."
|
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."
|
312
312
|
|
313
313
|
# error message for invalid angles
|
314
|
-
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"
|
315
315
|
|
316
316
|
# error message for non 'integerish' value
|
317
|
-
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"
|
318
318
|
|
319
319
|
# error message for invalid cell reference
|
320
|
-
ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`"
|
320
|
+
ERR_CELL_REFERENCE_INVALID = "Invalid cell definition `%s`"
|
321
321
|
|
322
322
|
# error message for cell reference with last cell missing
|
323
|
-
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`"
|
324
324
|
|
325
325
|
# Regex to match forbidden control characters
|
326
326
|
# The following will be automatically stripped from worksheets.
|
@@ -356,7 +356,7 @@ module Axlsx
|
|
356
356
|
# x1F Information Separator One
|
357
357
|
#
|
358
358
|
# The following are not dealt with.
|
359
|
-
# If you have this in your data, expect
|
359
|
+
# If you have this in your data, expect Excel to blow up!
|
360
360
|
#
|
361
361
|
# x7F Delete
|
362
362
|
# x80 Control 0080
|
@@ -397,9 +397,8 @@ module Axlsx
|
|
397
397
|
# x0A Line Feed (Lf)
|
398
398
|
# x0D Carriage Return (Cr)
|
399
399
|
# x09 Character Tabulation
|
400
|
-
# @see
|
401
|
-
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
|
402
|
-
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)
|
403
402
|
|
404
403
|
# The regular expression used to remove control characters from worksheets
|
405
404
|
CONTROL_CHARS = pattern.freeze
|
@@ -413,4 +412,16 @@ module Axlsx
|
|
413
412
|
|
414
413
|
# Numeric recognition
|
415
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
|
416
427
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
|
1
5
|
module Axlsx
|
2
6
|
# This module defines some utils related with mime type detection
|
3
7
|
module MimeTypeUtils
|
@@ -7,5 +11,12 @@ module Axlsx
|
|
7
11
|
def self.get_mime_type(v)
|
8
12
|
Marcel::MimeType.for(Pathname.new(v))
|
9
13
|
end
|
14
|
+
|
15
|
+
# Detect a file mime type from URI
|
16
|
+
# @param [String] v URI
|
17
|
+
# @return [String] File mime type
|
18
|
+
def self.get_mime_type_from_uri(v)
|
19
|
+
Marcel::MimeType.for(URI.parse(v).open)
|
20
|
+
end
|
10
21
|
end
|
11
22
|
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
|
-
|
13
|
+
send(key, value) if !value.nil? && respond_to?(key)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|