xlsxrb 0.1.13 → 0.1.14

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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -0
  3. data/README.md +2 -0
  4. data/lib/xlsxrb/colors.rb +118 -0
  5. data/lib/xlsxrb/elements/cell.rb +205 -16
  6. data/lib/xlsxrb/elements/column.rb +6 -4
  7. data/lib/xlsxrb/elements/coordinate_access.rb +32 -0
  8. data/lib/xlsxrb/elements/image.rb +128 -0
  9. data/lib/xlsxrb/elements/row.rb +206 -9
  10. data/lib/xlsxrb/elements/styles.rb +157 -0
  11. data/lib/xlsxrb/elements/types.rb +95 -1
  12. data/lib/xlsxrb/elements/workbook.rb +85 -4
  13. data/lib/xlsxrb/elements/worksheet.rb +424 -29
  14. data/lib/xlsxrb/elements.rb +2 -0
  15. data/lib/xlsxrb/number_formatter.rb +429 -0
  16. data/lib/xlsxrb/ooxml/cfb.rb +1 -1
  17. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +7 -5
  18. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +11 -4
  19. data/lib/xlsxrb/ooxml/reader.rb +12 -14
  20. data/lib/xlsxrb/ooxml/shared_strings_parser.rb +7 -1
  21. data/lib/xlsxrb/ooxml/styles_parser.rb +39 -9
  22. data/lib/xlsxrb/ooxml/utils.rb +34 -18
  23. data/lib/xlsxrb/ooxml/workbook_parser.rb +53 -15
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +65 -14
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +319 -79
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +206 -61
  27. data/lib/xlsxrb/ooxml/writer/features_xml.rb +4 -2
  28. data/lib/xlsxrb/ooxml/writer.rb +14 -0
  29. data/lib/xlsxrb/ooxml/zip_reader.rb +109 -25
  30. data/lib/xlsxrb/stream_row.rb +243 -16
  31. data/lib/xlsxrb/stream_sheet.rb +414 -15
  32. data/lib/xlsxrb/stream_writer.rb +213 -17
  33. data/lib/xlsxrb/style_builder.rb +308 -22
  34. data/lib/xlsxrb/utils.rb +158 -0
  35. data/lib/xlsxrb/version.rb +1 -1
  36. data/lib/xlsxrb/workbook_builder.rb +73 -3
  37. data/lib/xlsxrb/worksheet_builder.rb +227 -16
  38. data/lib/xlsxrb.rb +578 -79
  39. data/sig/generated/xlsxrb/colors.rbs +40 -0
  40. data/sig/generated/xlsxrb/elements/cell.rbs +113 -8
  41. data/sig/generated/xlsxrb/elements/column.rbs +3 -2
  42. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +18 -0
  43. data/sig/generated/xlsxrb/elements/image.rbs +82 -0
  44. data/sig/generated/xlsxrb/elements/row.rbs +83 -4
  45. data/sig/generated/xlsxrb/elements/styles.rbs +79 -0
  46. data/sig/generated/xlsxrb/elements/types.rbs +43 -0
  47. data/sig/generated/xlsxrb/elements/workbook.rbs +51 -2
  48. data/sig/generated/xlsxrb/elements/worksheet.rbs +231 -18
  49. data/sig/generated/xlsxrb/number_formatter.rbs +132 -0
  50. data/sig/generated/xlsxrb/ooxml/reader.rbs +6 -0
  51. data/sig/generated/xlsxrb/ooxml/shared_strings_parser.rbs +2 -0
  52. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +5 -2
  53. data/sig/generated/xlsxrb/ooxml/utils.rbs +17 -8
  54. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +9 -3
  55. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +28 -6
  56. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +3 -1
  57. data/sig/generated/xlsxrb/ooxml/writer.rbs +2 -0
  58. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +10 -0
  59. data/sig/generated/xlsxrb/stream_row.rbs +100 -6
  60. data/sig/generated/xlsxrb/stream_sheet.rbs +247 -13
  61. data/sig/generated/xlsxrb/stream_writer.rbs +120 -14
  62. data/sig/generated/xlsxrb/style_builder.rbs +55 -18
  63. data/sig/generated/xlsxrb/utils.rbs +119 -0
  64. data/sig/generated/xlsxrb/workbook_builder.rbs +26 -0
  65. data/sig/generated/xlsxrb/worksheet_builder.rbs +107 -11
  66. data/sig/generated/xlsxrb.rbs +186 -27
  67. metadata +11 -1
