xlsxrb 0.1.14 → 0.1.16

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +108 -0
  3. data/README.md +37 -17
  4. data/benchmark/micro_ips.rb +70 -0
  5. data/lib/xlsxrb/elements/styles.rb +427 -15
  6. data/lib/xlsxrb/elements/workbook.rb +67 -4
  7. data/lib/xlsxrb/elements/worksheet.rb +117 -7
  8. data/lib/xlsxrb/ooxml/cfb.rb +10 -0
  9. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +56 -38
  10. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +14 -2
  11. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +12 -7
  12. data/lib/xlsxrb/ooxml/reader.rb +167 -139
  13. data/lib/xlsxrb/ooxml/shared_strings_parser.rb +83 -28
  14. data/lib/xlsxrb/ooxml/styles_parser.rb +57 -14
  15. data/lib/xlsxrb/ooxml/utils.rb +59 -2
  16. data/lib/xlsxrb/ooxml/workbook_parser.rb +63 -4
  17. data/lib/xlsxrb/ooxml/workbook_writer.rb +232 -59
  18. data/lib/xlsxrb/ooxml/worksheet_parser.rb +192 -123
  19. data/lib/xlsxrb/ooxml/worksheet_writer.rb +307 -125
  20. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +16 -12
  21. data/lib/xlsxrb/ooxml/writer/features_xml.rb +1 -1
  22. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +64 -15
  23. data/lib/xlsxrb/ooxml/writer.rb +31 -28
  24. data/lib/xlsxrb/ooxml/xml_builder.rb +22 -2
  25. data/lib/xlsxrb/ooxml/xml_parser.rb +45 -0
  26. data/lib/xlsxrb/ooxml/zip_reader.rb +83 -32
  27. data/lib/xlsxrb/stream_row.rb +4 -3
  28. data/lib/xlsxrb/stream_sheet.rb +259 -7
  29. data/lib/xlsxrb/stream_writer.rb +197 -31
  30. data/lib/xlsxrb/utils.rb +68 -0
  31. data/lib/xlsxrb/version.rb +1 -1
  32. data/lib/xlsxrb/workbook_builder.rb +110 -19
  33. data/lib/xlsxrb/worksheet_builder.rb +526 -15
  34. data/lib/xlsxrb.rb +889 -90
  35. data/sig/generated/xlsxrb/elements/styles.rbs +271 -5
  36. data/sig/generated/xlsxrb/elements/workbook.rbs +54 -3
  37. data/sig/generated/xlsxrb/elements/worksheet.rbs +63 -2
  38. data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +2 -0
  39. data/sig/generated/xlsxrb/ooxml/reader.rbs +12 -0
  40. data/sig/generated/xlsxrb/ooxml/shared_strings_parser.rbs +3 -1
  41. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +2 -0
  42. data/sig/generated/xlsxrb/ooxml/utils.rbs +22 -0
  43. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +7 -0
  44. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +13 -1
  45. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +18 -2
  46. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +13 -3
  47. data/sig/generated/xlsxrb/ooxml/writer/styles_xml.rbs +5 -2
  48. data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +6 -1
  49. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +9 -6
  50. data/sig/generated/xlsxrb/stream_row.rbs +3 -2
  51. data/sig/generated/xlsxrb/stream_sheet.rbs +132 -6
  52. data/sig/generated/xlsxrb/stream_writer.rbs +118 -27
  53. data/sig/generated/xlsxrb/utils.rbs +45 -0
  54. data/sig/generated/xlsxrb/worksheet_builder.rbs +252 -9
  55. data/sig/generated/xlsxrb.rbs +84 -10
  56. metadata +2 -1
@@ -10,6 +10,8 @@ module Xlsxrb
10
10
 
11
11
  EMPTY_HASH: untyped
12
12
 
13
+ EMPTY_BINARY: untyped
14
+
13
15
  TAG_DELIM_BYTES: untyped
14
16
 
15
17
  ROW_ATTR_START_BYTES: untyped
@@ -47,8 +49,22 @@ module Xlsxrb
47
49
 
48
50
  def self.extract_inline_text: (untyped xml, untyped from, untyped to) -> untyped
49
51
 
52
+ STRICT_NUMERIC_RE: ::Regexp
53
+
54
+ # Resolves a cell value from its type attribute and parsed XML content (<v> or <is>).
55
+ # Consolidates parsing across fast-scan direct, row values, events, and listener paths.
56
+ # : (String? type, String? raw_value, String? is_xml, Array[String | Elements::RichText | untyped] shared_strings) -> untyped
57
+ def self.resolve_cell_value: (String? type, String? raw_value, String? is_xml, Array[String | Elements::RichText | untyped] shared_strings) -> untyped
58
+
50
59
  def self.resolve_fast_value: (untyped raw, untyped type, untyped shared_strings) -> untyped
51
60
 
