xlsxrb 0.1.16 → 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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/README.md +81 -21
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +619 -98
  6. data/lib/xlsxrb/dsl_helpers.rb +583 -15
  7. data/lib/xlsxrb/elements/cell.rb +265 -53
  8. data/lib/xlsxrb/elements/column.rb +95 -6
  9. data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
  10. data/lib/xlsxrb/elements/image.rb +81 -15
  11. data/lib/xlsxrb/elements/metadata.rb +2733 -0
  12. data/lib/xlsxrb/elements/row.rb +130 -46
  13. data/lib/xlsxrb/elements/styles.rb +184 -76
  14. data/lib/xlsxrb/elements/types.rb +243 -7
  15. data/lib/xlsxrb/elements/workbook.rb +202 -65
  16. data/lib/xlsxrb/elements/worksheet.rb +728 -85
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
  22. data/lib/xlsxrb/ooxml/reader.rb +92 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
  24. data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
  25. data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
  26. data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
  27. data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
  28. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
  29. data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
  30. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
  31. data/lib/xlsxrb/ooxml/writer.rb +288 -35
  32. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  33. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  34. data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
  35. data/lib/xlsxrb/stream_row.rb +97 -18
  36. data/lib/xlsxrb/stream_sheet.rb +827 -157
  37. data/lib/xlsxrb/stream_writer.rb +2766 -375
  38. data/lib/xlsxrb/style_builder.rb +821 -105
  39. data/lib/xlsxrb/utils.rb +82 -57
  40. data/lib/xlsxrb/version.rb +1 -1
  41. data/lib/xlsxrb/workbook_builder.rb +542 -62
  42. data/lib/xlsxrb/worksheet_builder.rb +2279 -209
  43. data/lib/xlsxrb.rb +1539 -344
  44. data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
  45. data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
  46. data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
  47. data/sig/generated/xlsxrb/elements/column.rbs +62 -3
  48. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  49. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  50. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  51. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  52. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  53. data/sig/generated/xlsxrb/elements/types.rbs +29 -0
  54. data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
  55. data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
  56. data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
  57. data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
  58. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
  59. data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
  60. data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
  61. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
  62. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
  63. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
  64. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
  65. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
  66. data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
  67. data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
  68. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  69. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  70. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
  71. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  72. data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
  73. data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
  74. data/sig/generated/xlsxrb/style_builder.rbs +403 -75
  75. data/sig/generated/xlsxrb/utils.rbs +49 -13
  76. data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
  77. data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
  78. data/sig/generated/xlsxrb.rbs +321 -52
  79. metadata +3 -1
@@ -17,9 +17,177 @@ module Xlsxrb
17
17
  class Worksheet
18
18
  [Enumerable, CoordinateAccess].each { |m| include m }
19
19
 
20
- attr_reader :name, :rows, :columns, :charts, :conditional_formatting, :data_validations, :unmapped_data, :errors, :state, :hyperlinks, :comments, :images, :styles, :date1904, :print_area, :print_titles, :sparkline_groups, :merged_cells, :auto_filter, :tables, :shapes, :freeze_pane, :page_setup, :page_margins, :header_footer, :print_options, :sheet_protection, :sheet_view, :sheet_properties, :sheet_format, :row_breaks, :col_breaks, :protected_ranges, :cell_watches, :selection
21
- attr_writer :dimension
22
- alias conditional_formats conditional_formatting
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.
186
+ alias phonetic_pr phonetic_properties
187
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
188
+ alias background_picture background_image
189
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
190
+ alias picture background_image
23
191
 
24
192
  # @param name [String] The worksheet name (max 31 characters).
25
193
  # @param rows [Array<Elements::Row>] Rows in the sheet.
@@ -56,53 +224,239 @@ module Xlsxrb
56
224
  # @param sheet_properties [Hash] Sheet properties (e.g. tabColor, outlinePr).
57
225
  # @param sheet_format [Hash] Sheet format properties (e.g. defaultRowHeight, defaultColWidth).
58
226
  # @param row_breaks [Array<Integer | Hash>] Explicit page row breaks.
59
- # @param col_breaks [Array<Integer | Hash>] Explicit page column breaks.
227
+ # @param column_breaks [Array<Integer | Hash>] Explicit page column breaks.
228
+ # @param col_breaks [Array<Integer | Hash>] Deprecated alias for column_breaks.
60
229
  # @param protected_ranges [Array<Hash>] Protected range definitions.
61
230
  # @param cell_watches [Array<String>] Watched cell references.
