xlsxrb 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +93 -1
  3. data/README.md +79 -19
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +595 -113
  6. data/lib/xlsxrb/dsl_helpers.rb +72 -20
  7. data/lib/xlsxrb/elements/cell.rb +243 -56
  8. data/lib/xlsxrb/elements/column.rb +94 -5
  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 +242 -7
  15. data/lib/xlsxrb/elements/workbook.rb +171 -82
  16. data/lib/xlsxrb/elements/worksheet.rb +598 -102
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +12 -4
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -2
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +264 -17
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
  22. data/lib/xlsxrb/ooxml/reader.rb +4 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +10 -3
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +90 -36
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +2 -2
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +64 -19
  27. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +5 -2
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +26 -5
  29. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +19 -9
  30. data/lib/xlsxrb/ooxml/writer.rb +22 -6
  31. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  32. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  33. data/lib/xlsxrb/stream_row.rb +97 -18
  34. data/lib/xlsxrb/stream_sheet.rb +706 -190
  35. data/lib/xlsxrb/stream_writer.rb +1893 -374
  36. data/lib/xlsxrb/style_builder.rb +774 -111
  37. data/lib/xlsxrb/utils.rb +66 -106
  38. data/lib/xlsxrb/version.rb +1 -1
  39. data/lib/xlsxrb/workbook_builder.rb +380 -83
  40. data/lib/xlsxrb/worksheet_builder.rb +1210 -233
  41. data/lib/xlsxrb.rb +1266 -326
  42. data/sig/generated/xlsxrb/chart_builder.rbs +319 -90
  43. data/sig/generated/xlsxrb/dsl_helpers.rbs +20 -2
  44. data/sig/generated/xlsxrb/elements/cell.rbs +92 -20
  45. data/sig/generated/xlsxrb/elements/column.rbs +61 -2
  46. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  47. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  48. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  49. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  50. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  51. data/sig/generated/xlsxrb/elements/types.rbs +27 -0
  52. data/sig/generated/xlsxrb/elements/workbook.rbs +63 -52
  53. data/sig/generated/xlsxrb/elements/worksheet.rbs +192 -51
  54. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -0
  55. data/sig/generated/xlsxrb/ooxml/reader.rbs +3 -0
  56. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
  57. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +1 -1
  58. data/sig/generated/xlsxrb/ooxml/writer.rbs +3 -0
  59. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  60. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  61. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  62. data/sig/generated/xlsxrb/stream_sheet.rbs +324 -115
  63. data/sig/generated/xlsxrb/stream_writer.rbs +1068 -255
  64. data/sig/generated/xlsxrb/style_builder.rbs +389 -79
  65. data/sig/generated/xlsxrb/utils.rbs +34 -18
  66. data/sig/generated/xlsxrb/workbook_builder.rbs +234 -34
  67. data/sig/generated/xlsxrb/worksheet_builder.rbs +628 -126
  68. data/sig/generated/xlsxrb.rbs +257 -49
  69. metadata +3 -1
@@ -18,9 +18,14 @@ module Xlsxrb
18
18
  # @param unmapped_data [Hash] Additional metadata for round-tripping.
19
19
  # @param errors [Array<String>, nil] Validation errors.
20
20
  # @param defined_names [Array<Hash>, nil] Defined names list.
21
+ # @param workbook_properties [Elements::WorkbookProperties, Hash, nil] Workbook properties.
22
+ # @param core_properties [Elements::CoreProperties, Hash, nil] Core properties.
23
+ # @param app_properties [Elements::AppProperties, Hash, nil] App properties.
24
+ # @param workbook_protection [Elements::WorkbookProtection, Hash, nil] Workbook protection.
25
+ # @param custom_properties [Hash, Array, nil] Custom properties.
21
26
  # @param date1904 [Boolean] Whether the workbook uses the 1904 date system.