61
+ # Converts the text of a numeric cell (<c t="n">) into an Integer or Float.
62
+ # An empty <v></v> carries no value and yields nil. Text that is not an xsd:double
63
+ # (e.g. "abc") cannot come from a conforming producer and raises ParseError
64
+ # instead of silently becoming 0.
65
+ # : (String raw) -> (Integer | Float)?
66
+ def self.numeric_cell_value: (String raw) -> (Integer | Float)?
67
+
52
68
  # SECURITY NOTE: Decodes only standard predefined XML entities in a single pass.
53
69
  # This completely prevents "Billion Laughs" attacks (exponential entity expansion)
54
70
  # because it avoids recursive expansion and ignores custom entities entirely.
@@ -99,8 +115,8 @@ module Xlsxrb
99
115
  def self.fast_scan_cells_direct: (untyped xml, untyped from, untyped to, untyped shared_strings, untyped row_source, ?untyped _prefix, ?untyped styles, ?untyped date1904) ?{ (?) -> untyped } -> untyped
100
116
 
101
117
  # rubocop:disable Style/OptionalBooleanParameter
102
- # : (String xml, Integer from, Integer to, Array[String] shared_strings, ?untyped styles, ?bool date1904, ?type_cast: bool) -> Array[untyped]
103
- def self.fast_scan_row_values: (String xml, Integer from, Integer to, Array[String] shared_strings, ?untyped styles, ?bool date1904, ?type_cast: bool) -> Array[untyped]
118
+ # : (String xml, Integer from, Integer to, Array[String | Elements::RichText | untyped] shared_strings, ?untyped styles, ?bool date1904, ?type_cast: bool) -> Array[untyped]
119
+ def self.fast_scan_row_values: (String xml, Integer from, Integer to, Array[String | Elements::RichText | untyped] shared_strings, ?untyped styles, ?bool date1904, ?type_cast: bool) -> Array[untyped]
104
120
  end
105
121
  end
106
122
  end
@@ -13,7 +13,9 @@ module Xlsxrb
13
13
 
14
14
  INTEGER_STRINGS: untyped
15
15
 
16
- def initialize: (untyped io, ?date1904: untyped) -> untyped
16
+ attr_accessor escape_formulas: untyped
17
+
18
+ def initialize: (untyped io, ?date1904: untyped, ?escape_formulas: untyped) -> untyped
17
19
 
18
20
  def set_column_style: (untyped col_index, untyped style_id) -> untyped
19
21
 
@@ -24,7 +26,7 @@ module Xlsxrb
24
26
  # split_pane: { x_split:, y_split:, top_left_cell: }
25
27
  # selection: { active_cell:, sqref:, pane: }
26
28
  # sheet_view: Hash of sheet view properties
27
- def start: (?columns: untyped, ?sheet_properties: untyped, ?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped) -> untyped
29
+ def start: (?columns: untyped, ?sheet_properties: untyped, ?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped, ?sheet_format: untyped) -> untyped
28
30
 
29
31
  # Write a single row. Automatically calls start if needed.
30
32
  def write_row: (untyped row_index, untyped cells, ?attrs: untyped, ?unmapped: untyped, ?sst_index: untyped) -> untyped
@@ -34,16 +36,22 @@ module Xlsxrb
34
36
 
35
37
  # Write the worksheet footer. Call once after all rows.
36
38
  # Options for post-sheetData elements (in OOXML order):
37
- def finish: (?drawing_rid: untyped, ?sheet_protection: untyped, ?auto_filter: untyped, ?filter_columns: untyped, ?sort_state: untyped, ?merge_cells: untyped, ?conditional_formats: untyped, ?data_validations: untyped, ?hyperlinks: untyped, ?print_options: untyped, ?page_margins: untyped, ?page_setup: untyped, ?header_footer: untyped, ?row_breaks: untyped, ?col_breaks: untyped, ?tables: untyped, ?table_start_rid: untyped, ?legacy_drawing_rid: untyped, ?sparkline_groups: untyped) -> untyped
39
+ def finish: (?drawing_rid: untyped, ?sheet_protection: untyped, ?protected_ranges: untyped, ?auto_filter: untyped, ?filter_columns: untyped, ?sort_state: untyped, ?merge_cells: untyped, ?conditional_formats: untyped, ?data_validations: untyped, ?hyperlinks: untyped, ?print_options: untyped, ?page_margins: untyped, ?page_setup: untyped, ?header_footer: untyped, ?row_breaks: untyped, ?col_breaks: untyped, ?cell_watches: untyped, ?tables: untyped, ?table_start_rid: untyped, ?legacy_drawing_rid: untyped, ?sparkline_groups: untyped) -> untyped
38
40
 
39
41
  private
40
42
 
43
+ def resolve_style_id: (untyped style, untyped style_map) -> untyped
44
+
41
45
  def write_sheet_properties: (untyped props) -> untyped
42
46
 
43
47
  def write_sheet_views: (?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped) -> untyped
44
48
 
49
+ def write_sheet_format_pr: (untyped fmt) -> untyped
50
+
45
51
  def write_sheet_protection: (untyped opts) -> untyped