231
+ # @param ignored_errors [Array<Hash>] Ignored error rules.
232
+ # @param phonetic_properties [Hash, nil] Phonetic text properties.
62
233
  # @param selection [Hash, Array<Hash>, nil] Active cell and selection settings.
63
- #: (name: String?, ?rows: Array[Elements::Row], ?columns: Array[Elements::Column], ?charts: Array[Hash[Symbol, untyped]], ?conditional_formatting: Array[Hash[Symbol, untyped]]?, ?data_validations: Array[Hash[Symbol, untyped]], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?, ?conditional_formats: Array[Hash[Symbol, untyped]]?, ?state: Symbol, ?hyperlinks: Hash[String, untyped], ?comments: Array[Hash[Symbol, 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: Hash[Symbol, untyped]?, ?sparkline_groups: Array[Hash[Symbol, untyped]], ?merged_cells: Array[String], ?auto_filter: String?, ?tables: Array[Hash[Symbol, untyped]], ?shapes: Array[Hash[Symbol, untyped]], ?freeze_pane: Hash[Symbol, untyped]?, ?page_setup: Hash[Symbol, untyped], ?page_margins: Hash[Symbol, untyped]?, ?header_footer: Hash[Symbol, untyped], ?print_options: Hash[Symbol, untyped], ?sheet_protection: Hash[Symbol, untyped]?, ?sheet_view: Hash[Symbol, untyped], ?sheet_properties: Hash[Symbol, untyped], ?sheet_format: Hash[Symbol, untyped], ?row_breaks: Array[untyped], ?col_breaks: Array[untyped], ?protected_ranges: Array[Hash[Symbol, untyped]], ?cell_watches: Array[String], ?selection: (Hash[Symbol, untyped] | Array[Hash[Symbol, untyped]])?) -> void
64
- 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: [], protected_ranges: [], cell_watches: [], selection: nil)
234
+ # @param sheet_calc_pr [Hash, nil] Worksheet calculation properties.
235
+ # @param background_image [Hash, nil] Worksheet background image specification.
236
+ # @param threaded_comments [Array<Hash>] Threaded comments in the sheet.
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?
65
242
  @name = name
66
243
  @rows = (rows || []).freeze
67
244
  @columns = (columns || []).freeze
68
- @charts = (charts || []).freeze
69
- cf = conditional_formatting || conditional_formats || []
70
- @conditional_formatting = cf.freeze
71
- @data_validations = (data_validations || []).freeze
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
72
257
  @unmapped_data = (unmapped_data || {}).freeze
73
258
  computed_errors = errors || self.class.validate(@name, @rows)
74
259
  @errors = computed_errors.freeze
75
260
  @state = state ? state.to_sym : :visible
76
- @hyperlinks = (hyperlinks || {}).freeze
77
- @comments = (comments || []).freeze
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
78
273
  @images = (images || []).freeze
79
274
  @styles = styles
80
275
  @date1904 = date1904 ? true : false
81
276
  @dimension = dimension
82
277
  @print_area = print_area
83
- @print_titles = print_titles&.freeze
84
- @sparkline_groups = (sparkline_groups || []).freeze
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
85
301
  @trim_empty_rows = trim_empty_rows ? true : false
86
302
  @pad_empty_rows = pad_empty_rows ? true : false
87
303
  @pad_empty_cells = pad_empty_cells ? true : false
304
+ @threaded_comments = (threaded_comments || []).map { |tc| tc.is_a?(Elements::ThreadedComment) ? tc : Elements::ThreadedComment.new(**tc) }.freeze
88
305
  @merged_cells = (merged_cells || []).freeze
89
306
  @auto_filter = auto_filter
90
- @tables = (tables || []).freeze
91
- @shapes = (shapes || []).freeze
92
- @freeze_pane = freeze_pane&.freeze
93
- @page_setup = (page_setup || {}).freeze
94
- @page_margins = page_margins&.freeze
95
- @header_footer = (header_footer || {}).freeze
96
- @print_options = (print_options || {}).freeze
97
- @sheet_protection = sheet_protection&.freeze
98
- @sheet_view = (sheet_view || {}).freeze
99
- @sheet_properties = (sheet_properties || {}).freeze
100
- @sheet_format = (sheet_format || unmapped_data[:sheet_format] || unmapped_data.dig(:facade, :sheet_format) || {}).freeze
101
- @row_breaks = (row_breaks || []).freeze
102
- @col_breaks = (col_breaks || []).freeze
103
- @protected_ranges = (protected_ranges || unmapped_data[:protected_ranges] || unmapped_data.dig(:facade, :protected_ranges) || []).freeze
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
104
383
  @cell_watches = (cell_watches || unmapped_data[:cell_watches] || unmapped_data.dig(:facade, :cell_watches) || []).freeze