22
- # : (?sheets: Array[Elements::Worksheet | StreamSheet], ?shared_strings: Array[String], ?styles: Elements::Styles | Hash[untyped, untyped], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?, ?defined_names: Array[Hash[Symbol, untyped]]?, ?date1904: bool) -> void
23
- def initialize: (?sheets: Array[Elements::Worksheet | StreamSheet], ?shared_strings: Array[String], ?styles: Elements::Styles | Hash[untyped, untyped], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?, ?defined_names: Array[Hash[Symbol, untyped]]?, ?date1904: bool) -> void
27
+ # : (?sheets: Array[Elements::Worksheet | StreamSheet], ?shared_strings: Array[String], ?styles: Elements::Styles | Hash[untyped, untyped], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?, ?defined_names: Array[untyped]?, ?workbook_properties: (Elements::WorkbookProperties | Hash[Symbol, untyped])?, ?core_properties: (Elements::CoreProperties | Hash[Symbol, untyped])?, ?app_properties: (Elements::AppProperties | Hash[Symbol, untyped])?, ?workbook_protection: (Elements::WorkbookProtection | Hash[Symbol, untyped])?, ?custom_properties: (Hash[String, Elements::CustomProperty] | Hash[untyped, untyped] | Array[untyped])?, ?date1904: bool) -> void
28
+ def initialize: (?sheets: Array[Elements::Worksheet | StreamSheet], ?shared_strings: Array[String], ?styles: Elements::Styles | Hash[untyped, untyped], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?, ?defined_names: Array[untyped]?, ?workbook_properties: (Elements::WorkbookProperties | Hash[Symbol, untyped])?, ?core_properties: (Elements::CoreProperties | Hash[Symbol, untyped])?, ?app_properties: (Elements::AppProperties | Hash[Symbol, untyped])?, ?workbook_protection: (Elements::WorkbookProtection | Hash[Symbol, untyped])?, ?custom_properties: (Hash[String, Elements::CustomProperty] | Hash[untyped, untyped] | Array[untyped])?, ?date1904: bool) -> void
24
29
 
25
30
  # Iterate over worksheets.
26
31
  #
@@ -37,7 +42,11 @@ module Xlsxrb
37
42
  def each: () { (Elements::Worksheet | StreamSheet) -> void } -> void
38
43
  | () -> Enumerator[Elements::Worksheet | StreamSheet, void]
39
44
 
40
- alias each_sheet each
45
+ # @deprecated Use {#each} instead. Will be removed in 0.2.0.
46
+ # : () { (Elements::Worksheet | StreamSheet) -> void } -> void
47
+ # : () -> Enumerator[Elements::Worksheet | StreamSheet, void]
48
+ def each_sheet: () { (Elements::Worksheet | StreamSheet) -> void } -> void
49
+ | () -> Enumerator[Elements::Worksheet | StreamSheet, void]
41
50
 
42
51
  # Returns whether the workbook is valid according to ECMA-376 rules.
43
52
  #
@@ -45,13 +54,6 @@ module Xlsxrb
45
54
  # : () -> bool
46
55
  def valid?: () -> bool
47
56
 
48
- # Returns workbook-level properties (e.g. date1904, active_tab, full_calc_on_load), or an empty hash.
49
- #
50
- # @return [Hash<Symbol, untyped>]
51
- # @api public
52
- # : () -> Hash[Symbol, untyped]
53
- def workbook_properties: () -> Hash[Symbol, untyped]
54
-
55
57
  # Returns whether the workbook uses the 1904 date system.
56
58
  #
57
59
  # @return [Boolean]
@@ -66,11 +68,17 @@ module Xlsxrb
66
68
  # : () -> String?
67
69
  def code_name: () -> String?
68
70
 
69
- # Returns the 0-based active worksheet tab index from workbookView, or nil if not set.
71
+ # Returns the 0-based active worksheet index from workbookView, or nil if not set.
70
72
  #
71
73
  # @return [Integer, nil]
72
74
  # @api public
73
75
  # : () -> Integer?
76
+ def active_sheet_index: () -> Integer?
77
+
78
+ # @deprecated Use {#active_sheet_index} or {#active_sheet} instead.
79
+ # @return [Integer, nil]
80
+ # @api public
81
+ # : () -> Integer?
74
82
  def active_tab: () -> Integer?
75
83
 
76
84
  # Returns the active worksheet in the workbook, or the first worksheet if not set.
@@ -94,7 +102,9 @@ module Xlsxrb
94
102
  # : () -> bool
95
103
  def show_sheet_tabs?: () -> bool
96
104
 