@@ -123,12 +123,24 @@ module Xlsxrb
123
123
  # @param hidden [Boolean] Whether the row is hidden.
124
124
  # @param custom_height [Boolean] Whether to flag as custom height.
125
125
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
126
+ # @param collapsed [Boolean] Whether the row is collapsed.
126
127
  # @return [void]
127
128
  # @api public
128
- # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
129
- def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
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
130
131
 
131
- alias << row
132
+ alias add_row row
133
+
134
+ # Appends a row to the worksheet and returns self for chaining.
135
+ #
136
+ # @example
137
+ # sheet << ["A", 1] << ["B", 2]
138
+ #
139
+ # @param values [Array, Hash] Row cell values.
140
+ # @return [self]
141
+ # @api public
142
+ # : (Array[untyped] | Hash[untyped, untyped] values) -> self
143
+ def <<: (Array[untyped] | Hash[untyped, untyped] values) -> self
132
144
 
133
145
  # Configures column width and properties.
134
146
  #
@@ -179,8 +191,8 @@ module Xlsxrb
179
191
  # @param location [String, nil] Destination location / URL (keyword alternative).
180
192
  # @return [void]
181
193
  # @api public
182
- # : (String cell, ?String? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
183
- def hyperlink: (String cell, ?String? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
194
+ # : (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
195
+ def hyperlink: (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
184
196
 
185
197
  # Sets the auto-filter range on the active sheet.
186
198
  #
@@ -307,6 +319,26 @@ module Xlsxrb
307
319
  # : (sparklines: Array[Hash[Symbol, untyped]], ?type: (String | Symbol)?, **untyped opts) -> void
308
320
  def sparkline_group: (sparklines: Array[Hash[Symbol, untyped]], ?type: (String | Symbol)?, **untyped opts) -> void
309
321
 
322
+ # Adds a single sparkline to the sheet.
323
+ #
324
+ # @example Add a line sparkline
325
+ # s.add_sparkline(location: "F1", range: "A1:E1")
326
+ #
327
+ # @example Add a column sparkline with high/low markers
328
+ # s.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
329
+ #
330
+ # @example Add a win/loss sparkline
331
+ # s.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
332
+ #
333
+ # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
334
+ # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
335
+ # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
336
+ # @param opts [Hash] Additional sparkline options.
337
+ # @return [void]
338
+ # @api public
339
+ # : (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
340
+ def add_sparkline: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
341
+
310
342
  # Sets workbook-level properties.
311
343
  #
312
344
  # @param opts [Hash] Workbook property options.
@@ -377,6 +409,24 @@ module Xlsxrb
377
409
  # : (?rows: String?, ?cols: String?) -> void
378
410
  def print_titles: (?rows: String?, ?cols: String?) -> void
379
411
 
412
+ # Sets repeating title rows to appear at the top of each printed page.
413
+ #
414
+ # @param first [Integer, String] First row index (0-based) or range string (e.g. "1:2").
415
+ # @param last [Integer, String, nil] Optional last row index (0-based).
416
+ # @return [void]
417
+ # @api public
418
+ # : (Integer | String first, ?(Integer | String)? last) -> void
419
+ def repeat_rows: (Integer | String first, ?(Integer | String)? last) -> void
420
+
421
+ # Sets repeating title columns to appear at the left of each printed page.
422
+ #
423
+ # @param first [Integer, String] First column index (0-based) or column name/range.
424
+ # @param last [Integer, String, nil] Optional last column index/name.
425
+ # @return [void]
426
+ # @api public
427
+ # : (Integer | String first, ?(Integer | String)? last) -> void
428
+ def repeat_columns: (Integer | String first, ?(Integer | String)? last) -> void
429
+
380
430
  # Splits sheet view into panes.
381
431
  #
382
432
  # @param x_split [Numeric, nil] Horizontal split position.
@@ -573,22 +623,32 @@ module Xlsxrb
573
623
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
574
624
  # @return [void]
575
625
  # @api public
576
- # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
577
- def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
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
628
+
629
+ alias add_row row
578
630
 
579
- alias << row
631
+ # Appends a row to the worksheet and returns self for chaining.
632
+ #
633
+ # @example
634
+ # writer << ["A", 1] << ["B", 2]
635
+ #
636
+ # @param values [Array, Hash] Row cell values.
637
+ # @return [self]
638
+ # @api public
639
+ # : (Array[untyped] | Hash[untyped, untyped] values) -> self
640
+ def <<: (Array[untyped] | Hash[untyped, untyped] values) -> self
580
641
 
581
642
  # Sets column formatting and properties for one or multiple columns.
582
643
  #
583
644
  # @param index [Integer, String, Range, Array] Column index (0-based) or letter ("A".."D").
584
645
  # @param width [Float, Integer, nil] Column width in character units (0 - 255).
585
646
  # @param hidden [Boolean] Whether the column is hidden.
586
- # @param custom_width [Boolean] Whether custom width is set.
587
- # @param outline_level [Integer, nil] Grouping/outline level.
647
+ # @param style [Integer, Symbol, String, nil] Column style format or index.
588
648
  # @return [void]
589
649
  # @api public
590
- # : (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil) -> void
591
- def column: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil) -> void
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
592
652
 
593
653
  # Adds a chart to the current worksheet.
594
654
  #
@@ -609,8 +669,8 @@ module Xlsxrb
609
669
  # @param location [String, nil] Internal location.
610
670
  # @return [void]
611
671
  # @api public
612
- # : (String | Integer cell, ?String? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
613
- def hyperlink: (String | Integer cell, ?String? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
672
+ # : (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
673
+ def hyperlink: (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
614
674
 
615
675
  # Sets the auto-filter range on the active sheet.
616
676
  #
@@ -706,6 +766,26 @@ module Xlsxrb
706
766
  # : (sparklines: untyped, ?type: untyped, **untyped opts) -> void
707
767
  def sparkline_group: (sparklines: untyped, ?type: untyped, **untyped opts) -> void
708
768
 
769
+ # Adds a single sparkline to the sheet.
770
+ #
771
+ # @example Add a line sparkline
772
+ # writer.add_sparkline(location: "F1", range: "A1:E1")
773
+ #
774
+ # @example Add a column sparkline with high/low markers
775
+ # writer.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
776
+ #
777
+ # @example Add a win/loss sparkline
778
+ # writer.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
779
+ #
780
+ # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
781
+ # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
782
+ # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
783
+ # @param opts [Hash] Additional sparkline options.
784
+ # @return [void]
785
+ # @api public
786
+ # : (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
787
+ def add_sparkline: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
788
+
709
789
  # Merges a range of cells into a single cell.
710
790
  #
711
791
  # @param range [String, Hash, nil] Cell range (e.g. "A1:B2") or hash of coordinates.
@@ -886,6 +966,32 @@ module Xlsxrb
886
966
  # : (?rows: String?, ?cols: String?, ?sheet: String?) -> void
887
967
  def print_titles: (?rows: String?, ?cols: String?, ?sheet: String?) -> void
888
968
 
969
+ # Sets repeating title rows for pagination on the current or named sheet.
970
+ #
971
+ # @example Repeat first row
972
+ # stream.repeat_rows(0)
973
+ #
974
+ # @param first [Integer, String] First row index (0-based) or range string (e.g. "1:2").
975
+ # @param last [Integer, String, nil] Optional last row index (0-based).
976
+ # @param sheet [String, nil] Target sheet name.
977
+ # @return [void]
978
+ # @api public
979
+ # : (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
980
+ def repeat_rows: (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
981
+
982
+ # Sets repeating title columns for pagination on the current or named sheet.
983
+ #
984
+ # @example Repeat columns A through C
985
+ # stream.repeat_columns("A", "C")
986
+ #
987
+ # @param first [Integer, String] First column index (0-based) or column name/range.
988
+ # @param last [Integer, String, nil] Optional last column index/name.
989
+ # @param sheet [String, nil] Target sheet name.
990
+ # @return [void]
991
+ # @api public
992
+ # : (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
993
+ def repeat_columns: (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
994
+
889
995
  # Sets workbook protection.
890
996
  #
891
997
  # @param opts [Hash] Protection options.
@@ -7,6 +7,43 @@ module Xlsxrb
7
7
  class StyleBuilder
8
8
  COLORS: untyped
9
9
 
10
+ CSS_COLORS: untyped
11
+
12
+ BORDER_STYLES: untyped
13
+
14
+ BORDER_INDEX_MAP: untyped
15
+
16
+ # Normalizes a color definition (CSS color name, hex code, or RGB integer) to an OpenXML hex color string.
17
+ #
18
+ # @example
19
+ # StyleBuilder.normalize_color(:navy) #=> "FF000080"
20
+ # StyleBuilder.normalize_color("#FF0000") #=> "FFFF0000"
21
+ # StyleBuilder.normalize_color("#F00") #=> "FFFF0000"
22
+ # StyleBuilder.normalize_color("FF0000", alpha: false) #=> "FF0000"
23
+ # StyleBuilder.normalize_color(0xFF0000) #=> "FFFF0000"
24
+ #
25
+ # @param color [String, Symbol, Integer, nil]
26
+ # @param alpha [Boolean] Whether to include the alpha channel ("AARRGGBB" vs "RRGGBB").
27
+ # @return [String, nil]
28
+ # @api public
29
+ # : (String | Symbol | Integer | nil color, ?alpha: bool) -> String?
30
+ def self.normalize_color: (String | Symbol | Integer | nil color, ?alpha: bool) -> String?
31
+
32
+ # Normalizes a border style symbol, string, or integer index to an OOXML ST_BorderStyle symbol.
33
+ #
34
+ # @example
35
+ # StyleBuilder.normalize_border_style(:border_thin) #=> :thin
36
+ # StyleBuilder.normalize_border_style(1) #=> :thin
37
+ # StyleBuilder.normalize_border_style(:medium_dashed) #=> :mediumDashed
38
+ # StyleBuilder.normalize_border_style("double") #=> :double
39
+ # StyleBuilder.normalize_border_style(0) #=> :none
40
+ #
41
+ # @param style [Symbol, String, Integer, nil]
42
+ # @return [Symbol, nil]
43
+ # @api public
44
+ # : (Symbol | String | Integer | nil style) -> Symbol?
45
+ def self.normalize_border_style: (Symbol | String | Integer | nil style) -> Symbol?
46
+
10
47
  # Resolves a color symbol, string, or prefix to an aRGB hex string.
11
48
  #
12
49
  # @param color [Symbol, String, Object, nil]
@@ -147,55 +184,55 @@ module Xlsxrb
147
184
  def border: (**untyped) -> self
148
185
 
149
186
  # Sets all borders.
150
- # @param style [String, Symbol] The border style.
187
+ # @param style [String, Symbol, Integer] The border style.
151
188
  # @param color [String, Symbol, nil] The color.
152
189
  # @return [self]
153
190
  # @api public
154
- # : (?style: String | Symbol, ?color: String | Symbol | nil) -> self
155
- def border_all: (?style: String | Symbol, ?color: String | Symbol | nil) -> self
191
+ # : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
192
+ def border_all: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
156
193
 
157
194
  # Sets the left border.
158
- # @param style [String, Symbol] The border style.
195
+ # @param style [String, Symbol, Integer] The border style.
159
196
  # @param color [String, Symbol, nil] The color.
160
197
  # @return [self]
161
198
  # @api public
162
- # : (?style: String | Symbol, ?color: String | Symbol | nil) -> self
163
- def border_left: (?style: String | Symbol, ?color: String | Symbol | nil) -> self
199
+ # : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
200
+ def border_left: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
164
201
 
165
202
  # Sets the right border.
166
- # @param style [String, Symbol] The border style.
203
+ # @param style [String, Symbol, Integer] The border style.
167
204
  # @param color [String, Symbol, nil] The color.
168
205
  # @return [self]
169
206
  # @api public
170
- # : (?style: String | Symbol, ?color: String | Symbol | nil) -> self
171
- def border_right: (?style: String | Symbol, ?color: String | Symbol | nil) -> self
207
+ # : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
208
+ def border_right: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
172
209
 
173
210
  # Sets the top border.
174
- # @param style [String, Symbol] The border style.
211
+ # @param style [String, Symbol, Integer] The border style.
175
212
  # @param color [String, Symbol, nil] The color.
176
213
  # @return [self]
177
214
  # @api public
178
- # : (?style: String | Symbol, ?color: String | Symbol | nil) -> self
179
- def border_top: (?style: String | Symbol, ?color: String | Symbol | nil) -> self
215
+ # : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
216
+ def border_top: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
180
217
 
181
218
  # Sets the bottom border.
182
- # @param style [String, Symbol] The border style.
219
+ # @param style [String, Symbol, Integer] The border style.
183
220
  # @param color [String, Symbol, nil] The color.
184
221
  # @return [self]
185
222
  # @api public
186
- # : (?style: String | Symbol, ?color: String | Symbol | nil) -> self
187
- def border_bottom: (?style: String | Symbol, ?color: String | Symbol | nil) -> self
223
+ # : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
224
+ def border_bottom: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
188
225
 
189
226
  # rubocop:disable Naming/MethodParameterName
190
227
  # Sets diagonal borders.
191
- # @param style [String, Symbol] The border style.
228
+ # @param style [String, Symbol, Integer] The border style.
192
229
  # @param color [String, Symbol, nil] The color.
193
230
  # @param up [Boolean] Diagonal up.
194
231
  # @param down [Boolean] Diagonal down.
195
232
  # @return [self]
196
233
  # @api public
197
- # : (?style: String | Symbol, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> self
198
- def border_diagonal: (?style: String | Symbol, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> self
234
+ # : (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> self
235
+ def border_diagonal: (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> self
199
236
 
200
237
  # Sets horizontal alignment.
201
238
  # @param value [String, Symbol] The alignment.
@@ -0,0 +1,119 @@
1
+ # Generated from lib/xlsxrb/utils.rb with RBS::Inline
2
+
3
+ module Xlsxrb
4
+ # Public coordinate conversion and reference parsing utilities.
5
+ #
6
+ # @api public
7
+ module Utils
8
+ # Converts a cell reference string (e.g. "A1", "BC100") to 0-based [row, col] coordinates.
9
+ #
10
+ # @example
11
+ # Xlsxrb::Utils.ref_to_row_col("A1") #=> [0, 0]
12
+ # Xlsxrb::Utils.ref_to_row_col("BC100") #=> [99, 54]
13
+ #
14
+ # @param cell_ref [String, nil] Excel cell reference string.
15
+ # @return [Array(Integer, Integer), nil] 0-based [row_idx, col_idx] tuple, or nil if invalid.
16
+ # @api public
17
+ # : (String? cell_ref) -> [Integer, Integer]?
18
+ def self.ref_to_row_col: (String? cell_ref) -> [ Integer, Integer ]?
19
+
20
+ # Converts 0-based [row_idx, col_idx] coordinates to an A1-style reference string.
21
+ #
22
+ # @example
23
+ # Xlsxrb::Utils.row_col_to_ref(0, 0) #=> "A1"
24
+ # Xlsxrb::Utils.row_col_to_ref(99, 54) #=> "BC100"
25
+ #
26
+ # @param row_idx [Integer] 0-based row index.
27
+ # @param col_idx [Integer] 0-based column index.
28
+ # @return [String] A1-style reference string.
29
+ # @api public
30
+ # : (Integer row_idx, Integer col_idx) -> String
31
+ def self.row_col_to_ref: (Integer row_idx, Integer col_idx) -> String
32
+
33
+ # Converts a column letter name (e.g. "A", "BC") to a 0-based integer index.
34
+ #
35
+ # @example
36
+ # Xlsxrb::Utils.col_name_to_index("A") #=> 0
37
+ # Xlsxrb::Utils.col_name_to_index("BC") #=> 54
38
+ #
39
+ # @param col_name [String, Symbol, Integer] Column letter or index.
40
+ # @return [Integer] 0-based column index.
41
+ # @api public
42
+ # : (String | Symbol | Integer col_name) -> Integer
43
+ def self.col_name_to_index: (String | Symbol | Integer col_name) -> Integer
44
+
45
+ # Converts a 0-based column integer index to a column letter name (e.g. 0 -> "A", 54 -> "BC").
46
+ #
47
+ # @example
48
+ # Xlsxrb::Utils.col_index_to_name(0) #=> "A"
49
+ # Xlsxrb::Utils.col_index_to_name(54) #=> "BC"
50
+ #
51
+ # @param col_idx [Integer] 0-based column index.
52
+ # @return [String] Column letter name.
53
+ # @api public
54
+ # : (Integer col_idx) -> String
55
+ def self.col_index_to_name: (Integer col_idx) -> String
56
+
57
+ # Splits an A1-style cell reference into its column name and 1-based row number.
58
+ #
59
+ # @example
60
+ # Xlsxrb::Utils.split_coordinate("A1") #=> ["A", 1]
61
+ # Xlsxrb::Utils.split_coordinate("BC100") #=> ["BC", 100]
62
+ #
63
+ # @param cell_ref [String, nil] Excel cell reference string.
64
+ # @return [Array(String, Integer), nil] [col_name, row_number] tuple (1-based row), or nil if invalid.
65
+ # @api public
66
+ # : (String? cell_ref) -> [String, Integer]?
67
+ def self.split_coordinate: (String? cell_ref) -> [ String, Integer ]?
68
+
69
+ # Converts a Date or Time to an Excel numeric serial number (1900 or 1904 system).
70
+ #
71
+ # @example
72
+ # Xlsxrb::Utils.date_to_serial(Date.new(2026, 1, 1)) #=> 46023
73
+ #
74
+ # @param date_or_time [Date, Time] Date or Time instance.
75
+ # @param date1904 [Boolean] Whether to use the 1904 date system.
76
+ # @return [Integer, Float] Serial number.
77
+ # @api public
78
+ # : (Date | Time date_or_time, ?date1904: bool) -> (Integer | Float)
79
+ def self.date_to_serial: (Date | Time date_or_time, ?date1904: bool) -> (Integer | Float)
80
+
81
+ # Converts an Excel serial number to a Date.
82
+ #
83
+ # @example
84
+ # Xlsxrb::Utils.serial_to_date(46023) #=> #<Date: 2026-01-01>
85
+ #
86
+ # @param serial [Numeric] Excel serial number.
87
+ # @param date1904 [Boolean] Whether to use the 1904 date system.
88
+ # @return [Date]
89
+ # @api public
90
+ # : (Numeric serial, ?date1904: bool) -> Date
91
+ def self.serial_to_date: (Numeric serial, ?date1904: bool) -> Date
92
+
93
+ # Converts a Time or Date to a fractional Excel serial number.
94
+ #
95
+ # @example
96
+ # Xlsxrb::Utils.datetime_to_serial(Time.utc(2026, 1, 1, 12, 0, 0)) #=> 46023.5
97
+ #
98
+ # @param time [Time, Date] Time or Date instance.
99
+ # @param date1904 [Boolean] Whether to use the 1904 date system.
100
+ # @return [Float] Fractional serial number.
101
+ # @api public
102
+ # : (Time | Date time, ?date1904: bool) -> Float
103
+ def self.datetime_to_serial: (Time | Date time, ?date1904: bool) -> Float
104
+
105
+ # Converts an Excel serial number to a Time (UTC).
106
+ #
107
+ # @example
108
+ # Xlsxrb::Utils.serial_to_time(46023.5) #=> 2026-01-01 12:00:00 UTC
109
+ #
110
+ # @param serial [Numeric] Excel serial number.
111
+ # @param date1904 [Boolean] Whether to use the 1904 date system.
112
+ # @return [Time]
113
+ # @api public
114
+ # : (Numeric serial, ?date1904: bool) -> Time
115
+ def self.serial_to_time: (Numeric serial, ?date1904: bool) -> Time
116
+
117
+ alias self.serial_to_datetime self.serial_to_time
118
+ end
119
+ end
@@ -75,6 +75,32 @@ module Xlsxrb
75
75
  # : (?rows: String?, ?cols: String?, ?sheet: String?) -> void
76
76
  def print_titles: (?rows: String?, ?cols: String?, ?sheet: String?) -> void
77
77
 
78
+ # Sets repeating title rows for pagination on the target or active sheet.
79
+ #
80
+ # @example Repeat first row
81
+ # wb.repeat_rows(0)
82
+ #
83
+ # @param first [Integer, String] First row index (0-based) or range string (e.g. "1:2").
84
+ # @param last [Integer, String, nil] Optional last row index (0-based).
85
+ # @param sheet [String, nil] Target sheet name.
86
+ # @return [void]
87
+ # @api public
88
+ # : (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
89
+ def repeat_rows: (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
90
+
91
+ # Sets repeating title columns for pagination on the target or active sheet.
92
+ #
93
+ # @example Repeat columns A through C
94
+ # wb.repeat_columns("A", "C")
95
+ #
96
+ # @param first [Integer, String] First column index (0-based) or column name/range.
97
+ # @param last [Integer, String, nil] Optional last column index/name.
98
+ # @param sheet [String, nil] Target sheet name.
99
+ # @return [void]
100
+ # @api public
101
+ # : (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
102
+ def repeat_columns: (Integer | String first, ?(Integer | String)? last, ?sheet: String?) -> void
103
+
78
104
  # Sets workbook structure and window protection.
79
105
  #
80
106
  # @param opts [Hash] Protection options (e.g. lock_structure: true, password: "secret").
@@ -7,8 +7,11 @@ module Xlsxrb
7
7
  class WorksheetBuilder
8
8
  # @param name [String] The worksheet name.
9
9
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel limits.
10
- # : (String name, ?strict_excel_mode: bool) -> void
11
- def initialize: (String name, ?strict_excel_mode: bool) -> void
10
+ # @param state [Symbol] Sheet visibility state (:visible, :hidden, or :very_hidden).
11
+ # : (String name, ?strict_excel_mode: bool, ?state: Symbol) -> void
12
+ def initialize: (String name, ?strict_excel_mode: bool, ?state: Symbol) -> void
13
+
14
+ attr_reader name: untyped
12
15
 
13
16
  # Defines or configures a named cell style.
14
17
  #
@@ -38,11 +41,25 @@ module Xlsxrb
38
41
  # @param hidden [Boolean] Whether the row is hidden.
39
42
  # @param custom_height [Boolean] Whether custom row height is enforced.
40
43
  # @param outline_level [Integer, nil] Grouping/outline hierarchy level.
44
+ # @param collapsed [Boolean] Whether the row is collapsed.
41
45
  # @return [void]
42
46
  # @raise [ArgumentError] If limits are exceeded when strict_excel_mode is enabled.
43
47
  # @api public
44
- # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
45
- def row: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
48
+ # : (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
49
+ 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
50
+
51
+ alias add_row row
52
+
53
+ # Appends a row to the worksheet and returns self for chaining.
54
+ #
55
+ # @example
56
+ # sheet << ["A", 1] << ["B", 2]
57
+ #
58
+ # @param values [Array, Hash] Row cell values.
59
+ # @return [self]
60
+ # @api public
61
+ # : (Array[untyped] | Hash[untyped, untyped] values) -> self
62
+ def <<: (Array[untyped] | Hash[untyped, untyped] values) -> self
46
63
 
47
64
  # Sets column formatting and properties for one or multiple columns.
48
65
  #
@@ -54,14 +71,12 @@ module Xlsxrb
54
71
  #
55
72
  # @param index [Integer, String, Range, Array] Column index (0-based), letter ("A"), or range ("A".."D").
56
73
  # @param width [Float, Integer, nil] Column width in character units (0 to 255).
57
- # @param hidden [Boolean] Whether the column is hidden.
58
- # @param custom_width [Boolean] Whether custom width is explicitly set.
59
- # @param outline_level [Integer, nil] Grouping/outline level.
74
+ # @param style [Integer, Symbol, String, nil] Column style format or index.
60
75
  # @return [void]
61
76
  # @raise [ArgumentError] If width exceeds 255 in strict mode.
62
77
  # @api public
63
- # : (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil) -> void
64
- def column: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil) -> void
78
+ # : (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
79
+ 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
65
80
 
66
81
  # Adds a chart to the worksheet.
67
82
  #
@@ -82,8 +97,8 @@ module Xlsxrb
82
97
  # @param location [String, nil] Optional internal sheet location (e.g. "Sheet2!A1").
83
98
  # @return [void]
84
99
  # @api public
85
- # : (String | Integer cell, ?String? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
86
- def hyperlink: (String | Integer cell, ?String? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
100
+ # : (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
101
+ def hyperlink: (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
87
102
 
88
103
  # Sets an auto-filter range on the sheet.
89
104
  #
@@ -178,6 +193,26 @@ module Xlsxrb
178
193
  # : (sparklines: Array[String | Hash[Symbol, untyped]], ?type: (String | Symbol)?, **untyped opts) -> void
179
194
  def sparkline_group: (sparklines: Array[String | Hash[Symbol, untyped]], ?type: (String | Symbol)?, **untyped opts) -> void
180
195
 
196
+ # Adds a single sparkline to the sheet.
197
+ #
198
+ # @example Add a line sparkline
199
+ # sheet.add_sparkline(location: "F1", range: "A1:E1")
200
+ #
201
+ # @example Add a column sparkline with high/low markers
202
+ # sheet.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
203
+ #
204
+ # @example Add a win/loss sparkline
205
+ # sheet.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
206
+ #
207
+ # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
208
+ # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
209
+ # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
210
+ # @param opts [Hash] Additional sparkline options.
211
+ # @return [void]
212
+ # @api public
213
+ # : (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
214
+ def add_sparkline: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
215
+
181
216
  # Merges a range of cells into a single cell.
182
217
  #
183
218
  # @example Merge with string range
@@ -264,6 +299,67 @@ module Xlsxrb
264
299
  # : (Symbol name, untyped value) -> void
265
300
  def print_options: (Symbol name, untyped value) -> void
266
301
 
302
+ # Sets or gets the print area for the worksheet.
303
+ #
304
+ # @example Set print area range
305
+ # sheet.print_area("A1:H50")
306
+ #
307
+ # @example Get print area range
308
+ # sheet.print_area #=> "A1:H50"
309
+ #
310
+ # @param range [String, nil] Cell range (e.g. "A1:H50").
311
+ # @return [String, nil]
312
+ # @api public
313
+ # : (?String? range) -> String?
314
+ def print_area: (?String? range) -> String?
315
+
316
+ # Sets or gets repeating print titles (rows and/or columns) for pagination.
317
+ #
318
+ # @example Set repeating header rows
319
+ # sheet.print_titles(rows: "1:2")
320
+ #
321
+ # @example Get repeating print titles
322
+ # sheet.print_titles #=> { rows: "1:2", cols: nil }
323
+ #
324
+ # @param rows [String, nil] Repeating row range (e.g. "1:2").
325
+ # @param cols [String, nil] Repeating column range (e.g. "A:B").
326
+ # @return [Hash, nil]
327
+ # @api public
328
+ # : (?rows: String?, ?cols: String?) -> Hash[Symbol, untyped]?
329
+ def print_titles: (?rows: String?, ?cols: String?) -> Hash[Symbol, untyped]?
330
+
331
+ # Sets repeating title rows to appear at the top of each printed page.
332
+ # Accepts 0-indexed row numbers (WriteXLSX / xlsxrb convention) or Excel range string ("1:2").
333
+ #
334
+ # @example Repeat first row
335
+ # sheet.repeat_rows(0)
336
+ #
337
+ # @example Repeat rows 1 through 3
338
+ # sheet.repeat_rows(0, 2)
339
+ #
340
+ # @param first [Integer, String] First row index (0-based) or range string (e.g. "1:2").
341
+ # @param last [Integer, String, nil] Optional last row index (0-based, defaults to first).
342
+ # @return [void]
343
+ # @api public
344
+ # : (Integer | String first, ?(Integer | String)? last) -> void
345
+ def repeat_rows: (Integer | String first, ?(Integer | String)? last) -> void
346
+
347
+ # Sets repeating title columns to appear at the left of each printed page.
348
+ # Accepts 0-indexed column numbers (0 => "A"), column names ("A", "B"), or range string ("A:B").
349
+ #
350
+ # @example Repeat column A
351
+ # sheet.repeat_columns(0)
352
+ #
353
+ # @example Repeat columns A through C
354
+ # sheet.repeat_columns("A", "C")
355
+ #
356
+ # @param first [Integer, String] First column index (0-based) or column name/range.
357
+ # @param last [Integer, String, nil] Optional last column index/name (defaults to first).
358
+ # @return [void]
359
+ # @api public
360
+ # : (Integer | String first, ?(Integer | String)? last) -> void
361
+ def repeat_columns: (Integer | String first, ?(Integer | String)? last) -> void
362
+
267
363
  # Sets sheet-level protection with optional password hashing.
268
364
  #
269
365
  # @param opts [Hash] Protection options (e.g. password: "secret", select_locked_cells: true).