105
- @selection = selection&.freeze
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
106
460
  end
107
461
 
108
462
  # Returns whether trailing empty rows are omitted during iteration.
@@ -113,7 +467,13 @@ module Xlsxrb
113
467
  def trim_empty_rows?
114
468
  @trim_empty_rows ? true : false
115
469
  end
116
- alias trim_empty_rows trim_empty_rows?
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
117
477
 
118
478
  # Returns whether skipped rows are padded during iteration.
119
479
  #
@@ -123,7 +483,13 @@ module Xlsxrb
123
483
  def pad_empty_rows?
124
484
  @pad_empty_rows ? true : false
125
485
  end
126
- alias pad_empty_rows pad_empty_rows?
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
127
493
 
128
494
  # Returns whether missing cells within rows are padded during iteration.
129
495
  #
@@ -133,7 +499,13 @@ module Xlsxrb
133
499
  def pad_empty_cells?
134
500
  @pad_empty_cells ? true : false
135
501
  end
136
- alias pad_empty_cells pad_empty_cells?
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
137
509
 
138
510
  # Returns whether the worksheet uses the 1904 date system.
139
511
  #
@@ -154,6 +526,87 @@ module Xlsxrb
154
526
  @dimension ||= compute_dimension
155
527
  end
156
528
 
529
+ # Returns the worksheet tab color specification, or nil if not set.
530
+ #
531
+ # @return [String, Hash, nil] RGB hex string (e.g. "FFFF0000") or color hash (e.g. { theme: 3, tint: -0.5 }).
532
+ # @api public
533
+ #: () -> (String | Hash[Symbol, untyped])?
534
+ def tab_color
535
+ props = sheet_properties
536
+ props = props.to_h if props.is_a?(Elements::MetadataRecord)
537
+ return props[:tab_color] if props[:tab_color]
538
+ return { theme: props[:tab_color_theme], tint: props[:tab_color_tint] } if props[:tab_color_theme]
539
+ return { indexed: props[:tab_color_indexed] } if props[:tab_color_indexed]
540
+ return { auto: true } if props[:tab_color_auto]
541
+
542
+ nil
543
+ end
544
+
545
+ # Returns the internal VBA or application code name of the worksheet, or nil if not specified.
546
+ #
547
+ # @return [String, nil]
548
+ # @api public
549
+ #: () -> String?
550
+ def code_name
551
+ sheet_properties.respond_to?(:code_name) ? sheet_properties.code_name : sheet_properties[:code_name]
552
+ end
553
+
554
+ # Returns whether fit-to-page is enabled for page setup on this worksheet.
555
+ #
556
+ # @return [Boolean]
557
+ # @api public
558
+ #: () -> bool
559
+ def fit_to_page?
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?
572
+ end
573
+
574
+ # Returns whether full calculation on load is enabled on this worksheet.
575
+ #
576
+ # @return [Boolean]
577
+ # @api public
578
+ #: () -> bool
579
+ def full_calc_on_load?
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?
588
+ end
589
+
590
+ # Returns the outline and grouping properties of the worksheet, or an empty hash if none configured.
591
+ #
592
+ # @return [Hash]
593
+ # @api public
594
+ #: () -> Hash[Symbol, untyped]
595
+ def outline_properties
596
+ props = sheet_properties
597
+ props = props.to_h if props.is_a?(Elements::MetadataRecord)
598
+ return props[:outline_properties] if props[:outline_properties]
599
+
600
+ res = {}
601
+ res[:summary_below] = props[:summary_below] unless props[:summary_below].nil?
602
+ res[:summary_right] = props[:summary_right] unless props[:summary_right].nil?
603
+ res[:show_outline_symbols] = props[:show_outline_symbols] unless props[:show_outline_symbols].nil?
604
+ res[:apply_styles] = props[:apply_styles] unless props[:apply_styles].nil?
605
+ res
606
+ end
607
+ # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
608
+ alias outline_pr outline_properties
609
+
157
610
  # Iterate over rows in the worksheet.
158
611
  #
159
612
  # @example
@@ -308,21 +761,23 @@ module Xlsxrb
308
761
  # Returns all images anchored at a specific cell reference or 0-based coordinate.
309
762
  #
310
763
  # @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
311
- # @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.
312
765
  # @return [Array<Elements::Image>]
313
766
  # @api public
