xlsxrb 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/README.md +81 -21
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +619 -98
  6. data/lib/xlsxrb/dsl_helpers.rb +583 -15
  7. data/lib/xlsxrb/elements/cell.rb +265 -53
  8. data/lib/xlsxrb/elements/column.rb +95 -6
  9. data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
  10. data/lib/xlsxrb/elements/image.rb +81 -15
  11. data/lib/xlsxrb/elements/metadata.rb +2733 -0
  12. data/lib/xlsxrb/elements/row.rb +130 -46
  13. data/lib/xlsxrb/elements/styles.rb +184 -76
  14. data/lib/xlsxrb/elements/types.rb +243 -7
  15. data/lib/xlsxrb/elements/workbook.rb +202 -65
  16. data/lib/xlsxrb/elements/worksheet.rb +728 -85
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
  22. data/lib/xlsxrb/ooxml/reader.rb +92 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
  24. data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
  25. data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
  26. data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
  27. data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
  28. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
  29. data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
  30. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
  31. data/lib/xlsxrb/ooxml/writer.rb +288 -35
  32. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  33. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  34. data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
  35. data/lib/xlsxrb/stream_row.rb +97 -18
  36. data/lib/xlsxrb/stream_sheet.rb +827 -157
  37. data/lib/xlsxrb/stream_writer.rb +2766 -375
  38. data/lib/xlsxrb/style_builder.rb +821 -105
  39. data/lib/xlsxrb/utils.rb +82 -57
  40. data/lib/xlsxrb/version.rb +1 -1
  41. data/lib/xlsxrb/workbook_builder.rb +542 -62
  42. data/lib/xlsxrb/worksheet_builder.rb +2279 -209
  43. data/lib/xlsxrb.rb +1539 -344
  44. data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
  45. data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
  46. data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
  47. data/sig/generated/xlsxrb/elements/column.rbs +62 -3
  48. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  49. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  50. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  51. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  52. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  53. data/sig/generated/xlsxrb/elements/types.rbs +29 -0
  54. data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
  55. data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
  56. data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
  57. data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
  58. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
  59. data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
  60. data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
  61. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
  62. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
  63. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
  64. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
  65. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
  66. data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
  67. data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
  68. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  69. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  70. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
  71. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  72. data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
  73. data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
  74. data/sig/generated/xlsxrb/style_builder.rbs +403 -75
  75. data/sig/generated/xlsxrb/utils.rbs +49 -13
  76. data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
  77. data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
  78. data/sig/generated/xlsxrb.rbs +321 -52
  79. metadata +3 -1
@@ -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]
@@ -59,49 +61,68 @@ module Xlsxrb
59
61
  # : () -> bool
60
62
  def date1904?: () -> bool
61
63
 
62
- # Returns the 0-based active worksheet tab index from workbookView, or nil if not set.
64
+ # Returns the internal VBA or application code name of the workbook, or nil if not specified.
63
65
  #
66
+ # @return [String, nil]
67
+ # @api public
68
+ # : () -> String?
69
+ def code_name: () -> String?
70
+
71
+ # Returns the 0-based active worksheet index from workbookView, or nil if not set.
72
+ #
73
+ # @return [Integer, nil]
74
+ # @api public
75
+ # : () -> Integer?
76
+ def active_sheet_index: () -> Integer?
77
+
78
+ # @deprecated Use {#active_sheet_index} or {#active_sheet} instead.
64
79
  # @return [Integer, nil]
65
80
  # @api public
66
81
  # : () -> Integer?
67
82
  def active_tab: () -> Integer?
68
83
 
69
- # Returns whether Excel is instructed to perform a full recalculation when loading the workbook.
84
+ # Returns the active worksheet in the workbook, or the first worksheet if not set.
70
85
  #
71
- # @return [Boolean]
86
+ # @return [Elements::Worksheet, StreamSheet, nil]
72
87
  # @api public
73
- # : () -> bool
74
- def full_calc_on_load?: () -> bool
88
+ # : () -> (Elements::Worksheet | StreamSheet)?
89
+ def active_sheet: () -> (Elements::Worksheet | StreamSheet)?
75
90
 
76
- alias full_calc_on_load full_calc_on_load?
77
-
78
- # Returns core document properties (e.g. title, creator, created), or an empty hash.
91
+ # Returns the index of the first sheet tab visible in the sheet tab scroll area.
79
92
  #
80
- # @return [Hash<Symbol, untyped>]
93
+ # @return [Integer, nil]
81
94
  # @api public
82
- # : () -> Hash[Symbol, untyped]
83
- def core_properties: () -> Hash[Symbol, untyped]
95
+ # : () -> Integer?
96
+ def first_sheet: () -> Integer?
84
97
 
85
- # Returns application properties (e.g. app_name, doc_security), or an empty hash.
98
+ # Returns whether sheet tabs are displayed in the workbook window.
86
99
  #
87
- # @return [Hash<Symbol, untyped>]
100
+ # @return [Boolean]
88
101
  # @api public
89
- # : () -> Hash[Symbol, untyped]
90
- def app_properties: () -> Hash[Symbol, untyped]
102
+ # : () -> bool
103
+ def show_sheet_tabs?: () -> bool
104
+
105
+ # @deprecated Use {#show_sheet_tabs?} instead. Will be removed in 0.2.0.
106
+ # : () -> bool
107
+ def show_sheet_tabs: () -> bool
91
108
 
