oxcel 0.1.0-x86_64-linux-musl
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +212 -0
- data/docs/MIGRATING_FROM_CAXLSX.md +120 -0
- data/docs/MIGRATING_FROM_ROO.md +99 -0
- data/lib/oxcel/3.3/oxcel.so +0 -0
- data/lib/oxcel/3.4/oxcel.so +0 -0
- data/lib/oxcel/4.0/oxcel.so +0 -0
- data/lib/oxcel/a1.rb +66 -0
- data/lib/oxcel/compat/caxlsx.rb +295 -0
- data/lib/oxcel/compat/roo.rb +294 -0
- data/lib/oxcel/configuration.rb +29 -0
- data/lib/oxcel/diff.rb +235 -0
- data/lib/oxcel/rails.rb +57 -0
- data/lib/oxcel/reader.rb +135 -0
- data/lib/oxcel/resource.rb +317 -0
- data/lib/oxcel/sheet.rb +188 -0
- data/lib/oxcel/types.rb +130 -0
- data/lib/oxcel/version.rb +5 -0
- data/lib/oxcel/workbook.rb +50 -0
- data/lib/oxcel.rb +169 -0
- data/rbi/oxcel.rbi +1144 -0
- data/sig/oxcel.rbs +404 -0
- data/skills/oxcel/SKILL.md +152 -0
- metadata +75 -0
data/sig/oxcel.rbs
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
module Oxcel
|
|
2
|
+
VERSION: String
|
|
3
|
+
|
|
4
|
+
type cell_value = String | Integer | Float | bool | Date | Time | nil
|
|
5
|
+
type sheet_selector = String | Symbol | Integer | nil
|
|
6
|
+
type format_option = String | Symbol | nil
|
|
7
|
+
type style_option = Style | Hash[Symbol | String, untyped] | nil
|
|
8
|
+
type path_or_io = String | _ToPath | _Read | untyped
|
|
9
|
+
|
|
10
|
+
interface _ToPath
|
|
11
|
+
def to_path: () -> String
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
interface _Read
|
|
15
|
+
def read: () -> String
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class Error < StandardError
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class FileError < Error
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class ClosedWorkbookError < Error
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Configuration
|
|
28
|
+
attr_accessor coerce_integers: bool
|
|
29
|
+
attr_accessor constant_memory: bool
|
|
30
|
+
attr_accessor default_date_format: String
|
|
31
|
+
attr_accessor default_datetime_format: String
|
|
32
|
+
|
|
33
|
+
def initialize: () -> void
|
|
34
|
+
def inspect: () -> String
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
module A1
|
|
38
|
+
def self.col_to_letters: (Integer index) -> String
|
|
39
|
+
def self.letters_to_col: (String | Symbol letters) -> Integer
|
|
40
|
+
def self.format_cell: (Integer row, Integer col) -> String
|
|
41
|
+
def self.parse_cell: (String ref) -> [Integer, Integer]
|
|
42
|
+
def self.parse_range: (String range_str) -> [Integer, Integer, Integer, Integer]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Formula
|
|
46
|
+
attr_reader expression: String
|
|
47
|
+
|
|
48
|
+
def initialize: (untyped expression) -> void
|
|
49
|
+
def _oxcel_formula: () -> String
|
|
50
|
+
def to_s: () -> String
|
|
51
|
+
def ==: (untyped other) -> bool
|
|
52
|
+
alias eql? ==
|
|
53
|
+
def hash: () -> Integer
|
|
54
|
+
def inspect: () -> String
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class Hyperlink
|
|
58
|
+
attr_reader url: String
|
|
59
|
+
attr_reader text: String?
|
|
60
|
+
|
|
61
|
+
def initialize: (untyped url, ?untyped text) -> void
|
|
62
|
+
def _oxcel_url: () -> String
|
|
63
|
+
def _oxcel_text: () -> String?
|
|
64
|
+
def ==: (untyped other) -> bool
|
|
65
|
+
alias eql? ==
|
|
66
|
+
def hash: () -> Integer
|
|
67
|
+
def inspect: () -> String
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class Cell
|
|
71
|
+
attr_reader value: untyped
|
|
72
|
+
attr_reader style: Style?
|
|
73
|
+
|
|
74
|
+
def initialize: (untyped value, ?style: Style?) -> void
|
|
75
|
+
def _oxcel_cell_value: () -> untyped
|
|
76
|
+
def _oxcel_cell_style_id: () -> Integer?
|
|
77
|
+
def ==: (untyped other) -> bool
|
|
78
|
+
alias eql? ==
|
|
79
|
+
def hash: () -> Integer
|
|
80
|
+
def inspect: () -> String
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class Style
|
|
84
|
+
attr_reader id: Integer
|
|
85
|
+
attr_reader workbook: Workbook?
|
|
86
|
+
|
|
87
|
+
def initialize: (Integer id, ?Workbook? workbook) -> void
|
|
88
|
+
def ==: (untyped other) -> bool
|
|
89
|
+
alias eql? ==
|
|
90
|
+
def hash: () -> Integer
|
|
91
|
+
def inspect: () -> String
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class Reader
|
|
95
|
+
include Enumerable[Array[cell_value]]
|
|
96
|
+
|
|
97
|
+
attr_reader path: String?
|
|
98
|
+
|
|
99
|
+
def self.from_bytes: (String bytes, ?format: format_option) -> Reader
|
|
100
|
+
|
|
101
|
+
def initialize: (path_or_io path_or_io, ?format: format_option) -> void
|
|
102
|
+
def close: () -> nil
|
|
103
|
+
def closed?: () -> bool
|
|
104
|
+
def sheet_names: () -> Array[String]
|
|
105
|
+
def sheets_metadata: () -> Array[Hash[Symbol, untyped]]
|
|
106
|
+
def dimensions: (?sheet_selector sheet) -> [Integer, Integer]?
|
|
107
|
+
def merged_regions: (?sheet_selector sheet) -> Array[[Integer, Integer, Integer, Integer]]
|
|
108
|
+
def formulas: (?sheet_selector sheet) -> Hash[[Integer, Integer], String]
|
|
109
|
+
def read: (?sheet_selector sheet, ?coerce_integers: bool?) -> Array[Array[cell_value]]
|
|
110
|
+
def each_row: (?sheet_selector sheet, ?coerce_integers: bool?, ?skip_empty: bool) { (Array[cell_value]) -> void } -> nil
|
|
111
|
+
| (?sheet_selector sheet, ?coerce_integers: bool?, ?skip_empty: bool) -> Enumerator[Array[cell_value], nil]
|
|
112
|
+
alias each each_row
|
|
113
|
+
def each_hash: (?sheet_selector sheet, ?headers: Array[untyped]?, ?coerce_integers: bool?, ?symbolize_keys: bool, ?skip_empty: bool) { (Hash[String | Symbol, cell_value]) -> void } -> nil
|
|
114
|
+
| (?sheet_selector sheet, ?headers: Array[untyped]?, ?coerce_integers: bool?, ?symbolize_keys: bool, ?skip_empty: bool) -> Enumerator[Hash[String | Symbol, cell_value], nil]
|
|
115
|
+
def inspect: () -> String
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class Sheet
|
|
119
|
+
BATCH_SIZE: Integer
|
|
120
|
+
|
|
121
|
+
attr_reader name: String
|
|
122
|
+
attr_reader row_count: Integer
|
|
123
|
+
|
|
124
|
+
def add_row: (Array[untyped] values, ?style: style_option, ?styles: Array[style_option]?) -> self
|
|
125
|
+
alias << add_row
|
|
126
|
+
def add_rows: (Enumerable[Array[untyped]] enum, ?style: style_option, ?styles: Array[style_option]?) -> self
|
|
127
|
+
def stream: (Enumerable[untyped] enum, ?style: style_option, ?styles: Array[style_option]?) ?{ (untyped) -> Array[untyped] } -> self
|
|
128
|
+
def write_cell: (Integer row, Integer col, untyped value, ?style: style_option) -> self
|
|
129
|
+
def merge_range: (Integer first_row, Integer first_col, Integer last_row, Integer last_col, ?untyped text, ?style: style_option) -> self
|
|
130
|
+
def autofilter: (Integer first_row, Integer first_col, Integer last_row, Integer last_col) -> self
|
|
131
|
+
def column_width: (Integer col, Numeric width) -> self
|
|
132
|
+
def column_widths: (*(Numeric | nil) widths) -> self
|
|
133
|
+
def row_height: (Integer row, Numeric height) -> self
|
|
134
|
+
def freeze_panes: (Integer row, ?Integer col) -> self
|
|
135
|
+
def autofit: () -> self
|
|
136
|
+
def tab_color: (String hex) -> self
|
|
137
|
+
def gridlines: (bool visible) -> self
|
|
138
|
+
def protect: (?password: String?) -> self
|
|
139
|
+
def add_note: (Integer row, Integer col, String text) -> self
|
|
140
|
+
def add_dropdown: (Integer first_row, Integer first_col, Integer last_row, Integer last_col, Array[untyped] values, ?input_title: String?, ?input_message: String?, ?error_message: String?) -> self
|
|
141
|
+
def page_setup: (**untyped options) -> self
|
|
142
|
+
def inspect: () -> String
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
class Workbook
|
|
146
|
+
def initialize: (?constant_memory: bool?, ?default_date_format: String?, ?default_datetime_format: String?) -> void
|
|
147
|
+
def closed?: () -> bool
|
|
148
|
+
def add_style: (**untyped options) -> Style
|
|
149
|
+
def add_sheet: (?String | Symbol name, ?constant_memory: bool) ?{ (Sheet) -> void } -> Sheet
|
|
150
|
+
def save: (String | _ToPath path) -> void
|
|
151
|
+
def to_bytes: () -> String
|
|
152
|
+
def inspect: () -> String
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
module Resource
|
|
156
|
+
STYLE_KEYS: Array[Symbol]
|
|
157
|
+
|
|
158
|
+
class ColumnDef
|
|
159
|
+
attr_reader name: Symbol
|
|
160
|
+
attr_reader header: String
|
|
161
|
+
attr_reader width: Numeric?
|
|
162
|
+
attr_reader style_options: Hash[Symbol, untyped]?
|
|
163
|
+
attr_reader condition: Proc?
|
|
164
|
+
attr_reader extractor: Proc?
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
class Config
|
|
168
|
+
attr_accessor columns: Array[ColumnDef]
|
|
169
|
+
attr_accessor sheet_name: String?
|
|
170
|
+
attr_accessor constant_memory: bool
|
|
171
|
+
attr_accessor freeze_header: bool
|
|
172
|
+
attr_accessor autofilter: bool
|
|
173
|
+
attr_accessor include_header: bool
|
|
174
|
+
attr_accessor header_style: Hash[Symbol, untyped]?
|
|
175
|
+
attr_accessor header_height: Float?
|
|
176
|
+
attr_accessor page_setup: Hash[Symbol, untyped]?
|
|
177
|
+
attr_accessor tab_color: String?
|
|
178
|
+
attr_accessor after_write_hooks: Array[Proc]
|
|
179
|
+
|
|
180
|
+
def deep_copy: () -> Config
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
module ClassMethods
|
|
184
|
+
def _oxcel_config: () -> Config
|
|
185
|
+
def _oxcel_columns: () -> Array[ColumnDef]
|
|
186
|
+
def sheet_name: (?String | Symbol | nil name) -> String
|
|
187
|
+
def constant_memory: (?bool? enabled) -> bool
|
|
188
|
+
def freeze_header: (?bool? enabled) -> bool
|
|
189
|
+
def autofilter: (?bool? enabled) -> bool
|
|
190
|
+
def include_header: (?bool? enabled) -> bool
|
|
191
|
+
def header_style: (**untyped options) -> Hash[Symbol, untyped]?
|
|
192
|
+
def header_height: (?Numeric? height) -> Float?
|
|
193
|
+
def page_setup: (**untyped options) -> Hash[Symbol, untyped]?
|
|
194
|
+
def tab_color: (?String? hex) -> String?
|
|
195
|
+
def column: (Symbol | String name, ?header: String?, ?width: Numeric?, ?style: Hash[Symbol, untyped]?, ?if: Proc?, **untyped inline_style) ?{ (*untyped) -> untyped } -> void
|
|
196
|
+
def columns: (*(Symbol | String) names, **untyped shared_options) -> void
|
|
197
|
+
def after_write: () { (*untyped) -> void } -> void
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
attr_reader records: Enumerable[untyped]
|
|
201
|
+
attr_reader params: Hash[untyped, untyped]
|
|
202
|
+
|
|
203
|
+
def initialize: (Enumerable[untyped] records, ?params: Hash[untyped, untyped], ?sheet_name: String | Symbol | nil, ?constant_memory: bool?) -> void
|
|
204
|
+
def write_to: (Workbook workbook) -> Sheet
|
|
205
|
+
def save: (String | _ToPath path) -> (String | _ToPath)
|
|
206
|
+
alias to_file save
|
|
207
|
+
def to_bytes: () -> String
|
|
208
|
+
def inspect: () -> String
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
class CellDiff
|
|
212
|
+
attr_reader sheet: String
|
|
213
|
+
attr_reader row: Integer
|
|
214
|
+
attr_reader col: Integer
|
|
215
|
+
attr_reader left: untyped
|
|
216
|
+
attr_reader right: untyped
|
|
217
|
+
|
|
218
|
+
def initialize: (sheet: String, row: Integer, col: Integer, left: untyped, right: untyped) -> void
|
|
219
|
+
def cell_ref: () -> String
|
|
220
|
+
def ==: (untyped other) -> bool
|
|
221
|
+
alias eql? ==
|
|
222
|
+
def hash: () -> Integer
|
|
223
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
224
|
+
def to_s: () -> String
|
|
225
|
+
def inspect: () -> String
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
class DiffResult
|
|
229
|
+
attr_reader left_sheets: Array[String]
|
|
230
|
+
attr_reader right_sheets: Array[String]
|
|
231
|
+
attr_reader differences: Array[CellDiff]
|
|
232
|
+
attr_reader truncated: bool
|
|
233
|
+
|
|
234
|
+
def initialize: (left_sheets: Array[String], right_sheets: Array[String], differences: Array[CellDiff], ?truncated: bool, ?sheet_names_matched: bool?) -> void
|
|
235
|
+
def sheet_names_match?: () -> bool
|
|
236
|
+
def identical?: () -> bool
|
|
237
|
+
def different?: () -> bool
|
|
238
|
+
def truncated?: () -> bool
|
|
239
|
+
def summary: () -> String
|
|
240
|
+
def to_s: () -> String
|
|
241
|
+
def inspect: () -> String
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
module Diff
|
|
245
|
+
def self.compare: (
|
|
246
|
+
path_or_io | Reader left,
|
|
247
|
+
path_or_io | Reader right,
|
|
248
|
+
?sheets: String | Symbol | Array[String | Symbol] | nil,
|
|
249
|
+
?format_left: format_option,
|
|
250
|
+
?format_right: format_option,
|
|
251
|
+
?tolerance: Numeric,
|
|
252
|
+
?ignore_trailing_nils: bool,
|
|
253
|
+
?coerce_integers: bool,
|
|
254
|
+
?max_diffs: Integer?
|
|
255
|
+
) -> DiffResult
|
|
256
|
+
|
|
257
|
+
def self.col_index_to_letters: (Integer index) -> String
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
module Rails
|
|
261
|
+
MIME_TYPE: String
|
|
262
|
+
|
|
263
|
+
def self.install!: () -> void
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
module Compat
|
|
267
|
+
module Roo
|
|
268
|
+
class Cell
|
|
269
|
+
attr_reader value: untyped
|
|
270
|
+
attr_reader coordinate: [Integer, Integer]?
|
|
271
|
+
|
|
272
|
+
def initialize: (untyped value, ?coordinate: [Integer, Integer]?) -> void
|
|
273
|
+
def empty?: () -> bool
|
|
274
|
+
def to_s: () -> String
|
|
275
|
+
def ==: (untyped other) -> bool
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
class Sheet
|
|
279
|
+
attr_reader name: String
|
|
280
|
+
|
|
281
|
+
def first_row: () -> Integer?
|
|
282
|
+
def last_row: () -> Integer?
|
|
283
|
+
def first_column: () -> Integer?
|
|
284
|
+
def last_column: () -> Integer?
|
|
285
|
+
def row: (Integer row_number) -> Array[cell_value]
|
|
286
|
+
def cell: (Integer row_number, Integer | String | Symbol col) -> cell_value
|
|
287
|
+
def each_row_streaming: (?offset: Integer, ?max_rows: Integer?, ?pad_cells: bool) { (Array[Cell]) -> void } -> nil
|
|
288
|
+
| (?offset: Integer, ?max_rows: Integer?, ?pad_cells: bool) -> Enumerator[Array[Cell], nil]
|
|
289
|
+
def parse: (?Hash[untyped, untyped] options) -> Array[untyped]
|
|
290
|
+
def each: (?Hash[untyped, untyped]? headers) { (untyped) -> void } -> nil
|
|
291
|
+
| (?Hash[untyped, untyped]? headers) -> Enumerator[untyped, nil]
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
class Excelx
|
|
295
|
+
attr_reader default_sheet: String?
|
|
296
|
+
|
|
297
|
+
def initialize: (path_or_io path_or_io, ?file_warning: Symbol, ?extension: format_option, ?coerce_integers: bool) -> void
|
|
298
|
+
def default_sheet=: (String | Symbol name) -> String
|
|
299
|
+
def sheets: () -> Array[String]
|
|
300
|
+
def sheet: (Integer | String | Symbol index_or_name) -> Sheet
|
|
301
|
+
def first_row: () -> Integer?
|
|
302
|
+
def last_row: () -> Integer?
|
|
303
|
+
def first_column: () -> Integer?
|
|
304
|
+
def last_column: () -> Integer?
|
|
305
|
+
def row: (Integer row_number) -> Array[cell_value]
|
|
306
|
+
def cell: (Integer row_number, Integer | String | Symbol col) -> cell_value
|
|
307
|
+
def each_row_streaming: (?offset: Integer, ?max_rows: Integer?, ?pad_cells: bool) { (Array[Cell]) -> void } -> nil
|
|
308
|
+
| (?offset: Integer, ?max_rows: Integer?, ?pad_cells: bool) -> Enumerator[Array[Cell], nil]
|
|
309
|
+
def parse: (?Hash[untyped, untyped] options) -> Array[untyped]
|
|
310
|
+
def each: (?Hash[untyped, untyped]? headers) { (untyped) -> void } -> nil
|
|
311
|
+
| (?Hash[untyped, untyped]? headers) -> Enumerator[untyped, nil]
|
|
312
|
+
def close: () -> nil
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
module Spreadsheet
|
|
316
|
+
def self.open: (path_or_io path_or_io, ?Hash[untyped, untyped] options) -> Excelx
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
module Caxlsx
|
|
321
|
+
module A1Ref
|
|
322
|
+
def self.parse_cell: (String ref) -> [Integer, Integer]
|
|
323
|
+
def self.parse_range: (String range_str) -> [Integer, Integer, Integer, Integer]
|
|
324
|
+
def self.normalize_color: (String? hex) -> String?
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
class Styles
|
|
328
|
+
def add_style: (**untyped options) -> Style
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
class Pane
|
|
332
|
+
attr_accessor state: Symbol?
|
|
333
|
+
attr_accessor x_split: Integer
|
|
334
|
+
attr_accessor y_split: Integer
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
class SheetView
|
|
338
|
+
def pane: () ?{ (Pane) -> void } -> Pane
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
class Worksheet
|
|
342
|
+
attr_reader name: String
|
|
343
|
+
|
|
344
|
+
def row_count: () -> Integer
|
|
345
|
+
def add_row: (?Array[untyped] values, ?style: untyped, ?types: Symbol | Array[Symbol?] | nil, ?height: Numeric?) -> self
|
|
346
|
+
def column_widths: (*(Numeric | nil) widths) -> self
|
|
347
|
+
def merge_cells: (String range_str, ?untyped text, ?style: style_option) -> self
|
|
348
|
+
def auto_filter=: (String range_str) -> String
|
|
349
|
+
def sheet_view: () -> SheetView
|
|
350
|
+
def add_comment: (ref: String, text: String, ?author: String?) -> self
|
|
351
|
+
def add_data_validation: (String range_str, ?Hash[Symbol, untyped] opts) -> self
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
class Workbook
|
|
355
|
+
attr_reader worksheets: Array[Worksheet]
|
|
356
|
+
|
|
357
|
+
def styles: () ?{ (Styles) -> void } -> Styles
|
|
358
|
+
def add_worksheet: (?name: String | Symbol, ?constant_memory: bool) ?{ (Worksheet) -> void } -> Worksheet
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
class Package
|
|
362
|
+
attr_accessor use_shared_strings: bool
|
|
363
|
+
attr_accessor use_autowidth: bool
|
|
364
|
+
attr_reader workbook: Workbook
|
|
365
|
+
|
|
366
|
+
def initialize: (?constant_memory: bool) -> void
|
|
367
|
+
def serialize: (String | _ToPath path) -> bool
|
|
368
|
+
def to_stream: () -> untyped
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def self.config: () -> Configuration
|
|
374
|
+
alias self.configuration self.config
|
|
375
|
+
def self.configure: () ?{ (Configuration) -> void } -> Configuration
|
|
376
|
+
def self.reset_config!: () -> Configuration
|
|
377
|
+
alias self.reset_configuration! self.reset_config!
|
|
378
|
+
def self.open: [U] (path_or_io path_or_io, ?format: format_option) { (Reader) -> U } -> U
|
|
379
|
+
| (path_or_io path_or_io, ?format: format_option) -> Reader
|
|
380
|
+
def self.open_bytes: [U] (String bytes, ?format: format_option) { (Reader) -> U } -> U
|
|
381
|
+
| (String bytes, ?format: format_option) -> Reader
|
|
382
|
+
def self.sheet_names: (path_or_io path_or_io, ?format: format_option) -> Array[String]
|
|
383
|
+
def self.read: (path_or_io path_or_io, ?sheet: sheet_selector, ?format: format_option, ?coerce_integers: bool?) -> Array[Array[cell_value]]
|
|
384
|
+
def self.each_row: (path_or_io path_or_io, ?sheet: sheet_selector, ?format: format_option, ?coerce_integers: bool?, ?skip_empty: bool) { (Array[cell_value]) -> void } -> nil
|
|
385
|
+
| (path_or_io path_or_io, ?sheet: sheet_selector, ?format: format_option, ?coerce_integers: bool?, ?skip_empty: bool) -> Enumerator[Array[cell_value], nil]
|
|
386
|
+
def self.each_hash: (path_or_io path_or_io, ?sheet: sheet_selector, ?format: format_option, ?headers: Array[untyped]?, ?coerce_integers: bool?, ?symbolize_keys: bool, ?skip_empty: bool) { (Hash[String | Symbol, cell_value]) -> void } -> nil
|
|
387
|
+
| (path_or_io path_or_io, ?sheet: sheet_selector, ?format: format_option, ?headers: Array[untyped]?, ?coerce_integers: bool?, ?symbolize_keys: bool, ?skip_empty: bool) -> Enumerator[Hash[String | Symbol, cell_value], nil]
|
|
388
|
+
def self.write: (String | _ToPath path, ?constant_memory: bool?) ?{ (Workbook) -> void } -> (String | _ToPath)
|
|
389
|
+
def self.to_bytes: (?constant_memory: bool?) ?{ (Workbook) -> void } -> String
|
|
390
|
+
def self.formula: (untyped expression) -> Formula
|
|
391
|
+
def self.link: (untyped url, ?untyped text) -> Hyperlink
|
|
392
|
+
def self.cell: (untyped value, ?style: Style?) -> Cell
|
|
393
|
+
def self.diff: (
|
|
394
|
+
path_or_io | Reader left,
|
|
395
|
+
path_or_io | Reader right,
|
|
396
|
+
?sheets: String | Symbol | Array[String | Symbol] | nil,
|
|
397
|
+
?format_left: format_option,
|
|
398
|
+
?format_right: format_option,
|
|
399
|
+
?tolerance: Numeric,
|
|
400
|
+
?ignore_trailing_nils: bool,
|
|
401
|
+
?coerce_integers: bool,
|
|
402
|
+
?max_diffs: Integer?
|
|
403
|
+
) -> DiffResult
|
|
404
|
+
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: oxcel
|
|
3
|
+
description: Use, configure, and migrate Ruby/Rails apps to `oxcel` (unified Rust-backed Excel reader & writer using `calamine` + `rust_xlsxwriter`). Covers `Oxcel::Resource` declarative exports, O(1) streaming reads (`each_row` / `each_hash`), B2B formatting, Rails `render xlsx:`, migrating from `caxlsx` / `roo` with `Oxcel::Compat` + `Oxcel.diff`, and Sorbet/Tapioca (`rbi/`) + RBS (`sig/`) type integration.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# oxcel
|
|
7
|
+
|
|
8
|
+
Unified Rust-backed Excel (`.xlsx`, `.xlsm`, `.xlsb`, `.xls`, `.ods`) reader and writer for Ruby 3.2+ and Rails 7/8+.
|
|
9
|
+
|
|
10
|
+
## When to Use Which API
|
|
11
|
+
|
|
12
|
+
| Task | Preferred API | Why |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| Export ActiveRecord / domain models to `.xlsx` | `Oxcel::Resource` | Declarative Alba-style DSL, pre-compiled extractors, batched 1,024-row FFI, `constant_memory: true` (~30 MB flat RSS) |
|
|
15
|
+
| Custom multi-sheet / B2B report (merges, notes, dropdowns, page setup) | `Oxcel.write` / `Oxcel.to_bytes` | Full control over `Workbook`, `Style`, `Sheet`, `Oxcel.formula`, `Oxcel.link`, `Oxcel.cell` |
|
|
16
|
+
| Stream large `.xlsx` files without loading into RAM | `Oxcel.each_row` / `Oxcel.each_hash` | True O(1) Rust streaming (`XlsxCellReader`); supports lazy `.first(N)` early exit |
|
|
17
|
+
| Inspect metadata (sheets, dimensions, merged ranges, formulas) | `Oxcel.open` / `Oxcel.open_bytes` | Works on file paths, `Pathname`, `IO`, `StringIO`, `Tempfile`, raw bytes (magic-byte format detection) |
|
|
18
|
+
| Rails controller download | `require "oxcel/rails"` + `render xlsx:` | Registers `:xlsx` MIME type and `ActionController` renderer with RFC 5987 filename support |
|
|
19
|
+
| Incremental migration from `caxlsx` | `require "oxcel/compat/caxlsx"` | Drop-in `Oxcel::Compat::Caxlsx::Package` + `Oxcel.diff` parity verification |
|
|
20
|
+
| Incremental migration from `roo` | `require "oxcel/compat/roo"` | Drop-in 1-indexed `Oxcel::Compat::Roo::Excelx` / `Spreadsheet.open` |
|
|
21
|
+
|
|
22
|
+
## Core Usage Patterns
|
|
23
|
+
|
|
24
|
+
### 1. Declarative Export (`Oxcel::Resource`)
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
class OrderExporter
|
|
28
|
+
include Oxcel::Resource
|
|
29
|
+
|
|
30
|
+
sheet_name "Orders"
|
|
31
|
+
constant_memory true
|
|
32
|
+
freeze_header true
|
|
33
|
+
autofilter true
|
|
34
|
+
header_height 24
|
|
35
|
+
header_style bold: true, bg_color: "#1F4E78", font_color: "#FFFFFF", align: :center
|
|
36
|
+
page_setup orientation: :landscape, paper_size: :a4, fit_to_pages: [1, 0], repeat_rows: [0, 0]
|
|
37
|
+
|
|
38
|
+
column :id, header: "ID", width: 10
|
|
39
|
+
column :customer, header: "顧客名", width: 24 do |order|
|
|
40
|
+
order.customer_name
|
|
41
|
+
end
|
|
42
|
+
column :amount, header: "金額", width: 14, num_format: "#,##0", align: :right
|
|
43
|
+
column :ordered_on, header: "注文日", width: 14, num_format: "yyyy/mm/dd"
|
|
44
|
+
column :internal, header: "内部", if: ->(params) { params[:admin] }
|
|
45
|
+
|
|
46
|
+
after_write do |sheet|
|
|
47
|
+
sheet.add_row(["合計", nil, Oxcel.formula("=SUM(C2:C#{sheet.row_count})")])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Or shorthand for plain attributes: `columns :id, :name, :email`
|
|
52
|
+
OrderExporter.new(Order.find_each, params: { admin: true }).save("orders.xlsx")
|
|
53
|
+
bytes = OrderExporter.new(Order.find_each).to_bytes
|
|
54
|
+
|
|
55
|
+
# Multi-sheet composition:
|
|
56
|
+
Oxcel.write("report.xlsx", constant_memory: true) do |wb|
|
|
57
|
+
OrderExporter.new(Order.find_each).write_to(wb)
|
|
58
|
+
SummaryExporter.new(summaries).write_to(wb)
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 2. O(1) Streaming Read & Global Configuration
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
# Optional app-wide defaults (e.g. config/initializers/oxcel.rb)
|
|
66
|
+
Oxcel.configure do |config|
|
|
67
|
+
config.coerce_integers = true
|
|
68
|
+
config.default_date_format = "yyyy/mm/dd"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Lazy O(1) streaming — stops parsing after 10 rows
|
|
72
|
+
preview = Oxcel.each_row("huge.xlsx", coerce_integers: true).first(10)
|
|
73
|
+
|
|
74
|
+
# Hash streaming with symbolized keys
|
|
75
|
+
Oxcel.each_hash("orders.xlsx", coerce_integers: true, symbolize_keys: true) do |row|
|
|
76
|
+
# Values are native Ruby String, Integer, Float, Date, Time (UTC), Boolean, or nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Extensionless Tempfile / UploadedFile / ActiveStorage blob bytes
|
|
80
|
+
# Block form auto-closes the underlying file handle via `ensure reader.close`
|
|
81
|
+
Oxcel.open_bytes(blob.download) do |reader|
|
|
82
|
+
reader.sheet_names
|
|
83
|
+
reader.sheets_metadata # [{ name:, visibility:, type: }]
|
|
84
|
+
reader.dimensions(0) # [rows, cols]
|
|
85
|
+
reader.merged_regions(0)
|
|
86
|
+
reader.formulas(0) # { [row, col] => "SUM(C2:C10)" }
|
|
87
|
+
reader.first(5) # Reader includes Enumerable
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. Procedural Writer & B2B Features
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
Oxcel.write("invoice.xlsx", constant_memory: false) do |wb|
|
|
95
|
+
hdr = wb.add_style(bold: true, bg_color: "#1F4E78", font_color: "#FFFFFF", border_bottom: :double)
|
|
96
|
+
money = wb.add_style(num_format: "#,##0", align: :right)
|
|
97
|
+
|
|
98
|
+
wb.add_sheet("請求書") do |s|
|
|
99
|
+
s.tab_color("#1F4E78")
|
|
100
|
+
s.page_setup(orientation: :landscape, paper_size: :a4, fit_to_pages: [1, 0])
|
|
101
|
+
s.merge_range(0, 0, 0, 2, "御請求書", style: hdr)
|
|
102
|
+
s.add_row(%w[品目 金額 リンク], style: hdr)
|
|
103
|
+
s.add_row(["保守費用", 50_000, Oxcel.link("https://example.com", "詳細")], styles: [nil, money, nil])
|
|
104
|
+
s.add_row(["合計", Oxcel.cell(Oxcel.formula("=SUM(B3:B3)"), style: money), nil])
|
|
105
|
+
s.add_note(2, 0, "月末締め")
|
|
106
|
+
s.add_dropdown(2, 0, 20, 0, %w[保守費用 開発費用])
|
|
107
|
+
s.freeze_panes(2, 0)
|
|
108
|
+
s.protect(password: "secret")
|
|
109
|
+
s.autofit
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 4. Rails Integration
|
|
115
|
+
|
|
116
|
+
Rails Railtie is auto-registered when Rails is loaded (no manual `require "oxcel/rails"` needed):
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
class OrdersController < ApplicationController
|
|
120
|
+
def export
|
|
121
|
+
render xlsx: OrderExporter.new(Order.find_each), filename: "orders.xlsx"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 5. Migration Workflow (`caxlsx` / `roo` -> `oxcel`)
|
|
127
|
+
|
|
128
|
+
1. Start with the lazy-loaded (`autoload`) compatibility adapter for minimal diff first:
|
|
129
|
+
- `Oxcel::Compat::Caxlsx::Package` (or explicit `require "oxcel/compat/caxlsx"`)
|
|
130
|
+
- `Oxcel::Compat::Roo::Excelx` / `Spreadsheet` (or explicit `require "oxcel/compat/roo"`)
|
|
131
|
+
2. Verify output parity in tests or shadow runs using O(1) streaming diff:
|
|
132
|
+
```ruby
|
|
133
|
+
diff = Oxcel.diff("before.xlsx", "after.xlsx", tolerance: 1e-9)
|
|
134
|
+
raise diff.to_s if diff.different?
|
|
135
|
+
```
|
|
136
|
+
3. Refactor hot paths to native `Oxcel::Resource` / `Oxcel.each_row`.
|
|
137
|
+
|
|
138
|
+
See [docs/MIGRATING_FROM_CAXLSX.md](../../docs/MIGRATING_FROM_CAXLSX.md) and [docs/MIGRATING_FROM_ROO.md](../../docs/MIGRATING_FROM_ROO.md) for full API tables.
|
|
139
|
+
|
|
140
|
+
## Type Checking (Sorbet / Tapioca & RBS)
|
|
141
|
+
|
|
142
|
+
- **Sorbet / Tapioca**: `oxcel` bundles `rbi/oxcel.rbi`. Running `bin/tapioca gem oxcel` imports full strict signatures automatically (including `mixes_in_class_methods` for `Oxcel::Resource` subclasses, `Oxcel.diff`, and `Oxcel::Compat::*`). No `sorbet-runtime` dependency is added.
|
|
143
|
+
- **RBS / Steep / Ruby LSP**: `oxcel` bundles `sig/oxcel.rbs` covering the full public API.
|
|
144
|
+
|
|
145
|
+
## Common Pitfalls & Rules
|
|
146
|
+
|
|
147
|
+
1. **`constant_memory: true` limitations**: Rows are flushed sequentially. Do **not** call `autofit`, write out-of-order rows, or call `merge_range` / `add_note` on already-flushed rows when `constant_memory: true`. Use `constant_memory: false` for richly formatted small/medium reports, and `constant_memory: true` for large tabular exports (10k–1M+ rows).
|
|
148
|
+
2. **0-indexed native coordinates**: All native `Oxcel::Sheet` & `Oxcel::Reader` coordinates (`row`, `col`, `merge_range`, `autofilter`, `formulas`, `merged_regions`) are **0-indexed**. Only `Oxcel::Compat::Roo` uses 1-indexed rows/columns.
|
|
149
|
+
3. **Always pass `coerce_integers: true` when reading IDs/counts**: Excel stores numbers as floats; `coerce_integers: true` converts exact whole numbers (`42.0`) to Ruby `Integer` (`42`).
|
|
150
|
+
4. **Hex colors**: Native `add_style` / `tab_color` requires `"#RRGGBB"` or `"#RGB"` (leading `#`).
|
|
151
|
+
5. **Cross-workbook styles**: An `Oxcel::Style` belongs to the `Oxcel::Workbook` that created it; reusing it on another workbook raises `ArgumentError`.
|
|
152
|
+
6. **Errors**: Rescue `Oxcel::FileError` (corrupt/unreadable/unwritable file), `Oxcel::ClosedWorkbookError` (mutating after `save`/`to_bytes`), or base `Oxcel::Error < StandardError`.
|
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: oxcel
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: x86_64-linux-musl
|
|
6
|
+
authors:
|
|
7
|
+
- ken3ypa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-12-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Unified Rust-backed spreadsheet gem combining calamine (streaming reader)
|
|
14
|
+
and rust_xlsxwriter (constant-memory writer) with Rails ergonomics.
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE.txt
|
|
22
|
+
- README.md
|
|
23
|
+
- docs/MIGRATING_FROM_CAXLSX.md
|
|
24
|
+
- docs/MIGRATING_FROM_ROO.md
|
|
25
|
+
- lib/oxcel.rb
|
|
26
|
+
- lib/oxcel/3.3/oxcel.so
|
|
27
|
+
- lib/oxcel/3.4/oxcel.so
|
|
28
|
+
- lib/oxcel/4.0/oxcel.so
|
|
29
|
+
- lib/oxcel/a1.rb
|
|
30
|
+
- lib/oxcel/compat/caxlsx.rb
|
|
31
|
+
- lib/oxcel/compat/roo.rb
|
|
32
|
+
- lib/oxcel/configuration.rb
|
|
33
|
+
- lib/oxcel/diff.rb
|
|
34
|
+
- lib/oxcel/rails.rb
|
|
35
|
+
- lib/oxcel/reader.rb
|
|
36
|
+
- lib/oxcel/resource.rb
|
|
37
|
+
- lib/oxcel/sheet.rb
|
|
38
|
+
- lib/oxcel/types.rb
|
|
39
|
+
- lib/oxcel/version.rb
|
|
40
|
+
- lib/oxcel/workbook.rb
|
|
41
|
+
- rbi/oxcel.rbi
|
|
42
|
+
- sig/oxcel.rbs
|
|
43
|
+
- skills/oxcel/SKILL.md
|
|
44
|
+
homepage: https://github.com/ken3ypa/oxcel
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata:
|
|
48
|
+
source_code_uri: https://github.com/ken3ypa/oxcel
|
|
49
|
+
changelog_uri: https://github.com/ken3ypa/oxcel/blob/main/CHANGELOG.md
|
|
50
|
+
bug_tracker_uri: https://github.com/ken3ypa/oxcel/issues
|
|
51
|
+
rubygems_mfa_required: 'true'
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options: []
|
|
54
|
+
require_paths:
|
|
55
|
+
- lib
|
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.3'
|
|
61
|
+
- - "<"
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: 4.1.dev
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 3.3.22
|
|
69
|
+
requirements: []
|
|
70
|
+
rubygems_version: 3.5.23
|
|
71
|
+
signing_key:
|
|
72
|
+
specification_version: 4
|
|
73
|
+
summary: Blazing-fast, low-memory Excel (XLSX/XLS/XLSB/ODS) reader & writer for Ruby
|
|
74
|
+
powered by Rust
|
|
75
|
+
test_files: []
|