314
- #: (String | Symbol | Integer ref_or_row, ?Integer? col) -> Array[Elements::Image]
767
+ #: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Array[Elements::Image]
315
768
  def images_at(ref_or_row, col = nil)
316
769
  ref = if col
317
- "#{Cell.column_letter(col)}#{ref_or_row.to_i + 1}"
770
+ c_idx = col.is_a?(Integer) ? col : Cell._column_index(col)
771
+ "#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
318
772
  else
319
773
  ref_or_row.to_s.upcase
320
774
  end
321
- images.select { |img| img.cell_ref == ref }
775
+ images.select { |img| img.ref == ref }
322
776
  end
323
777
 
324
778
  # Yields self with images loaded or returns self.
325
779
  #
780
+ # @deprecated Access {#images} directly. Lazy-loading is automatic. Will be removed in 0.2.0.
326
781
  # @yield [sheet]
327
782
  # @yieldparam sheet [Elements::Worksheet]
328
783
  # @return [Elements::Worksheet, void]
@@ -330,6 +785,7 @@ module Xlsxrb
330
785
  #: () { (Elements::Worksheet) -> void } -> void
331
786
  #: () -> Elements::Worksheet
332
787
  def with_images
788
+ warn "[DEPRECATION] `with_images` is deprecated; access `images` directly.", uplevel: 1
333
789
  if block_given?
334
790
  yield self
335
791
  nil
@@ -376,13 +832,14 @@ module Xlsxrb
376
832
  # Returns hyperlink metadata for the given cell reference, or nil.
377
833
  #
378
834
  # @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
379
- # @param col [Integer, nil] Optional 0-based column index if ref_or_row is a row index.
380
- # @return [Hash, nil]
835
+ # @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
836
+ # @return [Elements::Hyperlink, nil]
381
837
  # @api public
382
- #: (String | Symbol | Integer ref_or_row, ?Integer? col) -> Hash[Symbol, untyped]?
838
+ #: (String | Symbol | Integer | nil ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Hyperlink?
383
839
  def hyperlink(ref_or_row, col = nil)
384
840
  ref = if col
385
- "#{Cell.column_letter(col)}#{ref_or_row.to_i + 1}"
841
+ c_idx = Cell._column_index(col)
842
+ "#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
386
843
  else
387
844
  ref_or_row.to_s.upcase
388
845
  end
@@ -392,13 +849,14 @@ module Xlsxrb
392
849
  # Returns comment metadata for the given cell reference, or nil.
393
850
  #
394
851
  # @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
395
- # @param col [Integer, nil] Optional 0-based column index if ref_or_row is a row index.
396
- # @return [Hash, nil]
852
+ # @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
853
+ # @return [Elements::Comment, nil]
397
854
  # @api public
398
- #: (String | Symbol | Integer ref_or_row, ?Integer? col) -> Hash[Symbol, untyped]?
855
+ #: (String | Symbol | Integer | nil ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Comment?
399
856
  def comment(ref_or_row, col = nil)
400
857
  ref = if col
401
- "#{Cell.column_letter(col)}#{ref_or_row.to_i + 1}"
858
+ c_idx = Cell._column_index(col)
859
+ "#{Cell._column_letter(c_idx)}#{ref_or_row.to_i + 1}"
402
860
  else
403
861
  ref_or_row.to_s.upcase
404
862
  end
@@ -407,39 +865,87 @@ module Xlsxrb
407
865
 
408
866
  # Returns comments indexed by cell reference.
409
867
  #
410
- # @return [Hash<String, Hash[Symbol, untyped]>]
868
+ # @return [Hash<String, Elements::Comment>]
411
869
  # @api public
412
- #: () -> Hash[String, Hash[Symbol, untyped]]
870
+ #: () -> Hash[String, Elements::Comment]
413
871
  def comments_by_ref
414
872
  @comments_by_ref ||= @comments.each_with_object({}) do |c, acc|
415
- r = c[:ref] || c[:cell]
873
+ r = c.respond_to?(:ref) ? c.ref : (c[:ref] || c[:cell])
416
874
  acc[r.to_s.upcase] = c if r
417
875
  end
418
876
  end
419
877
 