46
52
 
53
+ def write_protected_ranges: (untyped ranges) -> untyped
54
+
47
55
  def write_auto_filter: (untyped range, untyped filter_columns, untyped sort_state) -> untyped
48
56
 
49
57
  def write_filter_column: (untyped col_id, untyped filter) -> untyped
@@ -68,6 +76,8 @@ module Xlsxrb
68
76
 
69
77
  def write_col_breaks: (untyped breaks) -> untyped
70
78
 
79
+ def write_cell_watches: (untyped watches) -> untyped
80
+
71
81
  def write_table_parts: (untyped tables, untyped start_rid) -> untyped
72
82
 
73
83
  def write_sparklines: (untyped groups) -> untyped
@@ -14,7 +14,10 @@ module Xlsxrb
14
14
  # : (untyped protection) -> ::String
15
15
  def emit_protection_xml: (untyped protection) -> untyped
16
16
 
17
- # : (untyped source, ?tag: ::String) -> (::String | ::String | ::String | ::String | "")
17
+ # : (untyped rgb) -> ::String?
18
+ def format_rgb_hex: (untyped rgb) -> untyped
19
+
20
+ # : (untyped source, ?tag: ::String) -> ::String
18
21
  def emit_color_xml: (untyped source, ?tag: untyped) -> untyped
19
22
 
20
23
  # : (untyped font) -> untyped
@@ -23,7 +26,7 @@ module Xlsxrb
23
26
  # : (untyped fill) -> (untyped | ::String)
24
27
  def emit_fill_xml: (untyped fill) -> untyped
25
28
 
26
- # : (untyped tag, untyped fill, untyped prefix) -> (::String | ::String | ::String | ::String | "")
29
+ # : (untyped tag, untyped fill, untyped prefix) -> ::String
27
30
  def emit_fill_color_xml: (untyped tag, untyped fill, untyped prefix) -> untyped
28
31
 
29
32
  # : (untyped gradient) -> untyped
@@ -46,7 +46,12 @@ module Xlsxrb
46
46
  # : (untyped value) -> String
47
47
  def self.escape: (untyped value) -> String
48
48
 
49
- # Unescapes predefined XML entities in a string in a single pass.
49
+ NUM_ENTITY_RE: ::Regexp
50
+
51
+ XSTRING_RE: ::Regexp
52
+
53
+ # Unescapes predefined and numeric/hex XML entities, as well as
54
+ # ISO/IEC 29500-1 ST_Xstring (_xHHHH_) control character sequences.
50
55
  #
51
56
  # @param value [Object]
52
57
  # @return [String]
@@ -41,8 +41,8 @@ module Xlsxrb
41
41
 
42
42
  attr_reader compression_method: untyped
43
43
 
44
- # : (untyped io, Integer data_offset, Integer compressed_size, Integer compression_method, ?max_uncompressed_size: Integer?) -> void
45
- def initialize: (untyped io, Integer data_offset, Integer compressed_size, Integer compression_method, ?max_uncompressed_size: Integer?) -> void
44
+ # : (untyped io, Integer data_offset, Integer compressed_size, Integer compression_method, ?max_uncompressed_size: Integer?, ?encoding: Encoding?) -> void
45
+ def initialize: (untyped io, Integer data_offset, Integer compressed_size, Integer compression_method, ?max_uncompressed_size: Integer?, ?encoding: Encoding?) -> void
46
46
 
47
47
  # : (?Integer? length) -> String?
48
48
  def read: (?Integer? length) -> String?
@@ -86,12 +86,12 @@ module Xlsxrb
86
86
  def each_entry: () ?{ (?) -> untyped } -> untyped
87
87
 
88
88
  # Opens an EntryStreamIO for an entry by name.
89
- # : (String entry_name) -> EntryStreamIO
90
- def open_entry_io: (String entry_name) -> EntryStreamIO
89
+ # : (String entry_name, ?encoding: (Encoding | String | false | nil)) -> EntryStreamIO
90
+ def open_entry_io: (String entry_name, ?encoding: Encoding | String | false | nil) -> EntryStreamIO
91
91
 
92
92
  # Yields inflated binary chunks directly from the compressed stream.
93
- # : (String entry_name, ?chunk_size: Integer) ?{ (String) -> void } -> (void | Enumerator[String, void])
94
- def each_entry_chunk: (untyped entry_name, ?chunk_size: untyped) ?{ (?) -> untyped } -> untyped
93
+ # : (String entry_name, ?chunk_size: Integer, ?encoding: (Encoding | String | false | nil)) ?{ (String) -> void } -> (void | Enumerator[String, void])
94
+ def each_entry_chunk: (untyped entry_name, ?chunk_size: untyped, ?encoding: untyped) ?{ (?) -> untyped } -> untyped
95
95
 
96
96
  # Returns true if the archive contains the specified entry.
97
97
  # : (String name) -> bool
@@ -138,6 +138,9 @@ module Xlsxrb
138
138
  def ci_catalog: () -> untyped