97
- alias show_sheet_tabs show_sheet_tabs?
105
+ # @deprecated Use {#show_sheet_tabs?} instead. Will be removed in 0.2.0.
106
+ # : () -> bool
107
+ def show_sheet_tabs: () -> bool
98
108
 
99
109
  # Returns the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
100
110
  #
@@ -110,35 +120,9 @@ module Xlsxrb
110
120
  # : () -> bool
111
121
  def full_calc_on_load?: () -> bool
112
122
 
113
- alias full_calc_on_load full_calc_on_load?
114
-
115
- # Returns core document properties (e.g. title, creator, created), or an empty hash.
116
- #
117
- # @return [Hash<Symbol, untyped>]
118
- # @api public
119
- # : () -> Hash[Symbol, untyped]
120
- def core_properties: () -> Hash[Symbol, untyped]
121
-
122
- # Returns application properties (e.g. app_name, doc_security), or an empty hash.
123
- #
124
- # @return [Hash<Symbol, untyped>]
125
- # @api public
126
- # : () -> Hash[Symbol, untyped]
127
- def app_properties: () -> Hash[Symbol, untyped]
128
-
129
- # Returns custom document properties as an array of property hashes, or an empty array.
130
- #
131
- # @return [Array<Hash[Symbol, untyped]>]
132
- # @api public
133
- # : () -> Array[Hash[Symbol, untyped]]
134
- def custom_properties: () -> Array[Hash[Symbol, untyped]]
135
-
136
- # Returns workbook protection settings as a hash, or nil if unprotected.
137
- #
138
- # @return [Hash[Symbol, untyped], nil]
139
- # @api public
140
- # : () -> Hash[Symbol, untyped]?
141
- def workbook_protection: () -> Hash[Symbol, untyped]?
123
+ # @deprecated Use {#full_calc_on_load?} instead. Will be removed in 0.2.0.
124
+ # : () -> bool
125
+ def full_calc_on_load: () -> bool
142
126
 
143
127
  # Returns the defined name matching name (and optionally sheet), or nil.
144
128
  #
@@ -147,23 +131,24 @@ module Xlsxrb
147
131
  # wb.defined_name("Print_Area", sheet: "Sheet1")
148
132
  #
149
133
  # @param name [String] The defined name.
150
- # @param sheet [String, Integer, nil] Optional sheet name or 0-based index.
151
- # @return [Hash[Symbol, untyped], nil]
134
+ # @param sheet [String, Symbol, Integer, nil] Optional sheet name or 0-based index.
135
+ # @return [Elements::DefinedName, nil]
152
136
  # @api public
153
- # : (String name, ?sheet: (String | Integer)?) -> Hash[Symbol, untyped]?
154
- def defined_name: (String name, ?sheet: (String | Integer)?) -> Hash[Symbol, untyped]?
137
+ # : (String name, ?sheet: (String | Symbol | Integer)?) -> Elements::DefinedName?
138
+ def defined_name: (String name, ?sheet: (String | Symbol | Integer)?) -> Elements::DefinedName?
155
139
 
156
140
  # Returns the worksheet at the given 0-based index or by name.
157
141
  #
158
142
  # @example
159
143
  # wb.sheet(0)
160
144
  # wb.sheet("Sales")
145
+ # wb.sheet(:Sales)
161
146
  #
162
- # @param identifier [Integer, String, untyped] 0-based index or sheet name.
147
+ # @param identifier [Integer, String, Symbol, untyped] 0-based index or sheet name.
163
148
  # @return [Elements::Worksheet, StreamSheet, nil]
164
149
  # @api public
165
- # : (?Integer | String | untyped identifier) -> (Elements::Worksheet | StreamSheet)?
166
- def sheet: (?Integer | String | untyped identifier) -> (Elements::Worksheet | StreamSheet)?
150
+ # : (?Integer | String | Symbol | untyped identifier) -> (Elements::Worksheet | StreamSheet)?
151
+ def sheet: (?Integer | String | Symbol | untyped identifier) -> (Elements::Worksheet | StreamSheet)?
167
152
 
168
153
  alias [] sheet
169
154
 
@@ -194,19 +179,27 @@ module Xlsxrb
194
179
  # : (Integer | String | untyped sheet_identifier, String | Symbol | Integer ref_or_row, ?Integer? col) -> Array[Elements::Image]