878
+ # Returns the root threaded comment for the given cell reference, or nil.
879
+ #
880
+ # @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
881
+ # @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
882
+ # @return [Elements::ThreadedComment, nil]
883
+ # @api public
884
+ #: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::ThreadedComment?
885
+ def threaded_comment(ref_or_row, col = nil)
886
+ ref = if col
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}"
906
+ else
907
+ ref_or_row.to_s.upcase
908
+ end
909
+ threaded_comments_by_ref[ref] || []
910
+ end
911
+
912
+ # Returns threaded comments indexed by cell reference.
913
+ #
914
+ # @return [Hash<String, Array<Elements::ThreadedComment>>]
915
+ # @api public
916
+ #: () -> Hash[String, Array[Elements::ThreadedComment]]
917
+ def threaded_comments_by_ref
918
+ @threaded_comments_by_ref ||= @threaded_comments.each_with_object({}) do |c, acc|
919
+ r = c.respond_to?(:ref) ? c.ref : (c[:ref] || c[:cell])
920
+ (acc[r.to_s.upcase] ||= []) << c if r
921
+ end
922
+ end
923
+
420
924
  # Access a cell by reference or 0-based coordinates.
421
925
  #
422
926
  # @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
423
- # @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.
424
928
  # @return [Elements::Cell, nil]
425
929
  # @api public
426
- #: (String | Symbol | Integer ref_or_row, ?Integer? col) -> Elements::Cell?
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.
935
+ # @return [Elements::Cell, nil]
936
+ # @api public
937
+ #: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Cell?
427
938
  def cell(ref_or_row, col = nil)
428
- if col
429
- row = row_at(ref_or_row.to_i)
430
- row&.cell_at(col.to_i)
431
- else
432
- self[ref_or_row]
433
- end
939
+ self[ref_or_row, col]
434
940
  end
435
941
 
436
942
  # Returns the formatted string representation of a cell's value.
437
943
  #
438
944
  # @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
439
- # @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.
440
946
  # @return [String, nil]
441
947
  # @api public
442
- #: (String | Symbol | Integer ref_or_row, ?Integer? col) -> String?
948
+ #: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> String?
443
949
  def formatted_value(ref_or_row, col = nil)
444
950
  cell(ref_or_row, col)&.formatted_value
445
951
  end
@@ -449,20 +955,37 @@ module Xlsxrb
449
955
  # @example
450
956
  # new_sheet = sheet.update_cell("B1", value: "Updated")
451
957
  #
452
- # @param ref [String] The cell reference (e.g. "B1").
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.
453
960
  # @param value [Object] The new cell value.
454
- # @param style_index [Integer, String, nil] Optional new style index.
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.
455
963
  # @param formula [Elements::Formula, nil] Optional new formula.
456
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.
457
966
  # @param comment [Hash, String, nil] Optional new comment.
458
967
  # @return [Worksheet] A new Worksheet instance.
459
968
  # @api public
460
- #: (String ref, ?value: untyped, ?style_index: Integer | String | nil, ?formula: Elements::Formula?, ?hyperlink: (Hash[Symbol, untyped] | String)?, ?comment: (Hash[Symbol, untyped] | String)?) -> Elements::Worksheet
461
- def update_cell(ref, value: nil, style_index: nil, formula: nil, hyperlink: nil, comment: nil)
462
- parsed = Cell.parse_ref(ref)
463
- raise ArgumentError, "invalid cell reference: #{ref}" unless parsed
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
464
986
 
465
- row_idx, col_idx = parsed
987
+ row_idx, col_idx = parsed
988
+ end
466
989
  existing_row = row_at(row_idx)
467
990
 
468
991
  if existing_row
@@ -470,13 +993,14 @@ module Xlsxrb
470
993
  new_cell = if existing_cell
471
994
  existing_cell.with(
472
995
  value: value || existing_cell.value,
473
- style_index: style_index || existing_cell.style_index,
996
+ style: style || (style_index ? nil : existing_cell.style),
997
+ style_index: style_index || (style ? nil : existing_cell.style_index),
474
998
  formula: formula || existing_cell.formula,
475
999
  hyperlink: hyperlink || existing_cell.hyperlink,
476
1000
  comment: comment || existing_cell.comment
477
1001
  )
478
1002
  else
479
- 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)
480
1004
  end
481
1005
 
482
1006
  # Replace cell in the existing row
@@ -488,14 +1012,14 @@ module Xlsxrb
488
1012
  new_rows = rows.map { |r| r.index == row_idx ? new_row : r }
489
1013
  else
490
1014
  # Row doesn't exist, create it
491
- 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)
492
1016
  new_row = Row.new(index: row_idx, cells: [new_cell])
493
1017
  new_rows = (rows + [new_row]).sort_by!(&:index)
494
1018
  end
495
1019
  new_hyperlinks = hyperlink ? hyperlinks.merge(ref.upcase => hyperlink) : hyperlinks
496
1020
  new_comments = if comment
497
1021
  entry = comment.is_a?(Hash) ? comment.merge(ref: ref.upcase) : { ref: ref.upcase, text: comment }