139
139
 
140
140
  def normalize_text_encoding: (untyped data) -> untyped
141
+
142
+ # : (String extra_data, Integer usize, Integer csize, Integer offset) -> [Integer, Integer, Integer]
143
+ def parse_zip64_extra: (String extra_data, Integer usize, Integer csize, Integer offset) -> [ Integer, Integer, Integer ]
141
144
  end
142
145
  end
143
146
  end
@@ -43,10 +43,11 @@ module Xlsxrb
43
43
  # @param collapsed [Boolean] Whether the row is collapsed.
44
44
  # @param outline_level [Integer, nil] Grouping/outline level.
45
45
  # @param style_index [Integer, nil] Style index.
46
+ # @param styles [Elements::Styles, Hash, nil] Optional parsed styles.
46
47
  # @param date1904 [Boolean] Whether the 1904 date system is active.
47
48
  # @param pad_empty_cells [Boolean] Whether missing cells in this row are padded.
48
- # : (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style_index: Integer | nil, ?styles: Hash[untyped, untyped]?, ?date1904: bool, ?pad_empty_cells: bool) -> void
49
- def initialize: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style_index: Integer | nil, ?styles: Hash[untyped, untyped]?, ?date1904: bool, ?pad_empty_cells: bool) -> void
49
+ # : (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style_index: Integer | nil, ?styles: (Elements::Styles | Hash[untyped, untyped])?, ?date1904: bool, ?pad_empty_cells: bool) -> void
50
+ def initialize: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style_index: Integer | nil, ?styles: (Elements::Styles | Hash[untyped, untyped])?, ?date1904: bool, ?pad_empty_cells: bool) -> void
50
51
 
51
52
  # rubocop:disable Style/OptionalBooleanParameter
52
53
  def self.fast_create: (untyped index, untyped xml_bytes, untyped from, untyped to, untyped shared_strings, ?untyped prefix, ?untyped height, ?untyped hidden, ?untyped custom_height, ?untyped outline_level, ?untyped style_index, ?untyped styles, ?untyped date1904, ?untyped collapsed, ?untyped pad_empty_cells) -> untyped
@@ -34,9 +34,9 @@ module Xlsxrb
34
34
  # : Symbol
35
35
  attr_reader state: untyped
36
36
 
37
- # @return [Hash, nil] The parsed styles definition hash.
37
+ # @return [Elements::Styles, Hash, nil] The parsed styles definition.
38
38
  # @api public
39
- # : Hash[untyped, untyped]?
39
+ # : (Elements::Styles | Hash[untyped, untyped])?
40
40
  attr_reader styles: untyped
41
41
 
42
42
  # Initializes a streaming worksheet context.
@@ -44,7 +44,7 @@ module Xlsxrb
44
44
  # @param name [String] The sheet name.
45
45
  # @param sheet_source [String, Proc, IO, nil] Raw XML content or chunk supplier/stream.
46
46
  # @param shared_strings [Array<String>] Shared strings table.
47
- # @param styles [Hash, nil] Optional parsed styles hash.
47
+ # @param styles [Elements::Styles, Hash, nil] Optional parsed styles.
48
48
  # @param zip_reader [Ooxml::ZipReader, nil] Optional ZipReader context.
49
49
  # @param entry_name [String, nil] Archive entry name for this sheet.
50
50
  # @param date1904 [Boolean] Whether the 1904 date system is active.
@@ -53,8 +53,8 @@ module Xlsxrb
53
53
  # @param pad_empty_rows [Boolean] Whether to yield empty rows for skipped row numbers.
54
54
  # @param pad_empty_cells [Boolean] Whether to pad missing cells within rows.
55
55
  # @param images [Array<Elements::Image>, nil] Optional preloaded images array.
56
- # : (String name, untyped sheet_source, Array[String] shared_strings, ?Hash[untyped, untyped]? styles, ?zip_reader: Ooxml::ZipReader?, ?entry_name: String?, ?state: Symbol, ?date1904: bool, ?dimension: String?, ?trim_empty_rows: bool, ?pad_empty_rows: bool, ?pad_empty_cells: bool, ?images: Array[Elements::Image]?) -> void
57
- def initialize: (String name, untyped sheet_source, Array[String] shared_strings, ?Hash[untyped, untyped]? styles, ?zip_reader: Ooxml::ZipReader?, ?entry_name: String?, ?state: Symbol, ?date1904: bool, ?dimension: String?, ?trim_empty_rows: bool, ?pad_empty_rows: bool, ?pad_empty_cells: bool, ?images: Array[Elements::Image]?) -> void
56
+ # : (String name, untyped sheet_source, Array[String] shared_strings, ?(Elements::Styles | Hash[untyped, untyped])? styles, ?zip_reader: Ooxml::ZipReader?, ?entry_name: String?, ?state: Symbol, ?date1904: bool, ?dimension: String?, ?trim_empty_rows: bool, ?pad_empty_rows: bool, ?pad_empty_cells: bool, ?images: Array[Elements::Image]?) -> void
57
+ def initialize: (String name, untyped sheet_source, Array[String] shared_strings, ?(Elements::Styles | Hash[untyped, untyped])? styles, ?zip_reader: Ooxml::ZipReader?, ?entry_name: String?, ?state: Symbol, ?date1904: bool, ?dimension: String?, ?trim_empty_rows: bool, ?pad_empty_rows: bool, ?pad_empty_cells: bool, ?images: Array[Elements::Image]?) -> void
58
58
 
