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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +87 -11
- data/README.md +43 -16
- data/Rakefile +5 -11
- data/examples/generate.rb +3 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
- data/lib/axlsx/content_type/content_type.rb +8 -10
- data/lib/axlsx/content_type/default.rb +7 -6
- data/lib/axlsx/content_type/override.rb +6 -5
- data/lib/axlsx/doc_props/app.rb +96 -32
- data/lib/axlsx/doc_props/core.rb +9 -12
- data/lib/axlsx/drawing/area_chart.rb +16 -17
- data/lib/axlsx/drawing/area_series.rb +23 -18
- data/lib/axlsx/drawing/ax_data_source.rb +4 -7
- data/lib/axlsx/drawing/axes.rb +11 -10
- data/lib/axlsx/drawing/axis.rb +83 -36
- data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
- data/lib/axlsx/drawing/bar_chart.rb +29 -20
- data/lib/axlsx/drawing/bar_series.rb +23 -18
- data/lib/axlsx/drawing/bubble_chart.rb +9 -10
- data/lib/axlsx/drawing/bubble_series.rb +11 -12
- data/lib/axlsx/drawing/cat_axis.rb +38 -28
- data/lib/axlsx/drawing/chart.rb +52 -30
- data/lib/axlsx/drawing/d_lbls.rb +36 -32
- data/lib/axlsx/drawing/drawing.rb +61 -62
- data/lib/axlsx/drawing/graphic_frame.rb +6 -7
- data/lib/axlsx/drawing/hyperlink.rb +22 -14
- data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
- data/lib/axlsx/drawing/line_chart.rb +16 -17
- data/lib/axlsx/drawing/line_series.rb +23 -18
- data/lib/axlsx/drawing/marker.rb +29 -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 +10 -11
- data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
- data/lib/axlsx/drawing/pic.rb +68 -24
- data/lib/axlsx/drawing/picture_locking.rb +6 -7
- data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
- data/lib/axlsx/drawing/pie_chart.rb +36 -0
- data/lib/axlsx/drawing/pie_series.rb +26 -17
- data/lib/axlsx/drawing/scaling.rb +26 -13
- data/lib/axlsx/drawing/scatter_chart.rb +10 -11
- data/lib/axlsx/drawing/scatter_series.rb +17 -18
- data/lib/axlsx/drawing/ser_axis.rb +22 -19
- data/lib/axlsx/drawing/series.rb +14 -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 +9 -9
- data/lib/axlsx/drawing/val_axis.rb +7 -8
- data/lib/axlsx/drawing/view_3D.rb +38 -30
- data/lib/axlsx/drawing/vml_drawing.rb +19 -20
- data/lib/axlsx/drawing/vml_shape.rb +25 -26
- data/lib/axlsx/package.rb +134 -99
- data/lib/axlsx/rels/relationship.rb +42 -30
- data/lib/axlsx/rels/relationships.rb +9 -10
- data/lib/axlsx/stylesheet/border.rb +16 -8
- data/lib/axlsx/stylesheet/border_pr.rb +24 -12
- data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
- data/lib/axlsx/stylesheet/cell_style.rb +36 -15
- data/lib/axlsx/stylesheet/color.rb +23 -14
- data/lib/axlsx/stylesheet/dxf.rb +36 -15
- data/lib/axlsx/stylesheet/fill.rb +7 -6
- data/lib/axlsx/stylesheet/font.rb +71 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
- data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
- data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
- data/lib/axlsx/stylesheet/styles.rb +167 -118
- data/lib/axlsx/stylesheet/table_style.rb +20 -10
- data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
- data/lib/axlsx/stylesheet/table_styles.rb +16 -11
- data/lib/axlsx/stylesheet/theme.rb +163 -0
- data/lib/axlsx/stylesheet/xf.rb +78 -25
- data/lib/axlsx/util/accessors.rb +13 -11
- data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
- data/lib/axlsx/util/constants.rb +133 -110
- data/lib/axlsx/util/mime_type_utils.rb +75 -5
- data/lib/axlsx/util/options_parser.rb +4 -3
- data/lib/axlsx/util/serialized_attributes.rb +47 -23
- data/lib/axlsx/util/simple_typed_list.rb +77 -64
- data/lib/axlsx/util/storage.rb +38 -41
- data/lib/axlsx/util/uri_utils.rb +70 -0
- data/lib/axlsx/util/validators.rb +111 -48
- data/lib/axlsx/util/zip_command.rb +10 -12
- data/lib/axlsx/version.rb +3 -2
- data/lib/axlsx/workbook/defined_name.rb +13 -9
- data/lib/axlsx/workbook/defined_names.rb +5 -4
- data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
- data/lib/axlsx/workbook/workbook.rb +152 -120
- data/lib/axlsx/workbook/workbook_view.rb +9 -12
- data/lib/axlsx/workbook/workbook_views.rb +5 -5
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
- data/lib/axlsx/workbook/worksheet/break.rb +4 -5
- data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
- data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
- data/lib/axlsx/workbook/worksheet/col.rb +32 -19
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
- data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
- data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
- data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
- data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
- data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
- data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
- data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
- data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
- data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
- data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
- data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
- data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
- data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
- data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
- data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
- data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
- data/lib/axlsx/workbook/worksheet/row.rb +34 -23
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
- data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -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 +12 -8
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
- data/lib/axlsx/workbook/worksheet/table.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
- data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
- data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
- data/lib/axlsx.rb +120 -60
- data/lib/caxlsx.rb +3 -2
- metadata +42 -75
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module Axlsx
|
|
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
|
-
|
|
4
|
+
autoload :SheetCalcPr, 'axlsx/workbook/worksheet/sheet_calc_pr'
|
|
5
|
+
autoload :AutoFilter, 'axlsx/workbook/worksheet/auto_filter/auto_filter'
|
|
6
|
+
autoload :FilterColumn, 'axlsx/workbook/worksheet/auto_filter/filter_column'
|
|
7
|
+
autoload :Filters, 'axlsx/workbook/worksheet/auto_filter/filters'
|
|
8
|
+
autoload :SortState, 'axlsx/workbook/worksheet/auto_filter/sort_state'
|
|
9
|
+
autoload :SortCondition, 'axlsx/workbook/worksheet/auto_filter/sort_condition'
|
|
10
|
+
autoload :DateTimeConverter, 'axlsx/workbook/worksheet/date_time_converter'
|
|
11
|
+
autoload :ProtectedRange, 'axlsx/workbook/worksheet/protected_range'
|
|
12
|
+
autoload :ProtectedRanges, 'axlsx/workbook/worksheet/protected_ranges'
|
|
13
|
+
autoload :RichTextRun, 'axlsx/workbook/worksheet/rich_text_run'
|
|
14
|
+
autoload :RichText, 'axlsx/workbook/worksheet/rich_text'
|
|
15
|
+
autoload :CellSerializer, 'axlsx/workbook/worksheet/cell_serializer'
|
|
16
|
+
autoload :Cell, 'axlsx/workbook/worksheet/cell'
|
|
17
|
+
autoload :PageMargins, 'axlsx/workbook/worksheet/page_margins'
|
|
18
|
+
autoload :PageSetUpPr, 'axlsx/workbook/worksheet/page_set_up_pr'
|
|
19
|
+
autoload :OutlinePr, 'axlsx/workbook/worksheet/outline_pr'
|
|
20
|
+
autoload :PageSetup, 'axlsx/workbook/worksheet/page_setup'
|
|
21
|
+
autoload :HeaderFooter, 'axlsx/workbook/worksheet/header_footer'
|
|
22
|
+
autoload :PrintOptions, 'axlsx/workbook/worksheet/print_options'
|
|
23
|
+
autoload :Cfvo, 'axlsx/workbook/worksheet/cfvo'
|
|
24
|
+
autoload :Cfvos, 'axlsx/workbook/worksheet/cfvos'
|
|
25
|
+
autoload :ColorScale, 'axlsx/workbook/worksheet/color_scale'
|
|
26
|
+
autoload :DataBar, 'axlsx/workbook/worksheet/data_bar'
|
|
27
|
+
autoload :IconSet, 'axlsx/workbook/worksheet/icon_set'
|
|
28
|
+
autoload :ConditionalFormatting, 'axlsx/workbook/worksheet/conditional_formatting'
|
|
29
|
+
autoload :ConditionalFormattingRule, 'axlsx/workbook/worksheet/conditional_formatting_rule'
|
|
30
|
+
autoload :ConditionalFormattings, 'axlsx/workbook/worksheet/conditional_formattings'
|
|
31
|
+
autoload :Row, 'axlsx/workbook/worksheet/row'
|
|
32
|
+
autoload :Col, 'axlsx/workbook/worksheet/col'
|
|
33
|
+
autoload :Cols, 'axlsx/workbook/worksheet/cols'
|
|
34
|
+
autoload :Comments, 'axlsx/workbook/worksheet/comments'
|
|
35
|
+
autoload :Comment, 'axlsx/workbook/worksheet/comment'
|
|
36
|
+
autoload :MergedCells, 'axlsx/workbook/worksheet/merged_cells'
|
|
37
|
+
autoload :SheetProtection, 'axlsx/workbook/worksheet/sheet_protection'
|
|
38
|
+
autoload :SheetPr, 'axlsx/workbook/worksheet/sheet_pr'
|
|
39
|
+
autoload :Dimension, 'axlsx/workbook/worksheet/dimension'
|
|
40
|
+
autoload :SheetData, 'axlsx/workbook/worksheet/sheet_data'
|
|
41
|
+
autoload :WorksheetDrawing, 'axlsx/workbook/worksheet/worksheet_drawing'
|
|
42
|
+
autoload :WorksheetComments, 'axlsx/workbook/worksheet/worksheet_comments'
|
|
43
|
+
autoload :WorksheetHyperlink, 'axlsx/workbook/worksheet/worksheet_hyperlink'
|
|
44
|
+
autoload :WorksheetHyperlinks, 'axlsx/workbook/worksheet/worksheet_hyperlinks'
|
|
45
|
+
autoload :Break, 'axlsx/workbook/worksheet/break'
|
|
46
|
+
autoload :RowBreaks, 'axlsx/workbook/worksheet/row_breaks'
|
|
47
|
+
autoload :ColBreaks, 'axlsx/workbook/worksheet/col_breaks'
|
|
48
|
+
autoload :WorkbookView, 'axlsx/workbook/workbook_view'
|
|
49
|
+
autoload :WorkbookViews, 'axlsx/workbook/workbook_views'
|
|
50
|
+
autoload :Worksheet, 'axlsx/workbook/worksheet/worksheet'
|
|
51
|
+
autoload :BorderCreator, 'axlsx/workbook/worksheet/border_creator'
|
|
52
|
+
autoload :SharedStringsTable, 'axlsx/workbook/shared_strings_table'
|
|
53
|
+
autoload :DefinedName, 'axlsx/workbook/defined_name'
|
|
54
|
+
autoload :DefinedNames, 'axlsx/workbook/defined_names'
|
|
55
|
+
autoload :TableStyleInfo, 'axlsx/workbook/worksheet/table_style_info'
|
|
56
|
+
autoload :Table, 'axlsx/workbook/worksheet/table'
|
|
57
|
+
autoload :Tables, 'axlsx/workbook/worksheet/tables'
|
|
58
|
+
autoload :PivotTableCacheDefinition, 'axlsx/workbook/worksheet/pivot_table_cache_definition'
|
|
59
|
+
autoload :PivotTable, 'axlsx/workbook/worksheet/pivot_table'
|
|
60
|
+
autoload :PivotTables, 'axlsx/workbook/worksheet/pivot_tables'
|
|
61
|
+
autoload :DataValidation, 'axlsx/workbook/worksheet/data_validation'
|
|
62
|
+
autoload :DataValidations, 'axlsx/workbook/worksheet/data_validations'
|
|
63
|
+
autoload :SheetView, 'axlsx/workbook/worksheet/sheet_view'
|
|
64
|
+
autoload :SheetFormatPr, 'axlsx/workbook/worksheet/sheet_format_pr'
|
|
65
|
+
autoload :Pane, 'axlsx/workbook/worksheet/pane'
|
|
66
|
+
autoload :Selection, 'axlsx/workbook/worksheet/selection'
|
|
67
|
+
|
|
63
68
|
# The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
|
|
64
|
-
# The following parts of the Office Open XML spreadsheet specification are not
|
|
69
|
+
# The following parts of the Office Open XML spreadsheet specification are not implemented in this version.
|
|
65
70
|
#
|
|
66
71
|
# bookViews
|
|
67
72
|
# calcPr
|
|
@@ -84,7 +89,6 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
84
89
|
#
|
|
85
90
|
# *workbookPr is only supported to the extend of date1904
|
|
86
91
|
class Workbook
|
|
87
|
-
|
|
88
92
|
BOLD_FONT_MULTIPLIER = 1.5
|
|
89
93
|
FONT_SCALE_DIVISOR = 10.0
|
|
90
94
|
|
|
@@ -96,7 +100,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
96
100
|
|
|
97
101
|
# @see use_shared_strings
|
|
98
102
|
def use_shared_strings=(v)
|
|
99
|
-
Axlsx
|
|
103
|
+
Axlsx.validate_boolean(v)
|
|
100
104
|
@use_shared_strings = v
|
|
101
105
|
end
|
|
102
106
|
|
|
@@ -105,33 +109,32 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
105
109
|
attr_reader :is_reversed
|
|
106
110
|
|
|
107
111
|
def is_reversed=(v)
|
|
108
|
-
Axlsx
|
|
112
|
+
Axlsx.validate_boolean(v)
|
|
109
113
|
@is_reversed = v
|
|
110
114
|
end
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
# A collection of worksheets associated with this workbook.
|
|
116
|
+
# A collection of worksheets associated with this workbook.
|
|
114
117
|
# @note The recommended way to manage worksheets is add_worksheet
|
|
115
118
|
# @see Workbook#add_worksheet
|
|
116
119
|
# @see Worksheet
|
|
117
120
|
# @return [SimpleTypedList]
|
|
118
121
|
attr_reader :worksheets
|
|
119
122
|
|
|
120
|
-
# A
|
|
123
|
+
# A collection of charts associated with this workbook
|
|
121
124
|
# @note The recommended way to manage charts is Worksheet#add_chart
|
|
122
125
|
# @see Worksheet#add_chart
|
|
123
126
|
# @see Chart
|
|
124
127
|
# @return [SimpleTypedList]
|
|
125
128
|
attr_reader :charts
|
|
126
129
|
|
|
127
|
-
# A
|
|
130
|
+
# A collection of images associated with this workbook
|
|
128
131
|
# @note The recommended way to manage images is Worksheet#add_image
|
|
129
132
|
# @see Worksheet#add_image
|
|
130
133
|
# @see Pic
|
|
131
134
|
# @return [SimpleTypedList]
|
|
132
135
|
attr_reader :images
|
|
133
136
|
|
|
134
|
-
# A
|
|
137
|
+
# A collection of drawings associated with this workbook
|
|
135
138
|
# @note The recommended way to manage drawings is Worksheet#add_chart
|
|
136
139
|
# @see Worksheet#add_chart
|
|
137
140
|
# @see Drawing
|
|
@@ -140,15 +143,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
140
143
|
|
|
141
144
|
# pretty sure this two are always empty and can be removed.
|
|
142
145
|
|
|
143
|
-
|
|
144
|
-
# A colllection of tables associated with this workbook
|
|
146
|
+
# A collection of tables associated with this workbook
|
|
145
147
|
# @note The recommended way to manage drawings is Worksheet#add_table
|
|
146
148
|
# @see Worksheet#add_table
|
|
147
149
|
# @see Table
|
|
148
150
|
# @return [SimpleTypedList]
|
|
149
151
|
attr_reader :tables
|
|
150
152
|
|
|
151
|
-
# A
|
|
153
|
+
# A collection of pivot tables associated with this workbook
|
|
152
154
|
# @note The recommended way to manage drawings is Worksheet#add_table
|
|
153
155
|
# @see Worksheet#add_table
|
|
154
156
|
# @see Table
|
|
@@ -174,7 +176,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
174
176
|
# @see Comment
|
|
175
177
|
# @return [Comments]
|
|
176
178
|
def comments
|
|
177
|
-
worksheets.map
|
|
179
|
+
worksheets.map(&:comments).compact
|
|
178
180
|
end
|
|
179
181
|
|
|
180
182
|
# The styles associated with this workbook
|
|
@@ -187,6 +189,12 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
187
189
|
@styles
|
|
188
190
|
end
|
|
189
191
|
|
|
192
|
+
# The theme associated with this workbook
|
|
193
|
+
# @return [Theme]
|
|
194
|
+
def theme
|
|
195
|
+
@theme ||= Theme.new
|
|
196
|
+
end
|
|
197
|
+
|
|
190
198
|
# An array that holds all cells with styles
|
|
191
199
|
# @return Set
|
|
192
200
|
def styled_cells
|
|
@@ -200,16 +208,16 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
200
208
|
# A helper to apply styles that were added using `worksheet.add_style`
|
|
201
209
|
# @return [Boolean]
|
|
202
210
|
def apply_styles
|
|
203
|
-
return false
|
|
211
|
+
return false unless styled_cells
|
|
204
212
|
|
|
205
213
|
styled_cells.each do |cell|
|
|
206
214
|
current_style = styles.style_index[cell.style]
|
|
207
215
|
|
|
208
|
-
if current_style
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
216
|
+
new_style = if current_style
|
|
217
|
+
Axlsx.hash_deep_merge(current_style, cell.raw_style)
|
|
218
|
+
else
|
|
219
|
+
cell.raw_style
|
|
220
|
+
end
|
|
213
221
|
|
|
214
222
|
cell.style = styles.add_style(new_style)
|
|
215
223
|
end
|
|
@@ -217,23 +225,21 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
217
225
|
self.styles_applied = true
|
|
218
226
|
end
|
|
219
227
|
|
|
220
|
-
|
|
221
228
|
# Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
|
|
222
229
|
@@date1904 = false
|
|
223
230
|
|
|
224
|
-
|
|
225
|
-
# A quick helper to retrive a worksheet by name
|
|
231
|
+
# A quick helper to retrieve a worksheet by name
|
|
226
232
|
# @param [String] name The name of the sheet you are looking for
|
|
227
233
|
# @return [Worksheet] The sheet found, or nil
|
|
228
234
|
def sheet_by_name(name)
|
|
229
|
-
|
|
230
|
-
@worksheets
|
|
235
|
+
encoded_name = Axlsx.coder.encode(name)
|
|
236
|
+
@worksheets.find { |sheet| sheet.name == encoded_name }
|
|
231
237
|
end
|
|
232
238
|
|
|
233
|
-
# Creates a new Workbook
|
|
234
|
-
# The
|
|
235
|
-
# @option options [Boolean] date1904
|
|
236
|
-
def initialize(options={})
|
|
239
|
+
# Creates a new Workbook.
|
|
240
|
+
# The recommended way to work with workbooks is via Package#workbook.
|
|
241
|
+
# @option options [Boolean] date1904 If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
|
|
242
|
+
def initialize(options = {})
|
|
237
243
|
@styles = Styles.new
|
|
238
244
|
@worksheets = SimpleTypedList.new Worksheet
|
|
239
245
|
@drawings = SimpleTypedList.new Drawing
|
|
@@ -243,40 +249,65 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
243
249
|
@tables = SimpleTypedList.new Table
|
|
244
250
|
@pivot_tables = SimpleTypedList.new PivotTable
|
|
245
251
|
@comments = SimpleTypedList.new Comments
|
|
246
|
-
|
|
247
|
-
|
|
248
252
|
@use_autowidth = true
|
|
249
253
|
@bold_font_multiplier = BOLD_FONT_MULTIPLIER
|
|
250
254
|
@font_scale_divisor = FONT_SCALE_DIVISOR
|
|
251
255
|
|
|
252
|
-
self.
|
|
256
|
+
self.escape_formulas = options[:escape_formulas].nil? ? Axlsx.escape_formulas : options[:escape_formulas]
|
|
257
|
+
self.date1904 = !options[:date1904].nil? && options[:date1904]
|
|
253
258
|
yield self if block_given?
|
|
254
259
|
end
|
|
255
260
|
|
|
256
261
|
# Instance level access to the class variable 1904
|
|
257
262
|
# @return [Boolean]
|
|
258
|
-
def date1904
|
|
263
|
+
def date1904
|
|
264
|
+
@@date1904
|
|
265
|
+
end
|
|
259
266
|
|
|
260
267
|
# see @date1904
|
|
261
|
-
def date1904=(v)
|
|
268
|
+
def date1904=(v)
|
|
269
|
+
Axlsx.validate_boolean v
|
|
270
|
+
@@date1904 = v
|
|
271
|
+
end
|
|
262
272
|
|
|
263
273
|
# Sets the date1904 attribute to the provided boolean
|
|
264
274
|
# @return [Boolean]
|
|
265
|
-
def self.date1904=(v)
|
|
275
|
+
def self.date1904=(v)
|
|
276
|
+
Axlsx.validate_boolean v
|
|
277
|
+
@@date1904 = v
|
|
278
|
+
end
|
|
266
279
|
|
|
267
280
|
# retrieves the date1904 attribute
|
|
268
281
|
# @return [Boolean]
|
|
269
|
-
def self.date1904
|
|
282
|
+
def self.date1904
|
|
283
|
+
@@date1904
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Whether to treat values starting with an equals sign as formulas or as literal strings.
|
|
287
|
+
# Allowing user-generated data to be interpreted as formulas is a security risk.
|
|
288
|
+
# See https://www.owasp.org/index.php/CSV_Injection for details.
|
|
289
|
+
# @return [Boolean]
|
|
290
|
+
attr_reader :escape_formulas
|
|
291
|
+
|
|
292
|
+
# Sets whether to treat values starting with an equals sign as formulas or as literal strings.
|
|
293
|
+
# @param [Boolean] value The value to set.
|
|
294
|
+
def escape_formulas=(value)
|
|
295
|
+
Axlsx.validate_boolean(value)
|
|
296
|
+
@escape_formulas = value
|
|
297
|
+
end
|
|
270
298
|
|
|
271
299
|
# Indicates if the workbook should use autowidths or not.
|
|
272
300
|
# @note This gem no longer depends on RMagick for autowidth
|
|
273
301
|
# calculation. Thus the performance benefits of turning this off are
|
|
274
302
|
# marginal unless you are creating a very large sheet.
|
|
275
303
|
# @return [Boolean]
|
|
276
|
-
|
|
304
|
+
attr_reader :use_autowidth
|
|
277
305
|
|
|
278
306
|
# see @use_autowidth
|
|
279
|
-
def use_autowidth=(v=true)
|
|
307
|
+
def use_autowidth=(v = true)
|
|
308
|
+
Axlsx.validate_boolean v
|
|
309
|
+
@use_autowidth = v
|
|
310
|
+
end
|
|
280
311
|
|
|
281
312
|
# Font size of bold fonts is multiplied with this
|
|
282
313
|
# Used for automatic calculation of cell widths with bold text
|
|
@@ -284,7 +315,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
284
315
|
attr_reader :bold_font_multiplier
|
|
285
316
|
|
|
286
317
|
def bold_font_multiplier=(v)
|
|
287
|
-
Axlsx
|
|
318
|
+
Axlsx.validate_float v
|
|
288
319
|
@bold_font_multiplier = v
|
|
289
320
|
end
|
|
290
321
|
|
|
@@ -294,7 +325,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
294
325
|
attr_reader :font_scale_divisor
|
|
295
326
|
|
|
296
327
|
def font_scale_divisor=(v)
|
|
297
|
-
Axlsx
|
|
328
|
+
Axlsx.validate_float v
|
|
298
329
|
@font_scale_divisor = v
|
|
299
330
|
end
|
|
300
331
|
|
|
@@ -306,7 +337,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
306
337
|
# @param [Hash] options Options to pass into the worksheed during initialization.
|
|
307
338
|
# @option options [String] name The name of the worksheet
|
|
308
339
|
# @option options [Hash] page_margins The page margins for the worksheet
|
|
309
|
-
def insert_worksheet(index=0, options={})
|
|
340
|
+
def insert_worksheet(index = 0, options = {})
|
|
310
341
|
worksheet = Worksheet.new(self, options)
|
|
311
342
|
@worksheets.delete_at(@worksheets.size - 1)
|
|
312
343
|
@worksheets.insert(index, worksheet)
|
|
@@ -320,7 +351,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
320
351
|
# @option options [String] name The name of the worksheet.
|
|
321
352
|
# @option options [Hash] page_margins The page margins for the worksheet.
|
|
322
353
|
# @see Worksheet#initialize
|
|
323
|
-
def add_worksheet(options={})
|
|
354
|
+
def add_worksheet(options = {})
|
|
324
355
|
worksheet = Worksheet.new(self, options)
|
|
325
356
|
yield worksheet if block_given?
|
|
326
357
|
worksheet
|
|
@@ -330,7 +361,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
330
361
|
# @return WorkbookViews
|
|
331
362
|
# @option options [Hash] options passed into the added WorkbookView
|
|
332
363
|
# @see WorkbookView#initialize
|
|
333
|
-
def add_view(options={})
|
|
364
|
+
def add_view(options = {})
|
|
334
365
|
views << WorkbookView.new(options)
|
|
335
366
|
end
|
|
336
367
|
|
|
@@ -347,14 +378,15 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
347
378
|
def relationships
|
|
348
379
|
r = Relationships.new
|
|
349
380
|
@worksheets.each do |sheet|
|
|
350
|
-
r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN
|
|
381
|
+
r << Relationship.new(sheet, WORKSHEET_R, format(WORKSHEET_PN, r.size + 1))
|
|
351
382
|
end
|
|
352
383
|
pivot_tables.each_with_index do |pivot_table, index|
|
|
353
|
-
r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN
|
|
384
|
+
r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1))
|
|
354
385
|
end
|
|
355
|
-
r << Relationship.new(self, STYLES_R,
|
|
386
|
+
r << Relationship.new(self, STYLES_R, STYLES_PN)
|
|
387
|
+
r << Relationship.new(self, THEME_R, THEME_PN)
|
|
356
388
|
if use_shared_strings
|
|
357
|
-
|
|
389
|
+
r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN)
|
|
358
390
|
end
|
|
359
391
|
r
|
|
360
392
|
end
|
|
@@ -362,11 +394,11 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
362
394
|
# generates a shared string object against all cells in all worksheets.
|
|
363
395
|
# @return [SharedStringTable]
|
|
364
396
|
def shared_strings
|
|
365
|
-
SharedStringsTable.new(worksheets.collect
|
|
397
|
+
SharedStringsTable.new(worksheets.collect(&:cells), xml_space)
|
|
366
398
|
end
|
|
367
399
|
|
|
368
400
|
# The xml:space attribute for the worksheet.
|
|
369
|
-
# This determines how whitespace is handled
|
|
401
|
+
# This determines how whitespace is handled within the document.
|
|
370
402
|
# The most relevant part being whitespace in the cell text.
|
|
371
403
|
# allowed values are :preserve and :default. Axlsx uses :preserve unless
|
|
372
404
|
# you explicily set this to :default.
|
|
@@ -380,28 +412,29 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
380
412
|
# @param [Symbol] space must be one of :preserve or :default
|
|
381
413
|
def xml_space=(space)
|
|
382
414
|
Axlsx::RestrictionValidator.validate(:xml_space, [:preserve, :default], space)
|
|
383
|
-
@xml_space = space
|
|
415
|
+
@xml_space = space
|
|
384
416
|
end
|
|
385
417
|
|
|
386
418
|
# returns a range of cells in a worksheet
|
|
387
|
-
# @param [String] cell_def The
|
|
419
|
+
# @param [String] cell_def The Excel style reference defining the worksheet and cells. The range must specify the sheet to
|
|
388
420
|
# retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell.
|
|
389
421
|
# @return [Cell, Array]
|
|
390
422
|
def [](cell_def)
|
|
391
|
-
sheet_name = cell_def.split('!')[0] if cell_def.
|
|
392
|
-
worksheet =
|
|
423
|
+
sheet_name = cell_def.split('!')[0] if cell_def.include?('!')
|
|
424
|
+
worksheet = worksheets.find { |s| s.name == sheet_name }
|
|
393
425
|
raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet)
|
|
394
|
-
|
|
426
|
+
|
|
427
|
+
worksheet[cell_def.gsub(/.+!/, "")]
|
|
395
428
|
end
|
|
396
429
|
|
|
397
430
|
# Serialize the workbook
|
|
398
431
|
# @param [String] str
|
|
399
432
|
# @return [String]
|
|
400
|
-
def to_xml_string(str='')
|
|
401
|
-
add_worksheet(name: 'Sheet1')
|
|
433
|
+
def to_xml_string(str = +'')
|
|
434
|
+
add_worksheet(name: 'Sheet1') if worksheets.empty?
|
|
402
435
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
403
|
-
str <<
|
|
404
|
-
str <<
|
|
436
|
+
str << '<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">'
|
|
437
|
+
str << '<workbookPr date1904="' << @@date1904.to_s << '"/>'
|
|
405
438
|
views.to_xml_string(str)
|
|
406
439
|
str << '<sheets>'
|
|
407
440
|
if is_reversed
|
|
@@ -414,12 +447,11 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
|
414
447
|
unless pivot_tables.empty?
|
|
415
448
|
str << '<pivotCaches>'
|
|
416
449
|
pivot_tables.each do |pivot_table|
|
|
417
|
-
str <<
|
|
450
|
+
str << '<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << pivot_table.cache_definition.rId << '"/>'
|
|
418
451
|
end
|
|
419
452
|
str << '</pivotCaches>'
|
|
420
453
|
end
|
|
421
454
|
str << '</workbook>'
|
|
422
455
|
end
|
|
423
|
-
|
|
424
456
|
end
|
|
425
457
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# <xsd:complexType name="CT_BookView">
|
|
2
4
|
# <xsd:sequence>
|
|
3
5
|
# <xsd:element name="extLst" type="CT_ExtensionList" minOccurs="0" maxOccurs="1"/>
|
|
@@ -19,19 +21,16 @@
|
|
|
19
21
|
# </xsd:complexType>
|
|
20
22
|
|
|
21
23
|
module Axlsx
|
|
22
|
-
|
|
23
24
|
# A BookView defines the display properties for a workbook.
|
|
24
25
|
# Units for window widths and other dimensions are expressed in twips.
|
|
25
26
|
# Twip measurements are portable between different display resolutions.
|
|
26
27
|
# The formula is (screen pixels) * (20 * 72) / (logical device dpi),
|
|
27
28
|
# where the logical device dpi can be different for x and y coordinates.
|
|
28
29
|
class WorkbookView
|
|
29
|
-
|
|
30
30
|
include Axlsx::SerializedAttributes
|
|
31
31
|
include Axlsx::OptionsParser
|
|
32
32
|
include Axlsx::Accessors
|
|
33
33
|
|
|
34
|
-
|
|
35
34
|
# Creates a new BookView object
|
|
36
35
|
# @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
|
|
37
36
|
# @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible.
|
|
@@ -39,7 +38,7 @@ module Axlsx
|
|
|
39
38
|
# @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
|
|
40
39
|
# @option [Boolean] show_vertical_scroll Specifies a boolean value that indicates whether to display the vertical scroll bar.
|
|
41
40
|
# @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
|
|
42
|
-
# @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
|
|
41
|
+
# @option [Integer] tab_ratio Specifies the ratio between the workbook tabs bar and the horizontal scroll bar (from 0 to 1000, higher values mean more space for tabs). May only be supported on some clients.
|
|
43
42
|
# @option [Integer] first_sheet Specifies the index to the first sheet in this book view.
|
|
44
43
|
# @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
|
|
45
44
|
# @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
|
|
@@ -47,16 +46,15 @@ module Axlsx
|
|
|
47
46
|
# @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips.
|
|
48
47
|
# @option [Integer] window_height Specifies the height of the workbook window. The unit of measurement for this value is twips.
|
|
49
48
|
# @option [Boolean] auto_filter_date_grouping Specifies a boolean value that indicates whether to group dates when presenting the user with filtering options in the user interface.
|
|
50
|
-
def initialize(options={})
|
|
49
|
+
def initialize(options = {})
|
|
51
50
|
parse_options options
|
|
52
51
|
yield self if block_given?
|
|
53
52
|
end
|
|
54
53
|
|
|
55
|
-
|
|
56
54
|
unsigned_int_attr_accessor :x_window, :y_window, :window_width, :window_height,
|
|
57
55
|
:tab_ratio, :first_sheet, :active_tab
|
|
58
56
|
|
|
59
|
-
validated_attr_accessor
|
|
57
|
+
validated_attr_accessor [:visibility], :validate_view_visibility
|
|
60
58
|
|
|
61
59
|
serializable_attributes :visibility, :minimized,
|
|
62
60
|
:show_horizontal_scroll, :show_vertical_scroll,
|
|
@@ -67,14 +65,13 @@ module Axlsx
|
|
|
67
65
|
boolean_attr_accessor :minimized, :show_horizontal_scroll, :show_vertical_scroll,
|
|
68
66
|
:show_sheet_tabs, :auto_filter_date_grouping
|
|
69
67
|
|
|
70
|
-
|
|
71
68
|
# Serialize the WorkbookView
|
|
72
69
|
# @param [String] str
|
|
73
70
|
# @return [String]
|
|
74
|
-
def to_xml_string(str = '')
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
def to_xml_string(str = +'')
|
|
72
|
+
str << '<workbookView '
|
|
73
|
+
serialized_attributes str
|
|
74
|
+
str << '></workbookView>'
|
|
78
75
|
end
|
|
79
76
|
end
|
|
80
77
|
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# a simple types list of BookView objects
|
|
3
5
|
class WorkbookViews < SimpleTypedList
|
|
4
|
-
|
|
5
6
|
# creates the book views object
|
|
6
7
|
def initialize
|
|
7
|
-
super
|
|
8
|
+
super(WorkbookView)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
# Serialize to xml
|
|
11
12
|
# @param [String] str
|
|
12
13
|
# @return [String]
|
|
13
|
-
def to_xml_string(str = '')
|
|
14
|
+
def to_xml_string(str = +'')
|
|
14
15
|
return if empty?
|
|
16
|
+
|
|
15
17
|
str << "<bookViews>"
|
|
16
18
|
each { |view| view.to_xml_string(str) }
|
|
17
19
|
str << '</bookViews>'
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
|
-
|
|
22
|
-
|