498
- @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]
499
1023
  else
500
1024
  @comments
501
1025
  end
@@ -522,22 +1046,46 @@ module Xlsxrb
522
1046
  end
523
1047
  new_dv = changes.key?(:data_validations) ? changes[:data_validations] : data_validations
524
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
525
1061
  new_errors = changes.key?(:errors) ? changes[:errors] : errors
526
1062
  new_state = changes.key?(:state) ? changes[:state] : state
527
1063
  new_hyperlinks = changes.key?(:hyperlinks) ? changes[:hyperlinks] : hyperlinks
528
1064
  new_comments = changes.key?(:comments) ? changes[:comments] : comments
529
1065
  new_styles = changes.key?(:styles) ? changes[:styles] : styles
530
1066
  new_date1904 = changes.key?(:date1904) ? changes[:date1904] : date1904
531
- new_dim = changes.key?(:dimension) ? changes[:dimension] : @dimension
1067
+ new_dim = if changes.key?(:dimension)
1068
+ changes[:dimension]
1069
+ else
1070
+ (changes.key?(:rows) ? nil : @dimension)
1071
+ end
532
1072
  new_print_area = changes.key?(:print_area) ? changes[:print_area] : print_area
533
1073
  new_print_titles = changes.key?(:print_titles) ? changes[:print_titles] : print_titles
534
1074
  new_sparklines = changes.key?(:sparkline_groups) ? changes[:sparkline_groups] : sparkline_groups
535
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
536
1079
  new_merged = changes.key?(:merged_cells) ? changes[:merged_cells] : merged_cells
537
1080
  new_auto_filter = changes.key?(:auto_filter) ? changes[:auto_filter] : auto_filter
538
1081
  new_tables = changes.key?(:tables) ? changes[:tables] : tables
539
1082
  new_shapes = changes.key?(:shapes) ? changes[:shapes] : shapes
540
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
541
1089
  new_page_setup = changes.key?(:page_setup) ? changes[:page_setup] : page_setup
542
1090
  new_page_margins = changes.key?(:page_margins) ? changes[:page_margins] : page_margins
543
1091
  new_header_footer = changes.key?(:header_footer) ? changes[:header_footer] : header_footer
@@ -547,23 +1095,62 @@ module Xlsxrb
547
1095
  new_sheet_properties = changes.key?(:sheet_properties) ? changes[:sheet_properties] : sheet_properties
548
1096
  new_sheet_format = changes.key?(:sheet_format) ? changes[:sheet_format] : sheet_format
549
1097
  new_row_breaks = changes.key?(:row_breaks) ? changes[:row_breaks] : row_breaks
550
- new_col_breaks = changes.key?(:col_breaks) ? changes[:col_breaks] : col_breaks
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
551
1105
  new_protected_ranges = changes.key?(:protected_ranges) ? changes[:protected_ranges] : protected_ranges
552
1106
  new_cell_watches = changes.key?(:cell_watches) ? changes[:cell_watches] : cell_watches
1107
+ new_ignored_errors = changes.key?(:ignored_errors) ? changes[:ignored_errors] : ignored_errors
1108
+ new_phonetic_properties = if changes.key?(:phonetic_properties)
1109
+ changes[:phonetic_properties]
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
1112
+ changes[:phonetic_pr]
1113
+ else
1114
+ phonetic_properties
1115
+ end
553
1116
  new_selection = changes.key?(:selection) ? changes[:selection] : selection
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
1128
+ new_background_image = if changes.key?(:background_image)
1129
+ changes[:background_image]
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
1132
+ changes[:background_picture]
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
1135
+ changes[:picture]
1136
+ else
1137
+ background_image
1138
+ end
1139
+ new_threaded_comments = changes.key?(:threaded_comments) ? changes[:threaded_comments] : threaded_comments
554
1140
 