92
- # Returns custom document properties as an array of property hashes, or an empty array.
109
+ # Returns the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
93
110
  #
94
- # @return [Array<Hash[Symbol, untyped]>]
111
+ # @return [Integer, nil]
95
112
  # @api public
96
- # : () -> Array[Hash[Symbol, untyped]]
97
- def custom_properties: () -> Array[Hash[Symbol, untyped]]
113
+ # : () -> Integer?
114
+ def tab_ratio: () -> Integer?
98
115
 
99
- # Returns workbook protection settings as a hash, or nil if unprotected.
116
+ # Returns whether Excel is instructed to perform a full recalculation when loading the workbook.
100
117
  #
101
- # @return [Hash[Symbol, untyped], nil]
118
+ # @return [Boolean]
102
119
  # @api public
103
- # : () -> Hash[Symbol, untyped]?
104
- def workbook_protection: () -> Hash[Symbol, untyped]?
120
+ # : () -> bool
121
+ def full_calc_on_load?: () -> bool
122
+
123
+ # @deprecated Use {#full_calc_on_load?} instead. Will be removed in 0.2.0.
124
+ # : () -> bool
125
+ def full_calc_on_load: () -> bool
105
126
 
106
127
  # Returns the defined name matching name (and optionally sheet), or nil.
107
128
  #
@@ -110,23 +131,24 @@ module Xlsxrb
110
131
  # wb.defined_name("Print_Area", sheet: "Sheet1")
111
132
  #
112
133
  # @param name [String] The defined name.
113
- # @param sheet [String, Integer, nil] Optional sheet name or 0-based index.
114
- # @return [Hash[Symbol, untyped], nil]
134
+ # @param sheet [String, Symbol, Integer, nil] Optional sheet name or 0-based index.
135
+ # @return [Elements::DefinedName, nil]
115
136
  # @api public
116
- # : (String name, ?sheet: (String | Integer)?) -> Hash[Symbol, untyped]?
117
- 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?
118
139
 
119
140
  # Returns the worksheet at the given 0-based index or by name.
120
141
  #
121
142
  # @example
122
143
  # wb.sheet(0)
123
144
  # wb.sheet("Sales")
145
+ # wb.sheet(:Sales)
124
146
  #
125
- # @param identifier [Integer, String, untyped] 0-based index or sheet name.
147
+ # @param identifier [Integer, String, Symbol, untyped] 0-based index or sheet name.
126
148
  # @return [Elements::Worksheet, StreamSheet, nil]
127
149
  # @api public
128
- # : (?Integer | String | untyped identifier) -> (Elements::Worksheet | StreamSheet)?
129
- 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)?
130
152
 
131
153
  alias [] sheet
132
154
 
@@ -157,19 +179,27 @@ module Xlsxrb
157
179
  # : (Integer | String | untyped sheet_identifier, String | Symbol | Integer ref_or_row, ?Integer? col) -> Array[Elements::Image]
158
180
  def images_at: (Integer | String | untyped sheet_identifier, String | Symbol | Integer ref_or_row, ?Integer? col) -> Array[Elements::Image]
159
181
 
182
+ # Internal load helper without deprecation warning.
183
+ # @api private
184
+ # : () -> Elements::Workbook
185
+ def _load: () -> Elements::Workbook
186
+
160
187
  # Loads all sheets into memory, returning an Elements::Workbook where every
161
188
  # worksheet is a fully-parsed Elements::Worksheet supporting coordinate random access.
162
189
  #
163
190
  # @example
164
- # wb = Xlsxrb.read("file.xlsx").load
191
+ # wb = Xlsxrb.load("file.xlsx")
165
192
  # puts wb["Sheet1"]["A1"].value
166
193
  #
194
+ # @deprecated Use {Xlsxrb.load} instead. Will be removed in 0.2.0.
167
195
  # @return [Elements::Workbook]
168
196
  # @api public
169
197
  # : () -> Elements::Workbook
170
198
  def load: () -> Elements::Workbook
171
199
 
172
- 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
173
203
 
174
204
  # Closes any streaming resources associated with worksheets.
175
205
  #
@@ -181,6 +211,7 @@ module Xlsxrb
181
211
  # Returns a new Workbook with the specified sheet updated.
182
212
  # Yields the matched worksheet to the block, which must return a new Worksheet.
183
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.
184
215
  # @example
185
216
  # new_wb = wb.update_sheet("Sheet1") do |sheet|
186
217
  # sheet.update_cell("A1", value: "New Title")
@@ -208,15 +239,32 @@ module Xlsxrb
208
239
  # wb.save("output.xlsx")
209
240
  #
210
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:`).
211
245
  # @return [void]
212
246
  # @api public
213
- # : (String | IO | StringIO filepath) -> void
214
- 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
215
262
 
216
263
  # Validates workbook structure according to OOXML specifications.
217
264
  #
218
265
  # @param sheets [Array<Elements::Worksheet>]
219
266
  # @return [Array<String>] List of error messages.
267
+ # @api private
220
268
  # : (untyped sheets) -> Array[String]
221
269
  def self.validate: (untyped sheets) -> Array[String]
222
270
  end