xlsxrb 0.1.17 → 0.1.18
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 +93 -1
- data/README.md +79 -19
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
- data/lib/xlsxrb/chart_builder.rb +595 -113
- data/lib/xlsxrb/dsl_helpers.rb +72 -20
- data/lib/xlsxrb/elements/cell.rb +243 -56
- data/lib/xlsxrb/elements/column.rb +94 -5
- data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
- data/lib/xlsxrb/elements/image.rb +81 -15
- data/lib/xlsxrb/elements/metadata.rb +2733 -0
- data/lib/xlsxrb/elements/row.rb +130 -46
- data/lib/xlsxrb/elements/styles.rb +184 -76
- data/lib/xlsxrb/elements/types.rb +242 -7
- data/lib/xlsxrb/elements/workbook.rb +171 -82
- data/lib/xlsxrb/elements/worksheet.rb +598 -102
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +12 -4
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -2
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +264 -17
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
- data/lib/xlsxrb/ooxml/reader.rb +4 -0
- data/lib/xlsxrb/ooxml/styles_parser.rb +10 -3
- data/lib/xlsxrb/ooxml/workbook_writer.rb +90 -36
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +2 -2
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +64 -19
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +5 -2
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +26 -5
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +19 -9
- data/lib/xlsxrb/ooxml/writer.rb +22 -6
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
- data/lib/xlsxrb/stream_row.rb +97 -18
- data/lib/xlsxrb/stream_sheet.rb +706 -190
- data/lib/xlsxrb/stream_writer.rb +1893 -374
- data/lib/xlsxrb/style_builder.rb +774 -111
- data/lib/xlsxrb/utils.rb +66 -106
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +380 -83
- data/lib/xlsxrb/worksheet_builder.rb +1210 -233
- data/lib/xlsxrb.rb +1266 -326
- data/sig/generated/xlsxrb/chart_builder.rbs +319 -90
- data/sig/generated/xlsxrb/dsl_helpers.rbs +20 -2
- data/sig/generated/xlsxrb/elements/cell.rbs +92 -20
- data/sig/generated/xlsxrb/elements/column.rbs +61 -2
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
- data/sig/generated/xlsxrb/elements/image.rbs +30 -8
- data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
- data/sig/generated/xlsxrb/elements/row.rbs +61 -21
- data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
- data/sig/generated/xlsxrb/elements/types.rbs +27 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +63 -52
- data/sig/generated/xlsxrb/elements/worksheet.rbs +192 -51
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/writer.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
- data/sig/generated/xlsxrb/stream_row.rbs +48 -14
- data/sig/generated/xlsxrb/stream_sheet.rbs +324 -115
- data/sig/generated/xlsxrb/stream_writer.rbs +1068 -255
- data/sig/generated/xlsxrb/style_builder.rbs +389 -79
- data/sig/generated/xlsxrb/utils.rbs +34 -18
- data/sig/generated/xlsxrb/workbook_builder.rbs +234 -34
- data/sig/generated/xlsxrb/worksheet_builder.rbs +628 -126
- data/sig/generated/xlsxrb.rbs +257 -49
- metadata +3 -1
|
@@ -17,12 +17,176 @@ module Xlsxrb
|
|
|
17
17
|
class Worksheet
|
|
18
18
|
[Enumerable, CoordinateAccess].each { |m| include m }
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
# @return [Array<Hash[Symbol, untyped]>]
|
|
21
|
+
#
|
|
22
|
+
# Corresponds to ECMA-376 Part 4 §18.3.1.18 (<conditionalFormatting> and <cfRule> elements).
|
|
23
|
+
# In the OpenXML specification, conditional formatting definitions are emitted as
|
|
24
|
+
# `<conditionalFormatting>` elements containing individual rule definitions (`<cfRule>`).
|
|
25
|
+
# While ECMA-376 uses the uncountable noun `conditionalFormatting` as the XML element name,
|
|
26
|
+
# xlsxrb exposes these rules collectively as {#conditional_formats} (Array of Hashes)
|
|
27
|
+
# to maintain symmetric plural collection naming alongside other collections
|
|
28
|
+
# (e.g. {#tables}, {#data_validations}, {#merged_cells}) and paired with the singular builder
|
|
29
|
+
# method {WorksheetBuilder#conditional_format}.
|
|
30
|
+
#
|
|
31
|
+
# @api public
|
|
32
|
+
#: Array[Elements::ConditionalFormat]
|
|
33
|
+
attr_reader :conditional_formats
|
|
34
|
+
|
|
35
|
+
#: String?
|
|
36
|
+
attr_reader :name
|
|
37
|
+
#: Array[Elements::Row]
|
|
38
|
+
attr_reader :rows
|
|
39
|
+
#: Array[Elements::Column]
|
|
40
|
+
attr_reader :columns
|
|
41
|
+
#: Array[Elements::Chart]
|
|
42
|
+
attr_reader :charts
|
|
43
|
+
#: Array[Elements::DataValidation]
|
|
44
|
+
attr_reader :data_validations
|
|
45
|
+
#: Hash[untyped, untyped]
|
|
46
|
+
attr_reader :unmapped_data
|
|
47
|
+
#: Array[String]
|
|
48
|
+
attr_reader :errors
|
|
49
|
+
#: Symbol
|
|
50
|
+
attr_reader :state
|
|
51
|
+
#: Hash[String, Elements::Hyperlink]
|
|
52
|
+
attr_reader :hyperlinks
|
|
53
|
+
#: Array[Elements::Comment]
|
|
54
|
+
attr_reader :comments
|
|
55
|
+
#: Array[Elements::Image]
|
|
56
|
+
attr_reader :images
|
|
57
|
+
#: (Elements::Styles | Hash[untyped, untyped])?
|
|
58
|
+
attr_reader :styles
|
|
59
|
+
#: String?
|
|
60
|
+
attr_reader :print_area
|
|
61
|
+
#: Elements::PrintTitles?
|
|
62
|
+
attr_reader :print_titles
|
|
63
|
+
#: Array[Elements::SparklineGroup]
|
|
64
|
+
attr_reader :sparkline_groups
|
|
65
|
+
#: Array[String]
|
|
66
|
+
attr_reader :merged_cells
|
|
67
|
+
#: String?
|
|
68
|
+
attr_reader :auto_filter
|
|
69
|
+
#: Array[Elements::Table]
|
|
70
|
+
attr_reader :tables
|
|
71
|
+
#: Array[Elements::Shape]
|
|
72
|
+
attr_reader :shapes
|
|
73
|
+
#: Elements::FreezePane?
|
|
74
|
+
attr_reader :freeze_pane
|
|
75
|
+
#: Elements::PageSetup
|
|
76
|
+
attr_reader :page_setup
|
|
77
|
+
#: Elements::PageMargins?
|
|
78
|
+
attr_reader :page_margins
|
|
79
|
+
#: Elements::HeaderFooter
|
|
80
|
+
attr_reader :header_footer
|
|
81
|
+
#: Elements::PrintOptions
|
|
82
|
+
attr_reader :print_options
|
|
83
|
+
#: Elements::SheetProtection?
|
|
84
|
+
attr_reader :sheet_protection
|
|
85
|
+
#: Elements::SheetView
|
|
86
|
+
attr_reader :sheet_view
|
|
87
|
+
#: Elements::SheetProperties
|
|
88
|
+
attr_reader :sheet_properties
|
|
89
|
+
#: Elements::SheetFormat
|
|
90
|
+
attr_reader :sheet_format
|
|
91
|
+
#: Array[Elements::PageBreak]
|
|
92
|
+
attr_reader :row_breaks
|
|
93
|
+
#: Array[Elements::PageBreak]
|
|
94
|
+
attr_reader :column_breaks
|
|
95
|
+
#: Array[Elements::ProtectedRange]
|
|
96
|
+
attr_reader :protected_ranges
|
|
97
|
+
#: Array[String]
|
|
98
|
+
attr_reader :cell_watches
|
|
99
|
+
#: Array[Elements::IgnoredError]
|
|
100
|
+
attr_reader :ignored_errors
|
|
101
|
+
#: Elements::PhoneticProperties?
|
|
102
|
+
attr_reader :phonetic_properties
|
|
103
|
+
#: (Elements::Selection | Array[Elements::Selection])?
|
|
104
|
+
attr_reader :selection
|
|
105
|
+
#: Elements::BackgroundImage?
|
|
106
|
+
attr_reader :background_image
|
|
107
|
+
#: Array[Elements::ThreadedComment]
|
|
108
|
+
attr_reader :threaded_comments
|
|
109
|
+
#: Array[Elements::PivotTable]
|
|
110
|
+
attr_reader :pivot_tables
|
|
111
|
+
#: Elements::SplitPane?
|
|
112
|
+
attr_reader :split_pane
|
|
113
|
+
#: Hash[Integer, Elements::FilterColumn]
|
|
114
|
+
attr_reader :filter_columns
|
|
115
|
+
#: Elements::SortState?
|
|
116
|
+
attr_reader :sort_state
|
|
117
|
+
#: Array[Elements::HeaderFooterImage]
|
|
118
|
+
attr_reader :header_footer_images
|
|
119
|
+
|
|
120
|
+
# @deprecated Worksheet instances are immutable value objects. In 0.2.0, #dimension= will be removed.
|
|
121
|
+
#: (String? new_dim) -> String?
|
|
122
|
+
def dimension=(new_dim)
|
|
123
|
+
warn "[DEPRECATION] Elements::Worksheet#dimension= is deprecated; worksheets are immutable.", uplevel: 1
|
|
124
|
+
@dimension = new_dim
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# @deprecated Use {#date1904?} instead. Will be removed in 0.2.0.
|
|
128
|
+
#: () -> bool
|
|
129
|
+
def date1904
|
|
130
|
+
warn "[DEPRECATION] Elements::Worksheet#date1904 is deprecated; use #date1904? instead.", uplevel: 1
|
|
131
|
+
date1904?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Closes the worksheet resources (no-op for in-memory worksheet).
|
|
135
|
+
#
|
|
136
|
+
# @return [void]
|
|
137
|
+
# @api public
|
|
138
|
+
#: () -> void
|
|
139
|
+
def close
|
|
140
|
+
Xlsxrb::Deprecation.warn("Elements::Worksheet#close is deprecated; in-memory worksheets do not hold file handles.", uplevel: 1)
|
|
141
|
+
nil
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Support array pattern matching.
|
|
145
|
+
#
|
|
146
|
+
# @return [Array<Object>]
|
|
147
|
+
# @api public
|
|
148
|
+
#: () -> Array[untyped]
|
|
149
|
+
def deconstruct
|
|
150
|
+
[name, rows, columns]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# @deprecated Use {#column_breaks} instead.
|
|
154
|
+
#: () -> Array[Elements::PageBreak]
|
|
155
|
+
def col_breaks
|
|
156
|
+
warn "[DEPRECATION] `col_breaks` is deprecated; use `column_breaks` instead.", uplevel: 1
|
|
157
|
+
@column_breaks
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Returns worksheet calculation properties (<sheetCalcPr>), or nil if none configured.
|
|
161
|
+
#
|
|
162
|
+
# @return [Elements::SheetCalcProperties, nil]
|
|
163
|
+
# @api public
|
|
164
|
+
#: () -> Elements::SheetCalcProperties?
|
|
165
|
+
def sheet_calc_properties
|
|
166
|
+
@sheet_calc_pr
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
|
|
170
|
+
#: () -> Elements::SheetCalcProperties?
|
|
171
|
+
def sheet_calc_pr
|
|
172
|
+
warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
|
|
173
|
+
sheet_calc_properties
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
|
|
177
|
+
#: () -> Elements::SheetCalcProperties?
|
|
178
|
+
def calc_pr
|
|
179
|
+
warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
|
|
180
|
+
sheet_calc_properties
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# @deprecated Use {#conditional_formats} instead. Matches the ECMA-376 XML element name (<conditionalFormatting>), but {#conditional_formats} is canonical in xlsxrb. Will be removed in version 0.2.0.
|
|
184
|
+
alias conditional_formatting conditional_formats
|
|
185
|
+
# @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
|
|
23
186
|
alias phonetic_pr phonetic_properties
|
|
24
|
-
|
|
187
|
+
# @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
|
|
25
188
|
alias background_picture background_image
|
|
189
|
+
# @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
|
|
26
190
|
alias picture background_image
|
|
27
191
|
|
|
28
192
|
# @param name [String] The worksheet name (max 31 characters).
|
|
@@ -60,7 +224,8 @@ module Xlsxrb
|
|
|
60
224
|
# @param sheet_properties [Hash] Sheet properties (e.g. tabColor, outlinePr).
|
|
61
225
|
# @param sheet_format [Hash] Sheet format properties (e.g. defaultRowHeight, defaultColWidth).
|
|
62
226
|
# @param row_breaks [Array<Integer | Hash>] Explicit page row breaks.
|
|
63
|
-
# @param
|
|
227
|
+
# @param column_breaks [Array<Integer | Hash>] Explicit page column breaks.
|
|
228
|
+
# @param col_breaks [Array<Integer | Hash>] Deprecated alias for column_breaks.
|
|
64
229
|
# @param protected_ranges [Array<Hash>] Protected range definitions.
|
|
65
230
|
# @param cell_watches [Array<String>] Watched cell references.
|
|
66
231
|
# @param ignored_errors [Array<Hash>] Ignored error rules.
|
|
@@ -69,54 +234,229 @@ module Xlsxrb
|
|
|
69
234
|
# @param sheet_calc_pr [Hash, nil] Worksheet calculation properties.
|
|
70
235
|
# @param background_image [Hash, nil] Worksheet background image specification.
|
|
71
236
|
# @param threaded_comments [Array<Hash>] Threaded comments in the sheet.
|
|
72
|
-
#: (name: String?, ?rows: Array[Elements::Row], ?columns: Array[Elements::Column], ?charts: Array[
|
|
73
|
-
def initialize(name:, rows: [], columns: [], charts: [], conditional_formatting: nil, data_validations: [], unmapped_data: {}, errors: nil, conditional_formats: nil, state: :visible, hyperlinks: {}, comments: [], images: [], styles: nil, date1904: false, dimension: nil, trim_empty_rows: false, pad_empty_rows: false, pad_empty_cells: false, print_area: nil, print_titles: nil, sparkline_groups: [], merged_cells: [], auto_filter: nil, tables: [], shapes: [], freeze_pane: nil, page_setup: {}, page_margins: nil, header_footer: {}, print_options: {}, sheet_protection: nil, sheet_view: {}, sheet_properties: {}, sheet_format: {}, row_breaks: [], col_breaks:
|
|
237
|
+
#: (name: String?, ?rows: Array[Elements::Row], ?columns: Array[Elements::Column], ?charts: Array[untyped], ?conditional_formatting: Array[untyped]?, ?data_validations: Array[untyped], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?, ?conditional_formats: Array[untyped]?, ?state: Symbol, ?hyperlinks: Hash[String, untyped], ?comments: Array[untyped], ?images: Array[Elements::Image], ?styles: (Elements::Styles | Hash[untyped, untyped])?, ?date1904: bool, ?dimension: String?, ?trim_empty_rows: bool, ?pad_empty_rows: bool, ?pad_empty_cells: bool, ?print_area: String?, ?print_titles: untyped, ?sparkline_groups: Array[untyped], ?merged_cells: Array[String], ?auto_filter: String?, ?tables: Array[untyped], ?shapes: Array[untyped], ?freeze_pane: untyped, ?page_setup: untyped, ?page_margins: untyped, ?header_footer: untyped, ?print_options: untyped, ?sheet_protection: untyped, ?sheet_view: untyped, ?sheet_properties: untyped, ?sheet_format: untyped, ?row_breaks: Array[untyped], ?column_breaks: Array[untyped]?, ?col_breaks: Array[untyped]?, ?protected_ranges: Array[untyped], ?cell_watches: Array[String], ?ignored_errors: Array[untyped], ?phonetic_properties: untyped, ?selection: untyped, ?sheet_calc_properties: untyped, ?sheet_calc_pr: untyped, ?background_image: untyped, ?threaded_comments: Array[untyped], ?pivot_tables: Array[untyped]?, ?split_pane: untyped, ?filter_columns: Hash[Integer, untyped]?, ?sort_state: untyped, ?header_footer_images: Array[untyped]?) -> void
|
|
238
|
+
def initialize(name:, rows: [], columns: [], charts: [], conditional_formatting: nil, data_validations: [], unmapped_data: {}, errors: nil, conditional_formats: nil, state: :visible, hyperlinks: {}, comments: [], images: [], styles: nil, date1904: false, dimension: nil, trim_empty_rows: false, pad_empty_rows: false, pad_empty_cells: false, print_area: nil, print_titles: nil, sparkline_groups: [], merged_cells: [], auto_filter: nil, tables: [], shapes: [], freeze_pane: nil, page_setup: {}, page_margins: nil, header_footer: {}, print_options: {}, sheet_protection: nil, sheet_view: {}, sheet_properties: {}, sheet_format: {}, row_breaks: [], column_breaks: nil, col_breaks: nil, protected_ranges: [], cell_watches: [], ignored_errors: [], phonetic_properties: nil, selection: nil, sheet_calc_properties: nil, sheet_calc_pr: nil, background_image: nil, threaded_comments: [], pivot_tables: nil, split_pane: nil, filter_columns: nil, sort_state: nil, header_footer_images: nil)
|
|
239
|
+
warn "[Xlsxrb DEPRECATION] Passing conditional_formatting: to Worksheet.new is deprecated; use conditional_formats: instead.", uplevel: 1 unless conditional_formatting.nil?
|
|
240
|
+
warn "[Xlsxrb DEPRECATION] Passing col_breaks: to Worksheet.new is deprecated; use column_breaks: instead.", uplevel: 1 unless col_breaks.nil?
|
|
241
|
+
warn "[Xlsxrb DEPRECATION] Worksheet.new(sheet_calc_pr:) is deprecated and will be removed in v0.2.0. Use sheet_calc_properties: instead.", uplevel: 1 unless sheet_calc_pr.nil?
|
|
74
242
|
@name = name
|
|
75
243
|
@rows = (rows || []).freeze
|
|
76
244
|
@columns = (columns || []).freeze
|
|
77
|
-
@charts = (charts || []).freeze
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
245
|
+
@charts = (charts || []).map { |c| c.is_a?(Elements::Chart) ? c : Elements::Chart.new(**c) }.freeze
|
|
246
|
+
raw_cfs = conditional_formats || conditional_formatting || []
|
|
247
|
+
cf = raw_cfs.map do |c|
|
|
248
|
+
if c.is_a?(Hash)
|
|
249
|
+
Elements::ConditionalFormat.new(**c)
|
|
250
|
+
else
|
|
251
|
+
c
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
@conditional_formats = cf.freeze
|
|
255
|
+
@conditional_formatting = @conditional_formats
|
|
256
|
+
@data_validations = (data_validations || []).map { |dv| dv.is_a?(Elements::DataValidation) ? dv : Elements::DataValidation.new(**dv) }.freeze
|
|
81
257
|
@unmapped_data = (unmapped_data || {}).freeze
|
|
82
258
|
computed_errors = errors || self.class.validate(@name, @rows)
|
|
83
259
|
@errors = computed_errors.freeze
|
|
84
260
|
@state = state ? state.to_sym : :visible
|
|
85
|
-
@hyperlinks = (hyperlinks || {}).
|
|
86
|
-
|
|
261
|
+
@hyperlinks = (hyperlinks || {}).to_h do |ref, hl|
|
|
262
|
+
hl_obj = case hl
|
|
263
|
+
when Hash
|
|
264
|
+
Elements::Hyperlink.new(**hl)
|
|
265
|
+
when String
|
|
266
|
+
Elements::Hyperlink.new(url: hl)
|
|
267
|
+
else
|
|
268
|
+
hl
|
|
269
|
+
end
|
|
270
|
+
[ref.to_s, hl_obj]
|
|
271
|
+
end.freeze
|
|
272
|
+
@comments = (comments || []).map { |c| c.is_a?(Elements::Comment) ? c : Elements::Comment.new(**c) }.freeze
|
|
87
273
|
@images = (images || []).freeze
|
|
88
274
|
@styles = styles
|
|
89
275
|
@date1904 = date1904 ? true : false
|
|
90
276
|
@dimension = dimension
|
|
91
277
|
@print_area = print_area
|
|
92
|
-
@print_titles = print_titles
|
|
93
|
-
|
|
278
|
+
@print_titles = if print_titles.nil?
|
|
279
|
+
nil
|
|
280
|
+
elsif print_titles.is_a?(Elements::PrintTitles)
|
|
281
|
+
print_titles
|
|
282
|
+
else
|
|
283
|
+
Elements::PrintTitles.new(**print_titles)
|
|
284
|
+
end
|
|
285
|
+
@sparkline_groups = (sparkline_groups || []).map do |sg|
|
|
286
|
+
if sg.is_a?(Hash)
|
|
287
|
+
sls = (sg[:sparklines] || []).map do |s|
|
|
288
|
+
if s.is_a?(Hash)
|
|
289
|
+
Elements::Sparkline.new(**s)
|
|
290
|
+
elsif s.is_a?(Elements::Sparkline)
|
|
291
|
+
s
|
|
292
|
+
else
|
|
293
|
+
Elements::Sparkline.new(sqref: s.to_s)
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
Elements::SparklineGroup.new(**sg, sparklines: sls)
|
|
297
|
+
else
|
|
298
|
+
sg
|
|
299
|
+
end
|
|
300
|
+
end.freeze
|
|
94
301
|
@trim_empty_rows = trim_empty_rows ? true : false
|
|
95
302
|
@pad_empty_rows = pad_empty_rows ? true : false
|
|
96
303
|
@pad_empty_cells = pad_empty_cells ? true : false
|
|
97
|
-
@threaded_comments = (threaded_comments || []).freeze
|
|
304
|
+
@threaded_comments = (threaded_comments || []).map { |tc| tc.is_a?(Elements::ThreadedComment) ? tc : Elements::ThreadedComment.new(**tc) }.freeze
|
|
98
305
|
@merged_cells = (merged_cells || []).freeze
|
|
99
306
|
@auto_filter = auto_filter
|
|
100
|
-
@tables = (tables || []).
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
307
|
+
@tables = (tables || []).map do |tb|
|
|
308
|
+
if tb.is_a?(Hash)
|
|
309
|
+
cols = (tb[:columns] || []).each_with_index.map do |col, idx|
|
|
310
|
+
if col.is_a?(Hash)
|
|
311
|
+
Elements::TableColumn.new(**col)
|
|
312
|
+
elsif col.is_a?(Elements::TableColumn)
|
|
313
|
+
col
|
|
314
|
+
else
|
|
315
|
+
Elements::TableColumn.new(name: col.to_s, id: idx + 1)
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
si = tb[:style_info] || (tb[:style] ? { name: tb[:style], show_row_stripes: tb[:show_row_stripes], show_first_column: tb[:show_first_column], show_last_column: tb[:show_last_column], show_column_stripes: tb[:show_column_stripes] } : nil)
|
|
319
|
+
si = Elements::TableStyleInfo.new(**si) if si.is_a?(Hash)
|
|
320
|
+
Elements::Table.new(**tb, columns: cols, style_info: si)
|
|
321
|
+
else
|
|
322
|
+
tb
|
|
323
|
+
end
|
|
324
|
+
end.freeze
|
|
325
|
+
@shapes = (shapes || []).map { |s| s.is_a?(Elements::Shape) ? s : Elements::Shape.new(**s) }.freeze
|
|
326
|
+
@freeze_pane = if freeze_pane.nil?
|
|
327
|
+
nil
|
|
328
|
+
elsif freeze_pane.is_a?(Elements::FreezePane)
|
|
329
|
+
freeze_pane
|
|
330
|
+
else
|
|
331
|
+
Elements::FreezePane.new(**freeze_pane)
|
|
332
|
+
end
|
|
333
|
+
ps = page_setup || {}
|
|
334
|
+
@page_setup = ps.is_a?(Elements::PageSetup) ? ps : Elements::PageSetup.new(**ps)
|
|
335
|
+
@page_margins = if page_margins.nil?
|
|
336
|
+
nil
|
|
337
|
+
elsif page_margins.is_a?(Elements::PageMargins)
|
|
338
|
+
page_margins
|
|
339
|
+
else
|
|
340
|
+
Elements::PageMargins.new(**page_margins)
|
|
341
|
+
end
|
|
342
|
+
hf = header_footer || {}
|
|
343
|
+
@header_footer = hf.is_a?(Elements::HeaderFooter) ? hf : Elements::HeaderFooter.new(**hf)
|
|
344
|
+
po = print_options || {}
|
|
345
|
+
@print_options = po.is_a?(Elements::PrintOptions) ? po : Elements::PrintOptions.new(**po)
|
|
346
|
+
@sheet_protection = if sheet_protection.nil?
|
|
347
|
+
nil
|
|
348
|
+
elsif sheet_protection.is_a?(Elements::SheetProtection)
|
|
349
|
+
sheet_protection
|
|
350
|
+
else
|
|
351
|
+
Elements::SheetProtection.new(**sheet_protection)
|
|
352
|
+
end
|
|
353
|
+
sv = sheet_view || {}
|
|
354
|
+
@sheet_view = sv.is_a?(Elements::SheetView) ? sv : Elements::SheetView.new(**sv)
|
|
355
|
+
sp = sheet_properties || {}
|
|
356
|
+
@sheet_properties = sp.is_a?(Elements::SheetProperties) ? sp : Elements::SheetProperties.new(**sp)
|
|
357
|
+
sf = sheet_format || unmapped_data[:sheet_format] || unmapped_data.dig(:facade, :sheet_format) || {}
|
|
358
|
+
@sheet_format = sf.is_a?(Elements::SheetFormat) ? sf : Elements::SheetFormat.new(**sf)
|
|
359
|
+
@row_breaks = (row_breaks || []).map do |brk|
|
|
360
|
+
if brk.is_a?(Elements::PageBreak)
|
|
361
|
+
brk
|
|
362
|
+
elsif brk.is_a?(Hash)
|
|
363
|
+
Elements::PageBreak.new(**brk)
|
|
364
|
+
else
|
|
365
|
+
Elements::PageBreak.new(id: brk.to_i, max: 16_383, man: 1)
|
|
366
|
+
end
|
|
367
|
+
end.freeze
|
|
368
|
+
raw_col_breaks = column_breaks || col_breaks || []
|
|
369
|
+
breaks = raw_col_breaks.map do |brk|
|
|
370
|
+
if brk.is_a?(Elements::PageBreak)
|
|
371
|
+
brk
|
|
372
|
+
elsif brk.is_a?(Hash)
|
|
373
|
+
Elements::PageBreak.new(**brk)
|
|
374
|
+
else
|
|
375
|
+
col_id = Elements::Cell._column_index(brk)
|
|
376
|
+
Elements::PageBreak.new(id: col_id, max: 1_048_575, man: 1)
|
|
377
|
+
end
|
|
378
|
+
end.freeze
|
|
379
|
+
@column_breaks = breaks
|
|
380
|
+
@col_breaks = breaks
|
|
381
|
+
pr = protected_ranges || unmapped_data[:protected_ranges] || unmapped_data.dig(:facade, :protected_ranges) || []
|
|
382
|
+
@protected_ranges = pr.map { |r| r.is_a?(Elements::ProtectedRange) ? r : Elements::ProtectedRange.new(**r) }.freeze
|
|
114
383
|
@cell_watches = (cell_watches || unmapped_data[:cell_watches] || unmapped_data.dig(:facade, :cell_watches) || []).freeze
|
|
115
|
-
|
|
116
|
-
@
|
|
117
|
-
|
|
118
|
-
@
|
|
119
|
-
|
|
384
|
+
ie = ignored_errors || unmapped_data[:ignored_errors] || unmapped_data.dig(:facade, :ignored_errors) || []
|
|
385
|
+
@ignored_errors = ie.map { |r| r.is_a?(Elements::IgnoredError) ? r : Elements::IgnoredError.new(**r) }.freeze
|
|
386
|
+
pp = phonetic_properties || unmapped_data[:phonetic_properties] || unmapped_data.dig(:facade, :phonetic_properties)
|
|
387
|
+
@phonetic_properties = if pp.nil?
|
|
388
|
+
nil
|
|
389
|
+
elsif pp.is_a?(Elements::PhoneticProperties)
|
|
390
|
+
pp
|
|
391
|
+
else
|
|
392
|
+
Elements::PhoneticProperties.new(**pp)
|
|
393
|
+
end
|
|
394
|
+
@selection = if selection.nil?
|
|
395
|
+
nil
|
|
396
|
+
elsif selection.is_a?(Elements::Selection)
|
|
397
|
+
selection
|
|
398
|
+
elsif selection.is_a?(Array)
|
|
399
|
+
selection.map { |s| s.is_a?(Elements::Selection) ? s : Elements::Selection.new(**s) }
|
|
400
|
+
else
|
|
401
|
+
Elements::Selection.new(**selection)
|
|
402
|
+
end
|
|
403
|
+
full_calc = if @sheet_properties.respond_to?(:full_calc_on_load)
|
|
404
|
+
@sheet_properties.full_calc_on_load
|
|
405
|
+
else
|
|
406
|
+
@sheet_properties[:full_calc_on_load]
|
|
407
|
+
end
|
|
408
|
+
resolved_calc = sheet_calc_properties || sheet_calc_pr
|
|
409
|
+
calc = resolved_calc || unmapped_data[:sheet_calc_properties] || unmapped_data[:sheet_calc_pr] || unmapped_data.dig(:facade, :sheet_calc_pr) || (full_calc ? { full_calc_on_load: true } : nil)
|
|
410
|
+
@sheet_calc_pr = if calc.nil?
|
|
411
|
+
nil
|
|
412
|
+
elsif calc.is_a?(Elements::SheetCalcProperties)
|
|
413
|
+
calc
|
|
414
|
+
else
|
|
415
|
+
Elements::SheetCalcProperties.new(**calc)
|
|
416
|
+
end
|
|
417
|
+
bg = background_image || unmapped_data[:background_image] || unmapped_data.dig(:facade, :background_image)
|
|
418
|
+
@background_image = if bg.nil?
|
|
419
|
+
nil
|
|
420
|
+
elsif bg.is_a?(Elements::BackgroundImage)
|
|
421
|
+
bg
|
|
422
|
+
else
|
|
423
|
+
Elements::BackgroundImage.new(**bg)
|
|
424
|
+
end
|
|
425
|
+
pt = pivot_tables || unmapped_data[:pivot_tables] || unmapped_data.dig(:facade, :pivot_tables) || []
|
|
426
|
+
@pivot_tables = pt.map { |r| r.is_a?(Elements::PivotTable) ? r : Elements::PivotTable.new(**r) }.freeze
|
|
427
|
+
sp = split_pane || unmapped_data[:split_pane] || unmapped_data.dig(:facade, :split_pane)
|
|
428
|
+
@split_pane = if sp.nil?
|
|
429
|
+
nil
|
|
430
|
+
elsif sp.is_a?(Elements::SplitPane)
|
|
431
|
+
sp
|
|
432
|
+
else
|
|
433
|
+
Elements::SplitPane.new(**sp)
|
|
434
|
+
end
|
|
435
|
+
fc = filter_columns || unmapped_data[:filter_columns] || unmapped_data.dig(:facade, :filter_columns) || {}
|
|
436
|
+
@filter_columns = fc.to_h do |k, v|
|
|
437
|
+
col_id = k.to_i
|
|
438
|
+
val = case v
|
|
439
|
+
when Elements::FilterColumn
|
|
440
|
+
v
|
|
441
|
+
when Hash
|
|
442
|
+
Elements::FilterColumn.new(**v)
|
|
443
|
+
when Array
|
|
444
|
+
Elements::FilterColumn.new(col_id: col_id, filters: v)
|
|
445
|
+
else
|
|
446
|
+
Elements::FilterColumn.new(col_id: col_id, filters: [v.to_s])
|
|
447
|
+
end
|
|
448
|
+
[col_id, val]
|
|
449
|
+
end.freeze
|
|
450
|
+
st = sort_state || unmapped_data[:sort_state] || unmapped_data.dig(:facade, :sort_state)
|
|
451
|
+
@sort_state = if st.nil?
|
|
452
|
+
nil
|
|
453
|
+
elsif st.is_a?(Elements::SortState)
|
|
454
|
+
st
|
|
455
|
+
else
|
|
456
|
+
Elements::SortState.new(**st)
|
|
457
|
+
end
|
|
458
|
+
hfi = header_footer_images || unmapped_data[:header_footer_images] || unmapped_data.dig(:facade, :header_footer_images) || []
|
|
459
|
+
@header_footer_images = hfi.map { |r| r.is_a?(Elements::HeaderFooterImage) ? r : Elements::HeaderFooterImage.new(**r) }.freeze
|
|
120
460
|
end
|
|
121
461
|
|
|
122
462
|
# Returns whether trailing empty rows are omitted during iteration.
|
|
@@ -127,7 +467,13 @@ module Xlsxrb
|
|
|
127
467
|
def trim_empty_rows?
|
|
128
468
|
@trim_empty_rows ? true : false
|
|
129
469
|
end
|
|
130
|
-
|
|
470
|
+
|
|
471
|
+
# @deprecated Use {#trim_empty_rows?} instead. Will be removed in 0.2.0.
|
|
472
|
+
#: () -> bool
|
|
473
|
+
def trim_empty_rows
|
|
474
|
+
warn "[DEPRECATION] #trim_empty_rows is deprecated; use #trim_empty_rows? instead.", uplevel: 1
|
|
475
|
+
trim_empty_rows?
|
|
476
|
+
end
|
|
131
477
|
|
|
132
478
|
# Returns whether skipped rows are padded during iteration.
|
|
133
479
|
#
|
|
@@ -137,7 +483,13 @@ module Xlsxrb
|
|
|
137
483
|
def pad_empty_rows?
|
|
138
484
|
@pad_empty_rows ? true : false
|
|
139
485
|
end
|
|
140
|
-
|
|
486
|
+
|
|
487
|
+
# @deprecated Use {#pad_empty_rows?} instead. Will be removed in 0.2.0.
|
|
488
|
+
#: () -> bool
|
|
489
|
+
def pad_empty_rows
|
|
490
|
+
warn "[DEPRECATION] #pad_empty_rows is deprecated; use #pad_empty_rows? instead.", uplevel: 1
|
|
491
|
+
pad_empty_rows?
|
|
492
|
+
end
|
|
141
493
|
|
|
142
494
|
# Returns whether missing cells within rows are padded during iteration.
|
|
143
495
|
#
|
|
@@ -147,7 +499,13 @@ module Xlsxrb
|
|
|
147
499
|
def pad_empty_cells?
|
|
148
500
|
@pad_empty_cells ? true : false
|
|
149
501
|
end
|
|
150
|
-
|
|
502
|
+
|
|
503
|
+
# @deprecated Use {#pad_empty_cells?} instead. Will be removed in 0.2.0.
|
|
504
|
+
#: () -> bool
|
|
505
|
+
def pad_empty_cells
|
|
506
|
+
warn "[DEPRECATION] #pad_empty_cells is deprecated; use #pad_empty_cells? instead.", uplevel: 1
|
|
507
|
+
pad_empty_cells?
|
|
508
|
+
end
|
|
151
509
|
|
|
152
510
|
# Returns whether the worksheet uses the 1904 date system.
|
|
153
511
|
#
|
|
@@ -175,6 +533,7 @@ module Xlsxrb
|
|
|
175
533
|
#: () -> (String | Hash[Symbol, untyped])?
|
|
176
534
|
def tab_color
|
|
177
535
|
props = sheet_properties
|
|
536
|
+
props = props.to_h if props.is_a?(Elements::MetadataRecord)
|
|
178
537
|
return props[:tab_color] if props[:tab_color]
|
|
179
538
|
return { theme: props[:tab_color_theme], tint: props[:tab_color_tint] } if props[:tab_color_theme]
|
|
180
539
|
return { indexed: props[:tab_color_indexed] } if props[:tab_color_indexed]
|
|
@@ -189,7 +548,7 @@ module Xlsxrb
|
|
|
189
548
|
# @api public
|
|
190
549
|
#: () -> String?
|
|
191
550
|
def code_name
|
|
192
|
-
sheet_properties[:code_name]
|
|
551
|
+
sheet_properties.respond_to?(:code_name) ? sheet_properties.code_name : sheet_properties[:code_name]
|
|
193
552
|
end
|
|
194
553
|
|
|
195
554
|
# Returns whether fit-to-page is enabled for page setup on this worksheet.
|
|
@@ -198,9 +557,19 @@ module Xlsxrb
|
|
|
198
557
|
# @api public
|
|
199
558
|
#: () -> bool
|
|
200
559
|
def fit_to_page?
|
|
201
|
-
sheet_properties
|
|
560
|
+
if sheet_properties.respond_to?(:fit_to_page)
|
|
561
|
+
sheet_properties.fit_to_page ? true : false
|
|
562
|
+
else
|
|
563
|
+
sheet_properties[:fit_to_page] ? true : false
|
|
564
|
+
end
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
# @deprecated Use {#fit_to_page?} instead. Will be removed in 0.2.0.
|
|
568
|
+
#: () -> bool
|
|
569
|
+
def fit_to_page
|
|
570
|
+
warn "[DEPRECATION] #fit_to_page is deprecated; use #fit_to_page? instead.", uplevel: 1
|
|
571
|
+
fit_to_page?
|
|
202
572
|
end
|
|
203
|
-
alias fit_to_page fit_to_page?
|
|
204
573
|
|
|
205
574
|
# Returns whether full calculation on load is enabled on this worksheet.
|
|
206
575
|
#
|
|
@@ -208,9 +577,15 @@ module Xlsxrb
|
|
|
208
577
|
# @api public
|
|
209
578
|
#: () -> bool
|
|
210
579
|
def full_calc_on_load?
|
|
211
|
-
|
|
580
|
+
@sheet_calc_pr&.full_calc_on_load == true || sheet_properties.full_calc_on_load == true
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
# @deprecated Use {#full_calc_on_load?} instead. Will be removed in 0.2.0.
|
|
584
|
+
#: () -> bool
|
|
585
|
+
def full_calc_on_load
|
|
586
|
+
warn "[DEPRECATION] #full_calc_on_load is deprecated; use #full_calc_on_load? instead.", uplevel: 1
|
|
587
|
+
full_calc_on_load?
|
|
212
588
|
end
|
|
213
|
-
alias full_calc_on_load full_calc_on_load?
|
|
214
589
|
|
|
215
590
|
# Returns the outline and grouping properties of the worksheet, or an empty hash if none configured.
|
|
216
591
|
#
|
|
@@ -219,6 +594,7 @@ module Xlsxrb
|
|
|
219
594
|
#: () -> Hash[Symbol, untyped]
|
|
220
595
|
def outline_properties
|
|
221
596
|
props = sheet_properties
|
|
597
|
+
props = props.to_h if props.is_a?(Elements::MetadataRecord)
|
|
222
598
|
return props[:outline_properties] if props[:outline_properties]
|
|
223
599
|
|
|
224
600
|
res = {}
|
|
@@ -228,6 +604,7 @@ module Xlsxrb
|
|
|
228
604
|
res[:apply_styles] = props[:apply_styles] unless props[:apply_styles].nil?
|
|
229
605
|
res
|
|
230
606
|
end
|
|
607
|
+
# @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
|
|
231
608
|
alias outline_pr outline_properties
|
|
232
609
|
|
|
233
610
|
# Iterate over rows in the worksheet.
|
|
@@ -384,21 +761,23 @@ module Xlsxrb
|
|
|
384
761
|
# Returns all images anchored at a specific cell reference or 0-based coordinate.
|
|
385
762
|
#
|
|
386
763
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
387
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
764
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
388
765
|
# @return [Array<Elements::Image>]
|
|
389
766
|
# @api public
|
|
390
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
767
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Array[Elements::Image]
|
|
391
768
|
def images_at(ref_or_row, col = nil)
|
|
392
769
|
ref = if col
|
|
393
|
-
|
|
770
|
+
c_idx = col.is_a?(Integer) ? col : Cell._column_index(col)
|
|
771
|
+
"#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
394
772
|
else
|
|
395
773
|
ref_or_row.to_s.upcase
|
|
396
774
|
end
|
|
397
|
-
images.select { |img| img.
|
|
775
|
+
images.select { |img| img.ref == ref }
|
|
398
776
|
end
|
|
399
777
|
|
|
400
778
|
# Yields self with images loaded or returns self.
|
|
401
779
|
#
|
|
780
|
+
# @deprecated Access {#images} directly. Lazy-loading is automatic. Will be removed in 0.2.0.
|
|
402
781
|
# @yield [sheet]
|
|
403
782
|
# @yieldparam sheet [Elements::Worksheet]
|
|
404
783
|
# @return [Elements::Worksheet, void]
|
|
@@ -406,6 +785,7 @@ module Xlsxrb
|
|
|
406
785
|
#: () { (Elements::Worksheet) -> void } -> void
|
|
407
786
|
#: () -> Elements::Worksheet
|
|
408
787
|
def with_images
|
|
788
|
+
warn "[DEPRECATION] `with_images` is deprecated; access `images` directly.", uplevel: 1
|
|
409
789
|
if block_given?
|
|
410
790
|
yield self
|
|
411
791
|
nil
|
|
@@ -452,13 +832,14 @@ module Xlsxrb
|
|
|
452
832
|
# Returns hyperlink metadata for the given cell reference, or nil.
|
|
453
833
|
#
|
|
454
834
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
455
|
-
# @param col [Integer, nil] Optional 0-based column index
|
|
456
|
-
# @return [
|
|
835
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
836
|
+
# @return [Elements::Hyperlink, nil]
|
|
457
837
|
# @api public
|
|
458
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
838
|
+
#: (String | Symbol | Integer | nil ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Hyperlink?
|
|
459
839
|
def hyperlink(ref_or_row, col = nil)
|
|
460
840
|
ref = if col
|
|
461
|
-
|
|
841
|
+
c_idx = Cell._column_index(col)
|
|
842
|
+
"#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
462
843
|
else
|
|
463
844
|
ref_or_row.to_s.upcase
|
|
464
845
|
end
|
|
@@ -468,13 +849,14 @@ module Xlsxrb
|
|
|
468
849
|
# Returns comment metadata for the given cell reference, or nil.
|
|
469
850
|
#
|
|
470
851
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
471
|
-
# @param col [Integer, nil] Optional 0-based column index
|
|
472
|
-
# @return [
|
|
852
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
853
|
+
# @return [Elements::Comment, nil]
|
|
473
854
|
# @api public
|
|
474
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
855
|
+
#: (String | Symbol | Integer | nil ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Comment?
|
|
475
856
|
def comment(ref_or_row, col = nil)
|
|
476
857
|
ref = if col
|
|
477
|
-
|
|
858
|
+
c_idx = Cell._column_index(col)
|
|
859
|
+
"#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
478
860
|
else
|
|
479
861
|
ref_or_row.to_s.upcase
|
|
480
862
|
end
|
|
@@ -483,26 +865,44 @@ module Xlsxrb
|
|
|
483
865
|
|
|
484
866
|
# Returns comments indexed by cell reference.
|
|
485
867
|
#
|
|
486
|
-
# @return [Hash<String,
|
|
868
|
+
# @return [Hash<String, Elements::Comment>]
|
|
487
869
|
# @api public
|
|
488
|
-
#: () -> Hash[String,
|
|
870
|
+
#: () -> Hash[String, Elements::Comment]
|
|
489
871
|
def comments_by_ref
|
|
490
872
|
@comments_by_ref ||= @comments.each_with_object({}) do |c, acc|
|
|
491
|
-
r = c[:ref] || c[:cell]
|
|
873
|
+
r = c.respond_to?(:ref) ? c.ref : (c[:ref] || c[:cell])
|
|
492
874
|
acc[r.to_s.upcase] = c if r
|
|
493
875
|
end
|
|
494
876
|
end
|
|
495
877
|
|
|
496
|
-
# Returns threaded
|
|
878
|
+
# Returns the root threaded comment for the given cell reference, or nil.
|
|
497
879
|
#
|
|
498
880
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
499
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
500
|
-
# @return [
|
|
881
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
882
|
+
# @return [Elements::ThreadedComment, nil]
|
|
501
883
|
# @api public
|
|
502
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
884
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::ThreadedComment?
|
|
503
885
|
def threaded_comment(ref_or_row, col = nil)
|
|
504
886
|
ref = if col
|
|
505
|
-
|
|
887
|
+
c_idx = col.is_a?(Integer) ? col : Cell._column_index(col)
|
|
888
|
+
"#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
889
|
+
else
|
|
890
|
+
ref_or_row.to_s.upcase
|
|
891
|
+
end
|
|
892
|
+
threaded_comments_by_ref[ref]&.first
|
|
893
|
+
end
|
|
894
|
+
|
|
895
|
+
# Returns threaded comments for the given cell reference, or empty array.
|
|
896
|
+
#
|
|
897
|
+
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
898
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
899
|
+
# @return [Array<Elements::ThreadedComment>]
|
|
900
|
+
# @api public
|
|
901
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Array[Elements::ThreadedComment]
|
|
902
|
+
def threaded_comments_at(ref_or_row, col = nil)
|
|
903
|
+
ref = if col
|
|
904
|
+
c_idx = col.is_a?(Integer) ? col : Cell._column_index(col)
|
|
905
|
+
"#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
506
906
|
else
|
|
507
907
|
ref_or_row.to_s.upcase
|
|
508
908
|
end
|
|
@@ -511,12 +911,12 @@ module Xlsxrb
|
|
|
511
911
|
|
|
512
912
|
# Returns threaded comments indexed by cell reference.
|
|
513
913
|
#
|
|
514
|
-
# @return [Hash<String, Array<
|
|
914
|
+
# @return [Hash<String, Array<Elements::ThreadedComment>>]
|
|
515
915
|
# @api public
|
|
516
|
-
#: () -> Hash[String, Array[
|
|
916
|
+
#: () -> Hash[String, Array[Elements::ThreadedComment]]
|
|
517
917
|
def threaded_comments_by_ref
|
|
518
918
|
@threaded_comments_by_ref ||= @threaded_comments.each_with_object({}) do |c, acc|
|
|
519
|
-
r = c[:ref] || c[:cell]
|
|
919
|
+
r = c.respond_to?(:ref) ? c.ref : (c[:ref] || c[:cell])
|
|
520
920
|
(acc[r.to_s.upcase] ||= []) << c if r
|
|
521
921
|
end
|
|
522
922
|
end
|
|
@@ -524,26 +924,28 @@ module Xlsxrb
|
|
|
524
924
|
# Access a cell by reference or 0-based coordinates.
|
|
525
925
|
#
|
|
526
926
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
527
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
927
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
928
|
+
# @return [Elements::Cell, nil]
|
|
929
|
+
# @api public
|
|
930
|
+
# Access a cell by reference (e.g. "A1") or 0-based coordinate indices (row, col).
|
|
931
|
+
#
|
|
932
|
+
# @deprecated Use {#[]} instead (e.g. sheet["A1"] or sheet[0, 0]). Will be removed in 0.2.0.
|
|
933
|
+
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
934
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
528
935
|
# @return [Elements::Cell, nil]
|
|
529
936
|
# @api public
|
|
530
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
937
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Cell?
|
|
531
938
|
def cell(ref_or_row, col = nil)
|
|
532
|
-
|
|
533
|
-
row = row_at(ref_or_row.to_i)
|
|
534
|
-
row&.cell_at(col.to_i)
|
|
535
|
-
else
|
|
536
|
-
self[ref_or_row]
|
|
537
|
-
end
|
|
939
|
+
self[ref_or_row, col]
|
|
538
940
|
end
|
|
539
941
|
|
|
540
942
|
# Returns the formatted string representation of a cell's value.
|
|
541
943
|
#
|
|
542
944
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
543
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
945
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
544
946
|
# @return [String, nil]
|
|
545
947
|
# @api public
|
|
546
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
948
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> String?
|
|
547
949
|
def formatted_value(ref_or_row, col = nil)
|
|
548
950
|
cell(ref_or_row, col)&.formatted_value
|
|
549
951
|
end
|
|
@@ -553,20 +955,37 @@ module Xlsxrb
|
|
|
553
955
|
# @example
|
|
554
956
|
# new_sheet = sheet.update_cell("B1", value: "Updated")
|
|
555
957
|
#
|
|
556
|
-
# @param
|
|
958
|
+
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "B1") or 0-based row index.
|
|
959
|
+
# @param col_or_value [Integer, String, Symbol, nil] 0-based column index or column letter/Symbol when ref_or_row is a row index.
|
|
557
960
|
# @param value [Object] The new cell value.
|
|
558
|
-
# @param
|
|
961
|
+
# @param style [String, Symbol, Hash, nil] Optional new style name or inline style properties.
|
|
962
|
+
# @param style_index [Integer, nil] Optional new 0-based style index.
|
|
559
963
|
# @param formula [Elements::Formula, nil] Optional new formula.
|
|
560
964
|
# @param hyperlink [Hash, String, nil] Optional new hyperlink.
|
|
965
|
+
# @deprecated Use {Xlsxrb.read} + {Xlsxrb.write} for streaming transformations or {Xlsxrb.write} DSL for report generation. Will be removed in 0.2.0.
|
|
561
966
|
# @param comment [Hash, String, nil] Optional new comment.
|
|
562
967
|
# @return [Worksheet] A new Worksheet instance.
|
|
563
968
|
# @api public
|
|
564
|
-
#: (String
|
|
565
|
-
def update_cell(
|
|
566
|
-
|
|
567
|
-
|
|
969
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col_or_value, ?value: untyped, ?style: (String | Symbol | Hash[Symbol, untyped])?, ?style_index: (Integer | String | Symbol | Hash[Symbol, untyped])?, ?formula: Elements::Formula?, ?hyperlink: (Hash[Symbol, untyped] | String)?, ?comment: (Hash[Symbol, untyped] | String)?) -> Elements::Worksheet
|
|
970
|
+
def update_cell(ref_or_row, col_or_value = nil, value: nil, style: nil, style_index: nil, formula: nil, hyperlink: nil, comment: nil)
|
|
971
|
+
warn "[DEPRECATION] Elements::Worksheet#update_cell is deprecated and will be removed in 0.2.0; use Xlsxrb.read + Xlsxrb.write for streaming transformations or Xlsxrb.write DSL for report generation.", uplevel: 1
|
|
972
|
+
if style_index && !style_index.is_a?(Integer)
|
|
973
|
+
warn "[DEPRECATION] Elements::Worksheet#update_cell passing non-Integer to style_index: is deprecated; use style: instead.", uplevel: 1
|
|
974
|
+
style ||= style_index
|
|
975
|
+
style_index = nil
|
|
976
|
+
end
|
|
977
|
+
if col_or_value
|
|
978
|
+
c_idx = col_or_value.is_a?(Integer) ? col_or_value : Cell._column_index(col_or_value)
|
|
979
|
+
row_idx = ref_or_row.to_i
|
|
980
|
+
ref = "#{Cell._column_letter(c_idx)}#{row_idx + 1}"
|
|
981
|
+
col_idx = c_idx
|
|
982
|
+
else
|
|
983
|
+
ref = ref_or_row.to_s.upcase
|
|
984
|
+
parsed = Cell._parse_ref(ref)
|
|
985
|
+
raise ArgumentError, "invalid cell reference: #{ref}" unless parsed
|
|
568
986
|
|
|
569
|
-
|
|
987
|
+
row_idx, col_idx = parsed
|
|
988
|
+
end
|
|
570
989
|
existing_row = row_at(row_idx)
|
|
571
990
|
|
|
572
991
|
if existing_row
|
|
@@ -574,13 +993,14 @@ module Xlsxrb
|
|
|
574
993
|
new_cell = if existing_cell
|
|
575
994
|
existing_cell.with(
|
|
576
995
|
value: value || existing_cell.value,
|
|
577
|
-
|
|
996
|
+
style: style || (style_index ? nil : existing_cell.style),
|
|
997
|
+
style_index: style_index || (style ? nil : existing_cell.style_index),
|
|
578
998
|
formula: formula || existing_cell.formula,
|
|
579
999
|
hyperlink: hyperlink || existing_cell.hyperlink,
|
|
580
1000
|
comment: comment || existing_cell.comment
|
|
581
1001
|
)
|
|
582
1002
|
else
|
|
583
|
-
Cell.new(row_index: row_idx, column_index: col_idx, value: value, style_index: style_index, formula: formula, hyperlink: hyperlink, comment: comment)
|
|
1003
|
+
Cell.new(row_index: row_idx, column_index: col_idx, value: value, style: style, style_index: style_index, formula: formula, hyperlink: hyperlink, comment: comment)
|
|
584
1004
|
end
|
|
585
1005
|
|
|
586
1006
|
# Replace cell in the existing row
|
|
@@ -592,14 +1012,14 @@ module Xlsxrb
|
|
|
592
1012
|
new_rows = rows.map { |r| r.index == row_idx ? new_row : r }
|
|
593
1013
|
else
|
|
594
1014
|
# Row doesn't exist, create it
|
|
595
|
-
new_cell = Cell.new(row_index: row_idx, column_index: col_idx, value: value, style_index: style_index, formula: formula, hyperlink: hyperlink, comment: comment)
|
|
1015
|
+
new_cell = Cell.new(row_index: row_idx, column_index: col_idx, value: value, style: style, style_index: style_index, formula: formula, hyperlink: hyperlink, comment: comment)
|
|
596
1016
|
new_row = Row.new(index: row_idx, cells: [new_cell])
|
|
597
1017
|
new_rows = (rows + [new_row]).sort_by!(&:index)
|
|
598
1018
|
end
|
|
599
1019
|
new_hyperlinks = hyperlink ? hyperlinks.merge(ref.upcase => hyperlink) : hyperlinks
|
|
600
1020
|
new_comments = if comment
|
|
601
1021
|
entry = comment.is_a?(Hash) ? comment.merge(ref: ref.upcase) : { ref: ref.upcase, text: comment }
|
|
602
|
-
@comments.reject { |c| (c[:ref] || c[:cell])&.to_s&.upcase == ref.upcase } + [entry]
|
|
1022
|
+
@comments.reject { |c| (c.respond_to?(:ref) ? c.ref : (c[:ref] || c[:cell]))&.to_s&.upcase == ref.upcase } + [entry]
|
|
603
1023
|
else
|
|
604
1024
|
@comments
|
|
605
1025
|
end
|
|
@@ -626,22 +1046,46 @@ module Xlsxrb
|
|
|
626
1046
|
end
|
|
627
1047
|
new_dv = changes.key?(:data_validations) ? changes[:data_validations] : data_validations
|
|
628
1048
|
new_unmapped = changes.key?(:unmapped_data) ? changes[:unmapped_data] : unmapped_data
|
|
1049
|
+
if new_unmapped.is_a?(Hash) && new_unmapped[:facade].is_a?(Hash)
|
|
1050
|
+
stale_keys = changes.keys.select { |k| new_unmapped[:facade].key?(k) }
|
|
1051
|
+
stale_keys << :col_breaks if changes.key?(:column_breaks) && new_unmapped[:facade].key?(:col_breaks)
|
|
1052
|
+
stale_keys << :sheet_calc_pr if changes.key?(:sheet_calc_properties) && new_unmapped[:facade].key?(:sheet_calc_pr)
|
|
1053
|
+
stale_keys << :merge_cells if changes.key?(:merged_cells) && new_unmapped[:facade].key?(:merge_cells)
|
|
1054
|
+
unless stale_keys.empty?
|
|
1055
|
+
new_unmapped = new_unmapped.dup
|
|
1056
|
+
new_facade = new_unmapped[:facade].dup
|
|
1057
|
+
stale_keys.each { |k| new_facade.delete(k) }
|
|
1058
|
+
new_unmapped[:facade] = new_facade
|
|
1059
|
+
end
|
|
1060
|
+
end
|
|
629
1061
|
new_errors = changes.key?(:errors) ? changes[:errors] : errors
|
|
630
1062
|
new_state = changes.key?(:state) ? changes[:state] : state
|
|
631
1063
|
new_hyperlinks = changes.key?(:hyperlinks) ? changes[:hyperlinks] : hyperlinks
|
|
632
1064
|
new_comments = changes.key?(:comments) ? changes[:comments] : comments
|
|
633
1065
|
new_styles = changes.key?(:styles) ? changes[:styles] : styles
|
|
634
1066
|
new_date1904 = changes.key?(:date1904) ? changes[:date1904] : date1904
|
|
635
|
-
new_dim = changes.key?(:dimension)
|
|
1067
|
+
new_dim = if changes.key?(:dimension)
|
|
1068
|
+
changes[:dimension]
|
|
1069
|
+
else
|
|
1070
|
+
(changes.key?(:rows) ? nil : @dimension)
|
|
1071
|
+
end
|
|
636
1072
|
new_print_area = changes.key?(:print_area) ? changes[:print_area] : print_area
|
|
637
1073
|
new_print_titles = changes.key?(:print_titles) ? changes[:print_titles] : print_titles
|
|
638
1074
|
new_sparklines = changes.key?(:sparkline_groups) ? changes[:sparkline_groups] : sparkline_groups
|
|
639
1075
|
new_trim = changes.key?(:trim_empty_rows) ? changes[:trim_empty_rows] : @trim_empty_rows
|
|
1076
|
+
new_pad_rows = changes.key?(:pad_empty_rows) ? changes[:pad_empty_rows] : @pad_empty_rows
|
|
1077
|
+
new_pad_cells = changes.key?(:pad_empty_cells) ? changes[:pad_empty_cells] : @pad_empty_cells
|
|
1078
|
+
new_images = changes.key?(:images) ? changes[:images] : images
|
|
640
1079
|
new_merged = changes.key?(:merged_cells) ? changes[:merged_cells] : merged_cells
|
|
641
1080
|
new_auto_filter = changes.key?(:auto_filter) ? changes[:auto_filter] : auto_filter
|
|
642
1081
|
new_tables = changes.key?(:tables) ? changes[:tables] : tables
|
|
643
1082
|
new_shapes = changes.key?(:shapes) ? changes[:shapes] : shapes
|
|
644
1083
|
new_freeze_pane = changes.key?(:freeze_pane) ? changes[:freeze_pane] : freeze_pane
|
|
1084
|
+
new_split_pane = changes.key?(:split_pane) ? changes[:split_pane] : split_pane
|
|
1085
|
+
new_pivot_tables = changes.key?(:pivot_tables) ? changes[:pivot_tables] : pivot_tables
|
|
1086
|
+
new_filter_columns = changes.key?(:filter_columns) ? changes[:filter_columns] : filter_columns
|
|
1087
|
+
new_sort_state = changes.key?(:sort_state) ? changes[:sort_state] : sort_state
|
|
1088
|
+
new_header_footer_images = changes.key?(:header_footer_images) ? changes[:header_footer_images] : header_footer_images
|
|
645
1089
|
new_page_setup = changes.key?(:page_setup) ? changes[:page_setup] : page_setup
|
|
646
1090
|
new_page_margins = changes.key?(:page_margins) ? changes[:page_margins] : page_margins
|
|
647
1091
|
new_header_footer = changes.key?(:header_footer) ? changes[:header_footer] : header_footer
|
|
@@ -651,24 +1095,43 @@ module Xlsxrb
|
|
|
651
1095
|
new_sheet_properties = changes.key?(:sheet_properties) ? changes[:sheet_properties] : sheet_properties
|
|
652
1096
|
new_sheet_format = changes.key?(:sheet_format) ? changes[:sheet_format] : sheet_format
|
|
653
1097
|
new_row_breaks = changes.key?(:row_breaks) ? changes[:row_breaks] : row_breaks
|
|
654
|
-
new_col_breaks = changes.key?(:
|
|
1098
|
+
new_col_breaks = if changes.key?(:column_breaks)
|
|
1099
|
+
changes[:column_breaks]
|
|
1100
|
+
elsif changes.key?(:col_breaks)
|
|
1101
|
+
changes[:col_breaks]
|
|
1102
|
+
else
|
|
1103
|
+
@column_breaks
|
|
1104
|
+
end
|
|
655
1105
|
new_protected_ranges = changes.key?(:protected_ranges) ? changes[:protected_ranges] : protected_ranges
|
|
656
1106
|
new_cell_watches = changes.key?(:cell_watches) ? changes[:cell_watches] : cell_watches
|
|
657
1107
|
new_ignored_errors = changes.key?(:ignored_errors) ? changes[:ignored_errors] : ignored_errors
|
|
658
1108
|
new_phonetic_properties = if changes.key?(:phonetic_properties)
|
|
659
1109
|
changes[:phonetic_properties]
|
|
660
1110
|
elsif changes.key?(:phonetic_pr)
|
|
1111
|
+
warn "[Xlsxrb DEPRECATION] Worksheet#with(:phonetic_pr) is deprecated and will be removed in v0.2.0. Use :phonetic_properties instead.", uplevel: 1
|
|
661
1112
|
changes[:phonetic_pr]
|
|
662
1113
|
else
|
|
663
1114
|
phonetic_properties
|
|
664
1115
|
end
|
|
665
1116
|
new_selection = changes.key?(:selection) ? changes[:selection] : selection
|
|
666
|
-
new_sheet_calc_pr = changes.key?(:
|
|
1117
|
+
new_sheet_calc_pr = if changes.key?(:sheet_calc_properties)
|
|
1118
|
+
changes[:sheet_calc_properties]
|
|
1119
|
+
elsif changes.key?(:sheet_calc_pr)
|
|
1120
|
+
warn "[Xlsxrb DEPRECATION] Worksheet#with(:sheet_calc_pr) is deprecated and will be removed in v0.2.0. Use :sheet_calc_properties instead.", uplevel: 1
|
|
1121
|
+
changes[:sheet_calc_pr]
|
|
1122
|
+
elsif changes.key?(:calc_pr)
|
|
1123
|
+
warn "[Xlsxrb DEPRECATION] Worksheet#with(:calc_pr) is deprecated and will be removed in v0.2.0. Use :sheet_calc_properties instead.", uplevel: 1
|
|
1124
|
+
changes[:calc_pr]
|
|
1125
|
+
else
|
|
1126
|
+
@sheet_calc_pr
|
|
1127
|
+
end
|
|
667
1128
|
new_background_image = if changes.key?(:background_image)
|
|
668
1129
|
changes[:background_image]
|
|
669
1130
|
elsif changes.key?(:background_picture)
|
|
1131
|
+
warn "[Xlsxrb DEPRECATION] Worksheet#with(:background_picture) is deprecated and will be removed in v0.2.0. Use :background_image instead.", uplevel: 1
|
|
670
1132
|
changes[:background_picture]
|
|
671
1133
|
elsif changes.key?(:picture)
|
|
1134
|
+
warn "[Xlsxrb DEPRECATION] Worksheet#with(:picture) is deprecated and will be removed in v0.2.0. Use :background_image instead.", uplevel: 1
|
|
672
1135
|
changes[:picture]
|
|
673
1136
|
else
|
|
674
1137
|
background_image
|
|
@@ -680,13 +1143,14 @@ module Xlsxrb
|
|
|
680
1143
|
rows: new_rows,
|
|
681
1144
|
columns: new_cols,
|
|
682
1145
|
charts: new_charts,
|
|
683
|
-
|
|
1146
|
+
conditional_formats: new_cf,
|
|
684
1147
|
data_validations: new_dv,
|
|
685
1148
|
unmapped_data: new_unmapped,
|
|
686
1149
|
errors: new_errors,
|
|
687
1150
|
state: new_state,
|
|
688
1151
|
hyperlinks: new_hyperlinks,
|
|
689
1152
|
comments: new_comments,
|
|
1153
|
+
images: new_images,
|
|
690
1154
|
styles: new_styles,
|
|
691
1155
|
date1904: new_date1904,
|
|
692
1156
|
dimension: new_dim,
|
|
@@ -694,11 +1158,18 @@ module Xlsxrb
|
|
|
694
1158
|
print_titles: new_print_titles,
|
|
695
1159
|
sparkline_groups: new_sparklines,
|
|
696
1160
|
trim_empty_rows: new_trim,
|
|
1161
|
+
pad_empty_rows: new_pad_rows,
|
|
1162
|
+
pad_empty_cells: new_pad_cells,
|
|
697
1163
|
merged_cells: new_merged,
|
|
698
1164
|
auto_filter: new_auto_filter,
|
|
699
1165
|
tables: new_tables,
|
|
700
1166
|
shapes: new_shapes,
|
|
701
1167
|
freeze_pane: new_freeze_pane,
|
|
1168
|
+
split_pane: new_split_pane,
|
|
1169
|
+
pivot_tables: new_pivot_tables,
|
|
1170
|
+
filter_columns: new_filter_columns,
|
|
1171
|
+
sort_state: new_sort_state,
|
|
1172
|
+
header_footer_images: new_header_footer_images,
|
|
702
1173
|
page_setup: new_page_setup,
|
|
703
1174
|
page_margins: new_page_margins,
|
|
704
1175
|
header_footer: new_header_footer,
|
|
@@ -708,13 +1179,13 @@ module Xlsxrb
|
|
|
708
1179
|
sheet_properties: new_sheet_properties,
|
|
709
1180
|
sheet_format: new_sheet_format,
|
|
710
1181
|
row_breaks: new_row_breaks,
|
|
711
|
-
|
|
1182
|
+
column_breaks: new_col_breaks,
|
|
712
1183
|
protected_ranges: new_protected_ranges,
|
|
713
1184
|
cell_watches: new_cell_watches,
|
|
714
1185
|
ignored_errors: new_ignored_errors,
|
|
715
1186
|
phonetic_properties: new_phonetic_properties,
|
|
716
1187
|
selection: new_selection,
|
|
717
|
-
|
|
1188
|
+
sheet_calc_properties: new_sheet_calc_pr,
|
|
718
1189
|
background_image: new_background_image,
|
|
719
1190
|
threaded_comments: new_threaded_comments
|
|
720
1191
|
)
|
|
@@ -738,17 +1209,25 @@ module Xlsxrb
|
|
|
738
1209
|
comments: comments,
|
|
739
1210
|
threaded_comments: threaded_comments,
|
|
740
1211
|
styles: styles,
|
|
741
|
-
date1904: date1904
|
|
1212
|
+
date1904: date1904?,
|
|
742
1213
|
dimension: dimension,
|
|
743
1214
|
print_area: print_area,
|
|
744
1215
|
print_titles: print_titles,
|
|
745
1216
|
sparkline_groups: sparkline_groups,
|
|
746
1217
|
trim_empty_rows: @trim_empty_rows,
|
|
1218
|
+
pad_empty_rows: @pad_empty_rows,
|
|
1219
|
+
pad_empty_cells: @pad_empty_cells,
|
|
747
1220
|
merged_cells: merged_cells,
|
|
748
1221
|
auto_filter: auto_filter,
|
|
749
1222
|
tables: tables,
|
|
750
1223
|
shapes: shapes,
|
|
751
1224
|
freeze_pane: freeze_pane,
|
|
1225
|
+
split_pane: split_pane,
|
|
1226
|
+
pivot_tables: pivot_tables,
|
|
1227
|
+
filter_columns: filter_columns,
|
|
1228
|
+
sort_state: sort_state,
|
|
1229
|
+
images: images,
|
|
1230
|
+
header_footer_images: header_footer_images,
|
|
752
1231
|
page_setup: page_setup,
|
|
753
1232
|
page_margins: page_margins,
|
|
754
1233
|
header_footer: header_footer,
|
|
@@ -758,6 +1237,7 @@ module Xlsxrb
|
|
|
758
1237
|
sheet_properties: sheet_properties,
|
|
759
1238
|
sheet_format: sheet_format,
|
|
760
1239
|
row_breaks: row_breaks,
|
|
1240
|
+
column_breaks: column_breaks,
|
|
761
1241
|
col_breaks: col_breaks,
|
|
762
1242
|
protected_ranges: protected_ranges,
|
|
763
1243
|
cell_watches: cell_watches,
|
|
@@ -765,8 +1245,9 @@ module Xlsxrb
|
|
|
765
1245
|
phonetic_properties: phonetic_properties,
|
|
766
1246
|
phonetic_pr: phonetic_properties,
|
|
767
1247
|
selection: selection,
|
|
768
|
-
|
|
769
|
-
|
|
1248
|
+
sheet_calc_properties: sheet_calc_properties,
|
|
1249
|
+
sheet_calc_pr: @sheet_calc_pr,
|
|
1250
|
+
calc_pr: @sheet_calc_pr,
|
|
770
1251
|
code_name: code_name,
|
|
771
1252
|
background_image: background_image,
|
|
772
1253
|
background_picture: background_image,
|
|
@@ -789,10 +1270,10 @@ module Xlsxrb
|
|
|
789
1270
|
header_footer == other.header_footer && print_options == other.print_options &&
|
|
790
1271
|
sheet_protection == other.sheet_protection && sheet_view == other.sheet_view &&
|
|
791
1272
|
sheet_properties == other.sheet_properties && sheet_format == other.sheet_format &&
|
|
792
|
-
row_breaks == other.row_breaks &&
|
|
1273
|
+
row_breaks == other.row_breaks && column_breaks == other.column_breaks &&
|
|
793
1274
|
protected_ranges == other.protected_ranges && cell_watches == other.cell_watches &&
|
|
794
1275
|
ignored_errors == other.ignored_errors && phonetic_properties == other.phonetic_properties &&
|
|
795
|
-
selection == other.selection &&
|
|
1276
|
+
selection == other.selection && sheet_calc_properties == other.sheet_calc_properties &&
|
|
796
1277
|
background_image == other.background_image
|
|
797
1278
|
end
|
|
798
1279
|
alias eql? ==
|
|
@@ -804,7 +1285,7 @@ module Xlsxrb
|
|
|
804
1285
|
state, hyperlinks, comments, threaded_comments, merged_cells, auto_filter, tables, shapes, freeze_pane,
|
|
805
1286
|
page_setup, page_margins, header_footer, print_options, sheet_protection, sheet_view,
|
|
806
1287
|
sheet_properties, sheet_format, row_breaks, col_breaks, protected_ranges,
|
|
807
|
-
cell_watches, ignored_errors, phonetic_properties, selection,
|
|
1288
|
+
cell_watches, ignored_errors, phonetic_properties, selection, sheet_calc_properties, background_image
|
|
808
1289
|
].hash
|
|
809
1290
|
end
|
|
810
1291
|
|
|
@@ -814,11 +1295,25 @@ module Xlsxrb
|
|
|
814
1295
|
# @api public
|
|
815
1296
|
#: () -> Elements::Worksheet
|
|
816
1297
|
def load
|
|
1298
|
+
Deprecation.warn("Elements::Worksheet#load is deprecated; worksheet is already loaded in memory.")
|
|
817
1299
|
self
|
|
818
1300
|
end
|
|
819
|
-
|
|
1301
|
+
|
|
1302
|
+
# @deprecated Use {#load} instead. Will be removed in 0.2.0.
|
|
1303
|
+
#: () -> Elements::Worksheet
|
|
1304
|
+
def to_worksheet
|
|
1305
|
+
warn "[DEPRECATION] #to_worksheet is deprecated; use #load instead.", uplevel: 1
|
|
1306
|
+
load
|
|
1307
|
+
end
|
|
820
1308
|
|
|
821
1309
|
FORBIDDEN_NAME_CHARS = %r{[\\/?*\[\]:]|[\x00-\x08\x0B\x0C\x0E-\x1F]}
|
|
1310
|
+
private_constant :FORBIDDEN_NAME_CHARS
|
|
1311
|
+
|
|
1312
|
+
# @api private
|
|
1313
|
+
#: () -> Regexp
|
|
1314
|
+
def self.forbidden_name_chars
|
|
1315
|
+
FORBIDDEN_NAME_CHARS
|
|
1316
|
+
end
|
|
822
1317
|
|
|
823
1318
|
# Returns whether the worksheet name is valid according to OOXML specifications (1..31 chars, no forbidden chars).
|
|
824
1319
|
#
|
|
@@ -839,6 +1334,7 @@ module Xlsxrb
|
|
|
839
1334
|
# @param name [String]
|
|
840
1335
|
# @param rows [Array<Elements::Row>]
|
|
841
1336
|
# @return [Array<String>] List of errors.
|
|
1337
|
+
# @api private
|
|
842
1338
|
#: (untyped name, untyped rows) -> Array[String]
|
|
843
1339
|
def self.validate(name, rows)
|
|
844
1340
|
errs = []
|
|
@@ -885,8 +1381,8 @@ module Xlsxrb
|
|
|
885
1381
|
|
|
886
1382
|
return nil if min_r.nil? || min_c.nil?
|
|
887
1383
|
|
|
888
|
-
start_cell = "#{Elements::Cell.
|
|
889
|
-
end_cell = "#{Elements::Cell.
|
|
1384
|
+
start_cell = "#{Elements::Cell._column_letter(min_c)}#{min_r + 1}"
|
|
1385
|
+
end_cell = "#{Elements::Cell._column_letter(max_c)}#{max_r + 1}"
|
|
890
1386
|
start_cell == end_cell ? start_cell : "#{start_cell}:#{end_cell}"
|
|
891
1387
|
end
|
|
892
1388
|
end
|