555
1141
  self.class.new(
556
1142
  name: new_name,
557
1143
  rows: new_rows,
558
1144
  columns: new_cols,
559
1145
  charts: new_charts,
560
- conditional_formatting: new_cf,
1146
+ conditional_formats: new_cf,
561
1147
  data_validations: new_dv,
562
1148
  unmapped_data: new_unmapped,
563
1149
  errors: new_errors,
564
1150
  state: new_state,
565
1151
  hyperlinks: new_hyperlinks,
566
1152
  comments: new_comments,
1153
+ images: new_images,
567
1154
  styles: new_styles,
568
1155
  date1904: new_date1904,
569
1156
  dimension: new_dim,
@@ -571,11 +1158,18 @@ module Xlsxrb
571
1158
  print_titles: new_print_titles,
572
1159
  sparkline_groups: new_sparklines,
573
1160
  trim_empty_rows: new_trim,
1161
+ pad_empty_rows: new_pad_rows,
1162
+ pad_empty_cells: new_pad_cells,
574
1163
  merged_cells: new_merged,
575
1164
  auto_filter: new_auto_filter,
576
1165
  tables: new_tables,
577
1166
  shapes: new_shapes,
578
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,
579
1173
  page_setup: new_page_setup,
580
1174
  page_margins: new_page_margins,
581
1175
  header_footer: new_header_footer,
@@ -585,10 +1179,15 @@ module Xlsxrb
585
1179
  sheet_properties: new_sheet_properties,
586
1180
  sheet_format: new_sheet_format,
587
1181
  row_breaks: new_row_breaks,
588
- col_breaks: new_col_breaks,
1182
+ column_breaks: new_col_breaks,
589
1183
  protected_ranges: new_protected_ranges,
590
1184
  cell_watches: new_cell_watches,
591
- selection: new_selection
1185
+ ignored_errors: new_ignored_errors,
1186
+ phonetic_properties: new_phonetic_properties,
1187
+ selection: new_selection,
1188
+ sheet_calc_properties: new_sheet_calc_pr,
1189
+ background_image: new_background_image,
1190
+ threaded_comments: new_threaded_comments
592
1191
  )
593
1192
  end
594
1193
 
@@ -608,18 +1207,27 @@ module Xlsxrb
608
1207
  state: state,
609
1208
  hyperlinks: hyperlinks,
610
1209
  comments: comments,
1210
+ threaded_comments: threaded_comments,
611
1211
  styles: styles,
612
- date1904: date1904,
1212
+ date1904: date1904?,
613
1213
  dimension: dimension,
614
1214
  print_area: print_area,
615
1215
  print_titles: print_titles,
616
1216
  sparkline_groups: sparkline_groups,
617
1217
  trim_empty_rows: @trim_empty_rows,
1218
+ pad_empty_rows: @pad_empty_rows,
1219
+ pad_empty_cells: @pad_empty_cells,
618
1220
  merged_cells: merged_cells,
619
1221
  auto_filter: auto_filter,
620
1222
  tables: tables,
621
1223
  shapes: shapes,
622
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,
623
1231
  page_setup: page_setup,
624
1232
  page_margins: page_margins,
625
1233
  header_footer: header_footer,
@@ -629,8 +1237,21 @@ module Xlsxrb
629
1237
  sheet_properties: sheet_properties,
630
1238
  sheet_format: sheet_format,
631
1239
  row_breaks: row_breaks,
1240
+ column_breaks: column_breaks,
632
1241
  col_breaks: col_breaks,
633
- selection: selection
1242
+ protected_ranges: protected_ranges,
1243
+ cell_watches: cell_watches,
1244
+ ignored_errors: ignored_errors,
1245
+ phonetic_properties: phonetic_properties,
1246
+ phonetic_pr: phonetic_properties,
1247
+ selection: selection,
1248
+ sheet_calc_properties: sheet_calc_properties,
1249
+ sheet_calc_pr: @sheet_calc_pr,
1250
+ calc_pr: @sheet_calc_pr,
1251
+ code_name: code_name,
1252
+ background_image: background_image,
1253
+ background_picture: background_image,
1254
+ picture: background_image
634
1255
  }
635
1256
  end
636
1257
 
@@ -642,14 +1263,18 @@ module Xlsxrb
642
1263
  name == other.name && rows == other.rows && columns == other.columns && charts == other.charts &&
643
1264
  conditional_formatting == other.conditional_formatting && data_validations == other.data_validations &&
644
1265
  state == other.state && hyperlinks == other.hyperlinks && comments == other.comments &&
1266
+ threaded_comments == other.threaded_comments &&
645
1267
  merged_cells == other.merged_cells && auto_filter == other.auto_filter &&
646
1268
  tables == other.tables && shapes == other.shapes && freeze_pane == other.freeze_pane &&
647
1269
  page_setup == other.page_setup && page_margins == other.page_margins &&
648
1270
  header_footer == other.header_footer && print_options == other.print_options &&
649
1271
  sheet_protection == other.sheet_protection && sheet_view == other.sheet_view &&
650
1272
  sheet_properties == other.sheet_properties && sheet_format == other.sheet_format &&