59
59
  # Returns whether trailing empty rows are omitted during iteration.
60
60
  #
@@ -143,6 +143,13 @@ module Xlsxrb
143
143
  # : () -> bool
144
144
  def visible?: () -> bool
145
145
 
146
+ # Returns whether the sheet is very hidden (:very_hidden).
147
+ #
148
+ # @return [Boolean]
149
+ # @api public
150
+ # : () -> bool
151
+ def very_hidden?: () -> bool
152
+
146
153
  # Iterates over rows in this streaming worksheet with O(1) memory.
147
154
  #
148
155
  # @overload each_row(&block)
@@ -353,13 +360,132 @@ module Xlsxrb
353
360
  # : () -> Array[Hash[Symbol, untyped]]
354
361
  def conditional_formats: () -> Array[Hash[Symbol, untyped]]
355
362
 
363
+ alias conditional_formatting conditional_formats
364
+
365
+ # Returns tables defined in this worksheet.
366
+ #
367
+ # @return [Array<Hash[Symbol, untyped]>]
368
+ # @api public
369
+ # : () -> Array[Hash[Symbol, untyped]]
370
+ def tables: () -> Array[Hash[Symbol, untyped]]
371
+
372
+ # Returns shapes defined in this worksheet.
373
+ #
374
+ # @return [Array<Hash[Symbol, untyped]>]
375
+ # @api public
376
+ # : () -> Array[Hash[Symbol, untyped]]
377
+ def shapes: () -> Array[Hash[Symbol, untyped]]
378
+
379
+ # Returns freeze pane settings for this worksheet, or nil if none.
380
+ #
381
+ # @return [Hash[Symbol, untyped], nil]
382
+ # @api public
383
+ # : () -> Hash[Symbol, untyped]?
384
+ def freeze_pane: () -> Hash[Symbol, untyped]?
385
+
386
+ # Returns sheet view properties for this worksheet.
387
+ #
388
+ # @return [Hash[Symbol, untyped]]
389
+ # @api public
390
+ # : () -> Hash[Symbol, untyped]
391
+ def sheet_view: () -> Hash[Symbol, untyped]
392
+
393
+ # Returns selection settings for this worksheet, or nil if none.
394
+ #
395
+ # @return [Hash[Symbol, untyped], nil]
396
+ # @api public
397
+ # : () -> Hash[Symbol, untyped]?
398
+ def selection: () -> Hash[Symbol, untyped]?
399
+
400
+ # Returns sheet protection settings as a hash, or nil if unprotected.
401
+ #
402
+ # @return [Hash[Symbol, untyped], nil]
403
+ # @api public
404
+ # : () -> Hash[Symbol, untyped]?
405
+ def sheet_protection: () -> Hash[Symbol, untyped]?
406
+
407
+ # Returns sheet-level properties (tabColor, outlinePr) for this worksheet.
408
+ #
409
+ # @return [Hash[Symbol, untyped]]
410
+ # @api public
411
+ # : () -> Hash[Symbol, untyped]
412
+ def sheet_properties: () -> Hash[Symbol, untyped]
413
+
414
+ # Returns sheet format properties (defaultRowHeight, defaultColWidth, baseColWidth) for this worksheet.
415
+ #
416
+ # @return [Hash[Symbol, untyped]]
417
+ # @api public
418
+ # : () -> Hash[Symbol, untyped]
419
+ def sheet_format: () -> Hash[Symbol, untyped]
420
+
421
+ # Returns page setup configurations for this worksheet.
422
+ #
423
+ # @return [Hash[Symbol, untyped]]
424
+ # @api public
425
+ # : () -> Hash[Symbol, untyped]
426
+ def page_setup: () -> Hash[Symbol, untyped]
427
+
428
+ # Returns page margins for this worksheet, or nil if none.
429
+ #
430
+ # @return [Hash[Symbol, untyped], nil]
431
+ # @api public
432
+ # : () -> Hash[Symbol, untyped]?
433
+ def page_margins: () -> Hash[Symbol, untyped]?
434
+
435
+ # Returns header/footer configurations for this worksheet.
436
+ #
437
+ # @return [Hash[Symbol, untyped]]
438
+ # @api public
439
+ # : () -> Hash[Symbol, untyped]
440
+ def header_footer: () -> Hash[Symbol, untyped]
441
+
442
+ # Returns print options for this worksheet.
443
+ #
444
+ # @return [Hash[Symbol, untyped]]
445
+ # @api public
446
+ # : () -> Hash[Symbol, untyped]
447
+ def print_options: () -> Hash[Symbol, untyped]
448
+
449
+ # Returns explicit row page breaks for this worksheet.
450
+ #
451
+ # @return [Array<untyped>]
452
+ # @api public
453
+ # : () -> Array[untyped]
454
+ def row_breaks: () -> Array[untyped]
455
+
456
+ # Returns explicit column page breaks for this worksheet.
457
+ #
458
+ # @return [Array<untyped>]
459
+ # @api public
460
+ # : () -> Array[untyped]
461
+ def col_breaks: () -> Array[untyped]
462
+
463
+ # Returns protected ranges defined for this worksheet.
464
+ #
465
+ # @return [Array<Hash[Symbol, untyped]>]
466
+ # @api public
467
+ # : () -> Array[Hash[Symbol, untyped]]
468
+ def protected_ranges: () -> Array[Hash[Symbol, untyped]]
469
+
470
+ # Returns cell watch cell references defined for this worksheet.
471
+ #
472
+ # @return [Array<String>]
473
+ # @api public
474
+ # : () -> Array[String]
475
+ def cell_watches: () -> Array[String]
476
+
356
477
  # Closes any underlying reader resources.