195
180
  def images_at: (Integer | String | untyped sheet_identifier, String | Symbol | Integer ref_or_row, ?Integer? col) -> Array[Elements::Image]
196
181
 
182
+ # Internal load helper without deprecation warning.
183
+ # @api private
184
+ # : () -> Elements::Workbook
185
+ def _load: () -> Elements::Workbook
186
+
197
187
  # Loads all sheets into memory, returning an Elements::Workbook where every
198
188
  # worksheet is a fully-parsed Elements::Worksheet supporting coordinate random access.
199
189
  #
200
190
  # @example
201
- # wb = Xlsxrb.read("file.xlsx").load
191
+ # wb = Xlsxrb.load("file.xlsx")
202
192
  # puts wb["Sheet1"]["A1"].value
203
193
  #
194
+ # @deprecated Use {Xlsxrb.load} instead. Will be removed in 0.2.0.
204
195
  # @return [Elements::Workbook]
205
196
  # @api public
206
197
  # : () -> Elements::Workbook
207
198
  def load: () -> Elements::Workbook
208
199
 
209
- alias to_workbook load
200
+ # @deprecated Use {Xlsxrb.load} instead. Will be removed in 0.2.0.
201
+ # : () -> Elements::Workbook
202
+ def to_workbook: () -> Elements::Workbook
210
203
 
211
204
  # Closes any streaming resources associated with worksheets.
212
205
  #
@@ -218,6 +211,7 @@ module Xlsxrb
218
211
  # Returns a new Workbook with the specified sheet updated.
219
212
  # Yields the matched worksheet to the block, which must return a new Worksheet.
220
213
  #
214
+ # @deprecated Use {Xlsxrb.read} + {Xlsxrb.write} for streaming transformations or {Xlsxrb.write} DSL for report generation. Will be removed in 0.2.0.
221
215
  # @example
222
216
  # new_wb = wb.update_sheet("Sheet1") do |sheet|
223
217
  # sheet.update_cell("A1", value: "New Title")
@@ -245,15 +239,32 @@ module Xlsxrb
245
239
  # wb.save("output.xlsx")
246
240
  #
247
241
  # @param filepath [String, IO, StringIO] Destination file path or IO stream.
242
+ # @param shared_strings [Boolean] Whether to intern strings into a shared strings table.
243
+ # @param compression_level [Integer, nil] ZIP deflate compression level (0..9).
244
+ # @param options [Hash] Optional write options forwarded to {Xlsxrb.write} (e.g. `password:`, `encryption_mode:`).
248
245
  # @return [void]
249
246
  # @api public
250
- # : (String | IO | StringIO filepath) -> void
251
- def save: (String | IO | StringIO filepath) -> void
247
+ # : (String | IO | StringIO filepath, ?shared_strings: bool, ?compression_level: Integer?, **untyped options) -> void
248
+ def save: (String | IO | StringIO filepath, ?shared_strings: bool, ?compression_level: Integer?, **untyped options) -> void
249
+
250
+ # Serializes the workbook to a binary XLSX data string in memory.
251
+ #
252
+ # @example Export workbook bytes
253
+ # data = wb.to_data
254
+ #
255
+ # @param shared_strings [Boolean] Whether to intern strings into a shared strings table.
256
+ # @param compression_level [Integer, nil] ZIP deflate compression level (0..9).
257
+ # @param options [Hash] Additional write options forwarded to {Xlsxrb.write} (e.g. `password:`, `encryption_mode:`).
258
+ # @return [String] Binary XLSX data.
259
+ # @api public
260
+ # : (?shared_strings: bool, ?compression_level: Integer?, **untyped options) -> String
261
+ def to_data: (?shared_strings: bool, ?compression_level: Integer?, **untyped options) -> String
252
262
 
253
263
  # Validates workbook structure according to OOXML specifications.
254
264
  #
255
265
  # @param sheets [Array<Elements::Worksheet>]
256
266
  # @return [Array<String>] List of error messages.
267
+ # @api private
257
268
  # : (untyped sheets) -> Array[String]
258
269
  def self.validate: (untyped sheets) -> Array[String]
259
270
  end