651
- row_breaks == other.row_breaks && col_breaks == other.col_breaks &&
652
- selection == other.selection
1273
+ row_breaks == other.row_breaks && column_breaks == other.column_breaks &&
1274
+ protected_ranges == other.protected_ranges && cell_watches == other.cell_watches &&
1275
+ ignored_errors == other.ignored_errors && phonetic_properties == other.phonetic_properties &&
1276
+ selection == other.selection && sheet_calc_properties == other.sheet_calc_properties &&
1277
+ background_image == other.background_image
653
1278
  end
654
1279
  alias eql? ==
655
1280
 
@@ -657,9 +1282,10 @@ module Xlsxrb
657
1282
  def hash
658
1283
  [
659
1284
  self.class, name, rows, columns, charts, conditional_formatting, data_validations,
660
- state, hyperlinks, comments, merged_cells, auto_filter, tables, shapes, freeze_pane,
1285
+ state, hyperlinks, comments, threaded_comments, merged_cells, auto_filter, tables, shapes, freeze_pane,
661
1286
  page_setup, page_margins, header_footer, print_options, sheet_protection, sheet_view,
662
- sheet_properties, sheet_format, row_breaks, col_breaks, selection
1287
+ sheet_properties, sheet_format, row_breaks, col_breaks, protected_ranges,
1288
+ cell_watches, ignored_errors, phonetic_properties, selection, sheet_calc_properties, background_image
663
1289
  ].hash
664
1290
  end
665
1291
 
@@ -669,11 +1295,25 @@ module Xlsxrb
669
1295
  # @api public
670
1296
  #: () -> Elements::Worksheet
671
1297
  def load
1298
+ Deprecation.warn("Elements::Worksheet#load is deprecated; worksheet is already loaded in memory.")
672
1299
  self
673
1300
  end
674
- alias to_worksheet load
675
1301
 
676
- FORBIDDEN_NAME_CHARS = %r{[\\/?*\[\]]}
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
1308
+
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
677
1317
 
678
1318
  # Returns whether the worksheet name is valid according to OOXML specifications (1..31 chars, no forbidden chars).
679
1319
  #
@@ -683,7 +1323,7 @@ module Xlsxrb
683
1323
  def self.valid_name?(name)
684
1324
  case name
685
1325
  when String
686
- !name.empty? && name.size <= 31 && !name.match?(FORBIDDEN_NAME_CHARS)
1326
+ !name.empty? && name.size <= 31 && !name.match?(FORBIDDEN_NAME_CHARS) && !name.start_with?("'") && !name.end_with?("'") && !name.casecmp?("History")
687
1327
  else
688
1328
  false
689
1329
  end
@@ -694,6 +1334,7 @@ module Xlsxrb
694
1334
  # @param name [String]
695
1335
  # @param rows [Array<Elements::Row>]
696
1336
  # @return [Array<String>] List of errors.
1337
+ # @api private
697
1338
  #: (untyped name, untyped rows) -> Array[String]
698
1339
  def self.validate(name, rows)
699
1340
  errs = []
@@ -701,7 +1342,9 @@ module Xlsxrb
701
1342
  errs << "worksheet name must be a non-empty String (got #{name.inspect})"
702
1343
  else
703
1344
  errs << "worksheet name cannot exceed 31 characters (got #{name.size})" if name.size > 31
704
- errs << "worksheet name cannot contain \\, /, ?, *, [, or ]" if name.match?(FORBIDDEN_NAME_CHARS)
1345
+ errs << "worksheet name cannot contain \\, /, ?, *, [, ], or :" if name.match?(FORBIDDEN_NAME_CHARS)
1346
+ errs << "worksheet name cannot start or end with an apostrophe" if name.start_with?("'") || name.end_with?("'")
1347
+ errs << "worksheet name 'History' is reserved by Excel" if name.casecmp?("History")
705
1348
  end
706
1349
  errs << "rows must be an Array (got #{rows.class})" unless rows.is_a?(Array)
707
1350
  if rows.is_a?(Array)
@@ -738,8 +1381,8 @@ module Xlsxrb
738
1381
 
739
1382
  return nil if min_r.nil? || min_c.nil?
740
1383
 
741
- start_cell = "#{Elements::Cell.column_letter(min_c)}#{min_r + 1}"
742
- end_cell = "#{Elements::Cell.column_letter(max_c)}#{max_r + 1}"
1384
+ start_cell = "#{Elements::Cell._column_letter(min_c)}#{min_r + 1}"
1385
+ end_cell = "#{Elements::Cell._column_letter(max_c)}#{max_r + 1}"
743
1386
  start_cell == end_cell ? start_cell : "#{start_cell}:#{end_cell}"
744
1387
  end
745
1388
  end