357
478
  # : () -> void
358
479
  def close: () -> void
359
480
 
360
481
  private
361
482
 
362
- # Returns the full raw XML string for this worksheet, loaded on demand.
483
+ # : () -> Hash[Symbol, untyped]
484
+ def sheet_view_data: () -> Hash[Symbol, untyped]
485
+
486
+ # : () -> Hash[Symbol, untyped]
487
+ def print_page_data: () -> Hash[Symbol, untyped]
488
+
363
489
  # : () -> String
364
490
  def raw_sheet_xml: () -> String
365
491
 
@@ -17,12 +17,16 @@ module Xlsxrb
17
17
  # : String?
18
18
  attr_reader current_sheet: untyped
19
19
 
20
+ # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
21
+ attr_accessor escape_formulas: untyped
22
+
20
23
  # Initializes a streaming writer context.
21
24
  #
22
25
  # @param target [String, IO, StringIO] Destination file path or writable IO stream.
23
26
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
24
- # : (untyped target, ?strict_excel_mode: bool) -> void
25
- def initialize: (untyped target, ?strict_excel_mode: bool) -> void
27
+ # @param escape_formulas [Boolean] Whether to treat strings starting with formula prefixes as plain text.
28
+ # : (untyped target, ?strict_excel_mode: bool, ?escape_formulas: bool) -> void
29
+ def initialize: (untyped target, ?strict_excel_mode: bool, ?escape_formulas: bool) -> void
26
30
 
27
31
  # Sets a workbook property.
28
32
  #
@@ -124,10 +128,11 @@ module Xlsxrb
124
128
  # @param custom_height [Boolean] Whether to flag as custom height.
125
129
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
126
130
  # @param collapsed [Boolean] Whether the row is collapsed.
131
+ # @param style [Integer, Symbol, String, Hash, nil] Row style format or index.
127
132
  # @return [void]
128
133
  # @api public
129
- # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
130
- def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
134
+ # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: untyped) -> void
135
+ def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: untyped) -> void
131
136
 
132
137
  alias add_row row
133
138
 
@@ -154,10 +159,11 @@ module Xlsxrb
154
159
  # @param custom_width [Boolean] Whether to flag as custom width.
155
160
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
156
161
  # @param collapsed [Boolean] Whether the outline group is collapsed.
162
+ # @param style [Integer, Symbol, String, Hash, nil] Column style format or index.
157
163
  # @return [void]
158
164
  # @api public
159
- # : (Integer | String | Symbol | Range[Integer | String] | Array[Integer | String] col_index, ?width: Float | Integer | nil, ?hidden: bool, ?best_fit: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool) -> void
160
- def column: (Integer | String | Symbol | Range[Integer | String] | Array[Integer | String] col_index, ?width: Float | Integer | nil, ?hidden: bool, ?best_fit: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool) -> void
165
+ # : (Integer | String | Symbol | Range[Integer | String] | Array[Integer | String] col_index, ?width: Float | Integer | nil, ?hidden: bool, ?best_fit: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
166
+ def column: (Integer | String | Symbol | Range[Integer | String] | Array[Integer | String] col_index, ?width: Float | Integer | nil, ?hidden: bool, ?best_fit: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
161
167
 
162
168
  # Adds a chart to the active sheet.
163
169
  #
@@ -232,16 +238,25 @@ module Xlsxrb
232
238
 
233
239
  # Adds data validation rules to a range.
234
240
  #
241
+ # Adds data validation to a cell or range.
242
+ #
235
243
  # @example Dropdown list validation
236
244
  # s.validate_data("B2:B100", type: "list", formula1: '"High,Medium,Low"')
237
245
  #
238
- # @param range [String] The cell range (e.g. "B2:B10").
239
- # @param type [String, Symbol] Validation type ("list", "whole", "decimal", "date", "time", "textLength", "custom").
246
+ # @example Block syntax
247
+ # s.validate_data("B2:B100") do |dv|
248
+ # dv.type :list
249
+ # dv.formula1 '"High,Medium,Low"'
250
+ # end
251
+ #
252
+ # @param range [String, nil] The cell range (e.g. "B2:B10").
253
+ # @param type [String, Symbol, nil] Validation type ("list", "whole", "decimal", "date", "time", "textLength", "custom").
240
254
  # @param opts [Hash] Validation options.
255
+ # @yield [data_validation_builder] Optional configuration block.
241
256
  # @return [void]
242
257
  # @api public
243
- # : (String range, ?type: String | Symbol, **untyped opts) -> void
244
- def validate_data: (String range, ?type: String | Symbol, **untyped opts) -> void
258
+ # : (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
259
+ def validate_data: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
245
260
 
246
261
  # Adds conditional formatting to a range.
247
262
  #
@@ -258,19 +273,26 @@ module Xlsxrb
258
273
 
259
274
  # Adds a formatted Excel Table to the sheet.
260
275
  #
261
- # @example
276
+ # @example Standard keyword arguments
262
277
  # s.table("A1:C10", columns: ["ID", "Name", "Total"], name: "SalesTable", style: "TableStyleMedium9")
263
278
  #
264
- # @param ref [String] The cell range for the table (e.g. "A1:D10").
265
- # @param columns [Array<String>, Array<Hash>] Column names or definitions.
279
+ # @example Block syntax
280
+ # s.table("A1:C10") do |t|
281
+ # t.columns ["ID", "Name", "Total"]
282
+ # t.style "TableStyleMedium9"
283
+ # end
284
+ #
285
+ # @param ref [String, nil] The cell range for the table (e.g. "A1:D10").
286
+ # @param columns [Array<String>, Array<Hash>, nil] Column names or definitions.
266
287
  # @param name [String, nil] Table name.
267
288
  # @param display_name [String, nil] Display name.
268
289
  # @param style [String, nil] Table style name.
269
290
  # @param opts [Hash] Additional options.
291
+ # @yield [table_builder] Optional configuration block.
270
292
  # @return [void]
271
293
  # @api public
272
- # : (String ref, columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) -> void
273
- def table: (String ref, columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) -> void
294
+ # : (?String? ref, ?columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) ?{ (TableBuilder) -> void } -> void
295
+ def table: (?String? ref, ?columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) ?{ (TableBuilder) -> void } -> void
274
296
 
275
297
  # simplecov:disable
276
298
  # Edge case / untested delegation block
@@ -575,6 +597,16 @@ module Xlsxrb
575
597
  # : (Symbol | String name, untyped value) -> void
576
598
  def sheet_view: (Symbol | String name, untyped value) -> void
577
599
 
600
+ # Configures sheet format properties (e.g. default_row_height, default_col_width).
601
+ #
602
+ # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
603
+ # @param value [Object, nil] Property value when name is provided.
604
+ # @param opts [Hash] Keyword arguments for sheet format properties.
605
+ # @return [Hash[Symbol, untyped]]
606
+ # @api public
607
+ # : (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
608
+ def sheet_format: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
609
+
578
610
  # simplecov:disable
579
611
  # Edge case / untested delegation block
580
612
  # Adds a horizontal page break after the given row index.
@@ -594,6 +626,29 @@ module Xlsxrb
594
626
  # @api public
595
627
  # : (Integer col_index) -> void
596
628
  def page_break_col: (Integer col_index) -> void
629
+
630
+ # Adds a protected range to the sheet.
631
+ #
632
+ # @param name [String] Name of the protected range.
633
+ # @param sqref [String] Cell range (e.g. "A1:B10").
634
+ # @param password [String, nil] Optional password or hash.
635
+ # @param opts [Hash] Additional options.
636
+ # @return [void]
637
+ # @api public
638
+ # : (String name, String sqref, ?password: String?, **untyped opts) -> void
639
+ def protected_range: (String name, String sqref, ?password: String?, **untyped opts) -> void
640
+
641
+ alias add_protected_range protected_range
642
+
643
+ # Adds a cell watch to the sheet.
644
+ #
645
+ # @param ref [String] Cell reference (e.g. "A1").
646
+ # @return [void]
647
+ # @api public
648
+ # : (String ref) -> void
649
+ def cell_watch: (String ref) -> void
650
+
651
+ alias add_cell_watch cell_watch
597
652
  end
598
653
 
599
654
  # Adds a new sheet to the workbook and starts streaming rows into it.
@@ -621,10 +676,11 @@ module Xlsxrb
621
676
  # @param hidden [Boolean] Whether the row is hidden.
622
677
  # @param custom_height [Boolean] Whether custom row height is set.
623
678
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
679
+ # @param style [Integer, Symbol, String, Hash, nil] Row style format or index.
624
680
  # @return [void]
625
681
  # @api public
626
- # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
627
- def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
682
+ # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: untyped) -> void
683
+ def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: untyped) -> void
628
684
 
629
685
  alias add_row row
630
686
 
@@ -644,11 +700,11 @@ module Xlsxrb
644
700
  # @param index [Integer, String, Range, Array] Column index (0-based) or letter ("A".."D").
645
701
  # @param width [Float, Integer, nil] Column width in character units (0 - 255).
646
702
  # @param hidden [Boolean] Whether the column is hidden.
647
- # @param style [Integer, Symbol, String, nil] Column style format or index.
703
+ # @param style [Integer, Symbol, String, Hash, nil] Column style format or index.
648
704
  # @return [void]
649
705
  # @api public
650
- # : (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String)?) -> void
651
- def column: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String)?) -> void
706
+ # : (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
707
+ def column: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
652
708
 
653
709
  # Adds a chart to the current worksheet.
654
710
  #
@@ -701,12 +757,13 @@ module Xlsxrb
701
757
 
702
758
  # Adds a data validation rule.
703
759
  #
704
- # @param sqref [String] Cell range.
760
+ # @param sqref [String, nil] Cell range.
705
761
  # @param opts [Hash] Validation options.
762
+ # @yield [data_validation_builder] Optional configuration block.
706
763
  # @return [void]
707
764
  # @api public
708
- # : (untyped sqref, **untyped opts) -> void
709
- def validate_data: (untyped sqref, **untyped opts) -> void
765
+ # : (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
766
+ def validate_data: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
710
767
 
711
768
  # Adds a conditional formatting rule.
712
769
  #
@@ -719,16 +776,17 @@ module Xlsxrb
719
776
 
720
777
  # Adds an Excel Table (ListObject).
721
778
  #
722
- # @param ref [String] Table range.
723
- # @param columns [Array<String>] Column names.
779
+ # @param ref [String, nil] Table range.
780
+ # @param columns [Array<String>, nil] Column names.
724
781
  # @param name [String, nil] Table name.
725
782
  # @param display_name [String, nil] Display name.
726
783
  # @param style [String, nil] Table style.
727
784
  # @param opts [Hash] Additional options.
785
+ # @yield [table_builder] Optional configuration block.
728
786
  # @return [void]
729
787
  # @api public
730
- # : (untyped ref, columns: untyped, ?name: untyped, ?display_name: untyped, ?style: untyped, **untyped opts) -> void
731
- def table: (untyped ref, columns: untyped, ?name: untyped, ?display_name: untyped, ?style: untyped, **untyped opts) -> void
788
+ # : (?String? ref, ?columns: untyped, ?name: untyped, ?display_name: untyped, ?style: untyped, **untyped opts) ?{ (TableBuilder) -> void } -> void
789
+ def table: (?String? ref, ?columns: untyped, ?name: untyped, ?display_name: untyped, ?style: untyped, **untyped opts) ?{ (TableBuilder) -> void } -> void
732
790
 
733
791
  # Adds a Pivot Table.
734
792
  #
@@ -920,6 +978,16 @@ module Xlsxrb
920
978
  # : (Symbol name, untyped value) -> void
921
979
  def sheet_view: (Symbol name, untyped value) -> void
922
980
 
981
+ # Configures sheet format properties (e.g. default_row_height, default_col_width).
982
+ #
983
+ # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
984
+ # @param value [Object, nil] Property value when name is provided.
985
+ # @param opts [Hash] Keyword arguments for sheet format properties.
986
+ # @return [Hash[Symbol, untyped]]
987
+ # @api public
988
+ # : (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
989
+ def sheet_format: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
990
+
923
991
  # Inserts a horizontal page break before a row.
924
992
  #
925
993
  # @param row_num [Integer] 1-based row number.
@@ -936,6 +1004,29 @@ module Xlsxrb
936
1004
  # : (Integer col_index) -> void
937
1005
  def page_break_col: (Integer col_index) -> void
938
1006
 
1007
+ # Adds a protected range to the current sheet.
1008
+ #
1009
+ # @param name [String] Name of the protected range.
1010
+ # @param sqref [String] Cell range (e.g. "A1:B10").
1011
+ # @param password [String, nil] Optional password or hash.
1012
+ # @param opts [Hash] Additional options.
1013
+ # @return [void]
1014
+ # @api public
1015
+ # : (String name, String sqref, ?password: String?, **untyped opts) -> void
1016
+ def protected_range: (String name, String sqref, ?password: String?, **untyped opts) -> void
1017
+
1018
+ alias add_protected_range protected_range
1019
+
1020
+ # Adds a cell watch to the current sheet.
1021
+ #
1022
+ # @param ref [String] Cell reference (e.g. "A1").
1023
+ # @return [void]
1024
+ # @api public
1025
+ # : (String ref) -> void
1026
+ def cell_watch: (String ref) -> void
1027
+
1028
+ alias add_cell_watch cell_watch
1029
+
939
1030
  # Adds a defined name.
940
1031
  #
941
1032
  # @param name [String] The defined name.