rbxl 1.5.0 → 1.6.0
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 +4 -4
- data/CHANGELOG.md +81 -0
- data/README.md +196 -43
- data/ext/rbxl_native/native.c +25 -4
- data/lib/rbxl/date_format.rb +82 -0
- data/lib/rbxl/editable_cell.rb +106 -22
- data/lib/rbxl/editable_styles.rb +273 -0
- data/lib/rbxl/editable_workbook.rb +371 -21
- data/lib/rbxl/editable_worksheet.rb +143 -17
- data/lib/rbxl/errors.rb +6 -3
- data/lib/rbxl/read_only_workbook.rb +3 -15
- data/lib/rbxl/style.rb +78 -0
- data/lib/rbxl/style_registry.rb +159 -0
- data/lib/rbxl/style_xml.rb +109 -0
- data/lib/rbxl/version.rb +1 -1
- data/lib/rbxl/write_only_cell.rb +18 -6
- data/lib/rbxl/write_only_workbook.rb +53 -4
- data/lib/rbxl/write_only_worksheet.rb +268 -5
- data/lib/rbxl/xml_edit.rb +77 -0
- data/lib/rbxl.rb +6 -0
- data/sig/rbxl.rbs +27 -4
- metadata +11 -4
|
@@ -25,6 +25,135 @@ module Rbxl
|
|
|
25
25
|
@name = name
|
|
26
26
|
@rows = []
|
|
27
27
|
@column_name_cache = []
|
|
28
|
+
@column_widths = {}
|
|
29
|
+
@row_heights = {}
|
|
30
|
+
@freeze = nil
|
|
31
|
+
@merges = []
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Sets the display width of one or more columns.
|
|
35
|
+
#
|
|
36
|
+
# sheet.column_width(0, 45.7) # column A
|
|
37
|
+
# sheet.column_width(1..3, 12.0) # columns B-D
|
|
38
|
+
#
|
|
39
|
+
# The argument is a 0-based column index or an ascending Range of
|
|
40
|
+
# indexes. Calling +column_width+ on the same column twice keeps the
|
|
41
|
+
# last value. Width values must be positive.
|
|
42
|
+
#
|
|
43
|
+
# @param index_or_range [Integer, Range<Integer>] 0-based column index or Range
|
|
44
|
+
# @param width [Numeric] column width in Excel units
|
|
45
|
+
# @return [Rbxl::WriteOnlyWorksheet] +self+ for chaining
|
|
46
|
+
# @raise [ArgumentError] if the index is negative or the width is not positive
|
|
47
|
+
# @raise [TypeError] if the first argument is neither Integer nor Range
|
|
48
|
+
def column_width(index_or_range, width)
|
|
49
|
+
width = Float(width)
|
|
50
|
+
raise ArgumentError, "column width must be positive (got #{width})" unless width.positive?
|
|
51
|
+
|
|
52
|
+
case index_or_range
|
|
53
|
+
when Integer
|
|
54
|
+
raise ArgumentError, "column index must be non-negative (got #{index_or_range})" if index_or_range.negative?
|
|
55
|
+
|
|
56
|
+
@column_widths[index_or_range] = width
|
|
57
|
+
when Range
|
|
58
|
+
first = index_or_range.first
|
|
59
|
+
last = index_or_range.last
|
|
60
|
+
raise ArgumentError, "column range must not be negative (got #{index_or_range})" if first.negative?
|
|
61
|
+
raise ArgumentError, "column range must be ascending (got #{index_or_range})" if first > last
|
|
62
|
+
|
|
63
|
+
index_or_range.each { |i| @column_widths[i] = width }
|
|
64
|
+
else
|
|
65
|
+
raise TypeError, "expected Integer or Range, got #{index_or_range.class}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
self
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Sets the height of one or more rows.
|
|
72
|
+
#
|
|
73
|
+
# sheet.row_height(0, 22) # row 1 (header)
|
|
74
|
+
# sheet.row_height(0..2, 18) # rows 1-3
|
|
75
|
+
#
|
|
76
|
+
# The argument is a 0-based row index or an ascending Range. Indexes
|
|
77
|
+
# may target rows that have not yet been appended; the height is
|
|
78
|
+
# applied if and when a matching row is emitted at save time.
|
|
79
|
+
#
|
|
80
|
+
# @param index_or_range [Integer, Range<Integer>] 0-based row index or Range
|
|
81
|
+
# @param height [Numeric] row height in points
|
|
82
|
+
# @return [Rbxl::WriteOnlyWorksheet] +self+ for chaining
|
|
83
|
+
# @raise [ArgumentError] if the index is negative or the height is not positive
|
|
84
|
+
# @raise [TypeError] if the first argument is neither Integer nor Range
|
|
85
|
+
def row_height(index_or_range, height)
|
|
86
|
+
height = Float(height)
|
|
87
|
+
raise ArgumentError, "row height must be positive (got #{height})" unless height.positive?
|
|
88
|
+
|
|
89
|
+
case index_or_range
|
|
90
|
+
when Integer
|
|
91
|
+
raise ArgumentError, "row index must be non-negative (got #{index_or_range})" if index_or_range.negative?
|
|
92
|
+
|
|
93
|
+
@row_heights[index_or_range] = height
|
|
94
|
+
when Range
|
|
95
|
+
first = index_or_range.first
|
|
96
|
+
last = index_or_range.last
|
|
97
|
+
raise ArgumentError, "row range must not be negative (got #{index_or_range})" if first.negative?
|
|
98
|
+
raise ArgumentError, "row range must be ascending (got #{index_or_range})" if first > last
|
|
99
|
+
|
|
100
|
+
index_or_range.each { |i| @row_heights[i] = height }
|
|
101
|
+
else
|
|
102
|
+
raise TypeError, "expected Integer or Range, got #{index_or_range.class}"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
self
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Freezes the top +rows+ rows and/or left +cols+ columns so they remain
|
|
109
|
+
# visible while the rest of the sheet scrolls.
|
|
110
|
+
#
|
|
111
|
+
# sheet.freeze!(rows: 1) # header row only
|
|
112
|
+
# sheet.freeze!(rows: 1, cols: 2) # header row + leftmost two columns
|
|
113
|
+
# sheet.freeze!(rows: 0, cols: 0) # clears any prior freeze
|
|
114
|
+
#
|
|
115
|
+
# @param rows [Integer] number of rows to freeze from the top (>= 0)
|
|
116
|
+
# @param cols [Integer] number of columns to freeze from the left (>= 0)
|
|
117
|
+
# @return [Rbxl::WriteOnlyWorksheet] +self+ for chaining
|
|
118
|
+
# @raise [ArgumentError] if either count is negative
|
|
119
|
+
def freeze!(rows: 0, cols: 0)
|
|
120
|
+
raise ArgumentError, "rows must be non-negative (got #{rows})" if rows.negative?
|
|
121
|
+
raise ArgumentError, "cols must be non-negative (got #{cols})" if cols.negative?
|
|
122
|
+
|
|
123
|
+
@freeze = (rows.zero? && cols.zero?) ? nil : { rows: rows, cols: cols }
|
|
124
|
+
self
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Merges a rectangular range of cells. Excel keeps the value of the
|
|
128
|
+
# top-left ("anchor") cell and visually spans it across the range.
|
|
129
|
+
#
|
|
130
|
+
# sheet.merge("A1:C1")
|
|
131
|
+
# sheet.merge("A1", "C1")
|
|
132
|
+
#
|
|
133
|
+
# The range string is stored as written; rbxl does not validate that
|
|
134
|
+
# the range is rectangular, ascending, or non-overlapping with other
|
|
135
|
+
# merges — Excel will resolve the file as long as the syntax is valid.
|
|
136
|
+
#
|
|
137
|
+
# @overload merge(range_string)
|
|
138
|
+
# @param range_string [String] OOXML range like <tt>"A1:C1"</tt>
|
|
139
|
+
# @overload merge(top_left, bottom_right)
|
|
140
|
+
# @param top_left [String] top-left cell coordinate
|
|
141
|
+
# @param bottom_right [String] bottom-right cell coordinate
|
|
142
|
+
# @return [Rbxl::WriteOnlyWorksheet] +self+ for chaining
|
|
143
|
+
# @raise [ArgumentError] if the arguments do not match either form
|
|
144
|
+
def merge(*args)
|
|
145
|
+
range =
|
|
146
|
+
case args
|
|
147
|
+
in [String => single]
|
|
148
|
+
single
|
|
149
|
+
in [String => from, String => to]
|
|
150
|
+
"#{from}:#{to}"
|
|
151
|
+
else
|
|
152
|
+
raise ArgumentError, %(merge expects "A1:B2" or "A1", "B2")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
@merges << range
|
|
156
|
+
self
|
|
28
157
|
end
|
|
29
158
|
|
|
30
159
|
# Appends a row of values. Equivalent to {#append} so that the shell
|
|
@@ -63,39 +192,173 @@ module Rbxl
|
|
|
63
192
|
#
|
|
64
193
|
# @return [String] worksheet XML
|
|
65
194
|
def to_xml
|
|
66
|
-
if defined?(Rbxl::Native)
|
|
67
|
-
return Rbxl::Native.generate_sheet(@rows)
|
|
195
|
+
if wrap_features_empty? && defined?(Rbxl::Native)
|
|
196
|
+
return Rbxl::Native.generate_sheet(@rows, formatted_row_heights)
|
|
68
197
|
end
|
|
69
198
|
|
|
70
199
|
dimension_ref = @rows.empty? ? "A1" : "A1:#{column_name(max_columns)}#{@rows.length}"
|
|
71
200
|
buf = +""
|
|
72
201
|
buf << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
73
202
|
buf << "\n"
|
|
74
|
-
|
|
203
|
+
if external_hyperlinks?
|
|
204
|
+
buf << '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'
|
|
205
|
+
else
|
|
206
|
+
buf << '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">'
|
|
207
|
+
end
|
|
75
208
|
buf << "\n"
|
|
76
209
|
buf << ' <dimension ref="'
|
|
77
210
|
buf << dimension_ref
|
|
78
211
|
buf << '"/>'
|
|
79
212
|
buf << "\n"
|
|
213
|
+
|
|
214
|
+
append_sheet_views_to(buf) if @freeze
|
|
215
|
+
append_cols_to(buf) unless @column_widths.empty?
|
|
216
|
+
|
|
80
217
|
buf << ' <sheetData>'
|
|
81
218
|
|
|
82
219
|
@rows.each_with_index do |row_values, row_index|
|
|
83
220
|
row_num_str = (row_index + 1).to_s
|
|
84
221
|
buf << '<row r="'
|
|
85
222
|
buf << row_num_str
|
|
86
|
-
buf << '"
|
|
223
|
+
buf << '"'
|
|
224
|
+
if (height = @row_heights[row_index])
|
|
225
|
+
buf << %( ht="#{format_number(height)}" customHeight="1")
|
|
226
|
+
end
|
|
227
|
+
buf << '>'
|
|
87
228
|
row_values.each_with_index do |value, col_index|
|
|
88
229
|
serialize_cell_to(buf, column_name(col_index + 1), row_num_str, value)
|
|
89
230
|
end
|
|
90
231
|
buf << '</row>'
|
|
91
232
|
end
|
|
92
233
|
|
|
93
|
-
buf <<
|
|
234
|
+
buf << '</sheetData>'
|
|
235
|
+
append_merge_cells_to(buf) unless @merges.empty?
|
|
236
|
+
append_hyperlinks_to(buf) if hyperlinks.any?
|
|
237
|
+
buf << "\n</worksheet>"
|
|
94
238
|
buf
|
|
95
239
|
end
|
|
96
240
|
|
|
241
|
+
# @return [Array<Hash>] hyperlinks in row-then-column order. Each entry has
|
|
242
|
+
# +:ref+ (Excel coordinate), +:target+ (URL or anchor without leading #),
|
|
243
|
+
# +:external+ (true/false), and +:rid+ (only set when external).
|
|
244
|
+
# Lazily computed on first access; assumes +@rows+ is stable by then.
|
|
245
|
+
def hyperlinks
|
|
246
|
+
@hyperlinks ||= compute_hyperlinks
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# @return [Array<Hash{Symbol=>String}>] {rid:, target:} pairs for external
|
|
250
|
+
# hyperlinks; empty array when the sheet has no external links.
|
|
251
|
+
def external_hyperlink_relationships
|
|
252
|
+
hyperlinks.select { |h| h[:external] }.map { |h| { rid: h[:rid], target: h[:target] } }
|
|
253
|
+
end
|
|
254
|
+
|
|
97
255
|
private
|
|
98
256
|
|
|
257
|
+
def wrap_features_empty?
|
|
258
|
+
@column_widths.empty? && @freeze.nil? && @merges.empty? && hyperlinks.empty?
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def external_hyperlinks?
|
|
262
|
+
hyperlinks.any? { |h| h[:external] }
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def compute_hyperlinks
|
|
266
|
+
out = []
|
|
267
|
+
rid_counter = 0
|
|
268
|
+
@rows.each_with_index do |row, row_index|
|
|
269
|
+
row.each_with_index do |cell, col_index|
|
|
270
|
+
next unless cell.is_a?(WriteOnlyCell) && cell.hyperlink
|
|
271
|
+
|
|
272
|
+
ref = "#{column_name(col_index + 1)}#{row_index + 1}"
|
|
273
|
+
target = cell.hyperlink
|
|
274
|
+
|
|
275
|
+
if target.start_with?("#")
|
|
276
|
+
out << { ref: ref, target: target[1..], external: false }
|
|
277
|
+
else
|
|
278
|
+
rid_counter += 1
|
|
279
|
+
out << { ref: ref, target: target, external: true, rid: "rId#{rid_counter}" }
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
out
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def append_hyperlinks_to(buf)
|
|
287
|
+
buf << '<hyperlinks>'
|
|
288
|
+
hyperlinks.each do |h|
|
|
289
|
+
buf << %(<hyperlink ref="#{h[:ref]}")
|
|
290
|
+
if h[:external]
|
|
291
|
+
buf << %( r:id="#{h[:rid]}")
|
|
292
|
+
else
|
|
293
|
+
buf << %( location="#{escape_attr(h[:target])}")
|
|
294
|
+
end
|
|
295
|
+
buf << '/>'
|
|
296
|
+
end
|
|
297
|
+
buf << '</hyperlinks>'
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def escape_attr(value)
|
|
301
|
+
str = value.to_s
|
|
302
|
+
str.gsub(/[&<>"]/) { |c| { '&' => '&', '<' => '<', '>' => '>', '"' => '"' }[c] }
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def formatted_row_heights
|
|
306
|
+
return nil if @row_heights.empty?
|
|
307
|
+
|
|
308
|
+
@row_heights.each_with_object({}) { |(idx, h), out| out[idx] = format_number(h) }
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def format_number(n)
|
|
312
|
+
n == n.to_i ? n.to_i.to_s : n.to_s
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def append_sheet_views_to(buf)
|
|
316
|
+
rows = @freeze[:rows]
|
|
317
|
+
cols = @freeze[:cols]
|
|
318
|
+
top_left = "#{column_name(cols + 1)}#{rows + 1}"
|
|
319
|
+
active_pane =
|
|
320
|
+
if cols.positive? && rows.positive?
|
|
321
|
+
"bottomRight"
|
|
322
|
+
elsif cols.positive?
|
|
323
|
+
"topRight"
|
|
324
|
+
else
|
|
325
|
+
"bottomLeft"
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
buf << ' <sheetViews><sheetView workbookViewId="0"><pane'
|
|
329
|
+
buf << %( xSplit="#{cols}") if cols.positive?
|
|
330
|
+
buf << %( ySplit="#{rows}") if rows.positive?
|
|
331
|
+
buf << %( topLeftCell="#{top_left}")
|
|
332
|
+
buf << %( activePane="#{active_pane}")
|
|
333
|
+
buf << ' state="frozen"/></sheetView></sheetViews>'
|
|
334
|
+
buf << "\n"
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def append_cols_to(buf)
|
|
338
|
+
sorted = @column_widths.sort
|
|
339
|
+
buf << ' <cols>'
|
|
340
|
+
i = 0
|
|
341
|
+
while i < sorted.length
|
|
342
|
+
start_idx, width = sorted[i]
|
|
343
|
+
end_idx = start_idx
|
|
344
|
+
j = i + 1
|
|
345
|
+
while j < sorted.length && sorted[j][0] == end_idx + 1 && sorted[j][1] == width
|
|
346
|
+
end_idx = sorted[j][0]
|
|
347
|
+
j += 1
|
|
348
|
+
end
|
|
349
|
+
buf << %(<col min="#{start_idx + 1}" max="#{end_idx + 1}" width="#{format_number(width)}" customWidth="1"/>)
|
|
350
|
+
i = j
|
|
351
|
+
end
|
|
352
|
+
buf << '</cols>'
|
|
353
|
+
buf << "\n"
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
def append_merge_cells_to(buf)
|
|
357
|
+
buf << %(<mergeCells count="#{@merges.length}">)
|
|
358
|
+
@merges.each { |range| buf << %(<mergeCell ref="#{range}"/>) }
|
|
359
|
+
buf << '</mergeCells>'
|
|
360
|
+
end
|
|
361
|
+
|
|
99
362
|
def serialize_cell_to(buf, col_name, row_num_str, value)
|
|
100
363
|
if value.is_a?(WriteOnlyCell)
|
|
101
364
|
serialize_write_only_cell_to(buf, col_name, row_num_str, value)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module Rbxl
|
|
2
|
+
# @api private
|
|
3
|
+
#
|
|
4
|
+
# DOM-insertion helpers for edit mode. Every fragment is parsed in the
|
|
5
|
+
# context of its new parent and then moved into the parent's namespace, so
|
|
6
|
+
# the inserted elements land in the right namespace whether the host
|
|
7
|
+
# document binds SpreadsheetML as the default namespace (Excel, LibreOffice)
|
|
8
|
+
# or under a prefix such as +x:+ (the .NET OpenXML SDK).
|
|
9
|
+
module XmlEdit
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# Serializes a document or node without libxml2's pretty-printing, so
|
|
13
|
+
# a re-serialized part keeps the source's layout apart from the edits.
|
|
14
|
+
#
|
|
15
|
+
# @return [String]
|
|
16
|
+
def serialize(node)
|
|
17
|
+
node.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Appends +xml+ as the last child of +parent+.
|
|
21
|
+
#
|
|
22
|
+
# @return [Nokogiri::XML::Element] the first inserted element
|
|
23
|
+
def append(parent, xml)
|
|
24
|
+
adopt(parent, parent.add_child(xml))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Inserts +xml+ immediately before +sibling+.
|
|
28
|
+
#
|
|
29
|
+
# @return [Nokogiri::XML::Element] the first inserted element
|
|
30
|
+
def insert_before(sibling, xml)
|
|
31
|
+
adopt(sibling.parent, sibling.add_previous_sibling(xml))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Inserts +xml+ as a child of +parent+ respecting a schema sequence:
|
|
35
|
+
# the new element goes before the first existing child whose local name
|
|
36
|
+
# appears after +name+ in +order+, or at the end when there is none.
|
|
37
|
+
#
|
|
38
|
+
# @param order [Array<String>] local names in schema sequence order
|
|
39
|
+
# @return [Nokogiri::XML::Element] the inserted element
|
|
40
|
+
def insert_in_order(parent, name, xml, order)
|
|
41
|
+
rank = order.index(name) or raise ArgumentError, "#{name} not in order list"
|
|
42
|
+
following = parent.element_children.find do |child|
|
|
43
|
+
idx = order.index(child.name)
|
|
44
|
+
idx && idx > rank
|
|
45
|
+
end
|
|
46
|
+
following ? insert_before(following, xml) : append(parent, xml)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Returns the first element child of +parent+ named +name+ in +parent+'s
|
|
50
|
+
# namespace, or +nil+.
|
|
51
|
+
def child(parent, name)
|
|
52
|
+
href = parent.namespace&.href
|
|
53
|
+
parent.element_children.find { |c| c.name == name && c.namespace&.href == href }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Returns all element children of +parent+ named +name+ in +parent+'s
|
|
57
|
+
# namespace.
|
|
58
|
+
def children(parent, name)
|
|
59
|
+
href = parent.namespace&.href
|
|
60
|
+
parent.element_children.select { |c| c.name == name && c.namespace&.href == href }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def adopt(parent, inserted)
|
|
64
|
+
ns = parent.namespace
|
|
65
|
+
nodes = inserted.is_a?(Nokogiri::XML::NodeSet) ? inserted.to_a : [inserted]
|
|
66
|
+
nodes.each { |node| set_namespace_deep(node, ns) } if ns
|
|
67
|
+
nodes.find(&:element?)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def set_namespace_deep(node, ns)
|
|
71
|
+
return unless node.element?
|
|
72
|
+
|
|
73
|
+
node.namespace = ns if node.namespace.nil?
|
|
74
|
+
node.element_children.each { |child| set_namespace_deep(child, ns) }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
data/lib/rbxl.rb
CHANGED
|
@@ -6,16 +6,22 @@ require "stringio"
|
|
|
6
6
|
require "zip"
|
|
7
7
|
|
|
8
8
|
require_relative "rbxl/cell"
|
|
9
|
+
require_relative "rbxl/date_format"
|
|
10
|
+
require_relative "rbxl/xml_edit"
|
|
9
11
|
require_relative "rbxl/empty_cell"
|
|
10
12
|
require_relative "rbxl/errors"
|
|
11
13
|
require_relative "rbxl/shared_strings_loader"
|
|
12
14
|
require_relative "rbxl/read_only_cell"
|
|
13
15
|
require_relative "rbxl/read_only_workbook"
|
|
14
16
|
require_relative "rbxl/read_only_worksheet"
|
|
17
|
+
require_relative "rbxl/editable_styles"
|
|
15
18
|
require_relative "rbxl/editable_cell"
|
|
16
19
|
require_relative "rbxl/editable_worksheet"
|
|
17
20
|
require_relative "rbxl/editable_workbook"
|
|
18
21
|
require_relative "rbxl/row"
|
|
22
|
+
require_relative "rbxl/style"
|
|
23
|
+
require_relative "rbxl/style_xml"
|
|
24
|
+
require_relative "rbxl/style_registry"
|
|
19
25
|
require_relative "rbxl/version"
|
|
20
26
|
require_relative "rbxl/write_only_cell"
|
|
21
27
|
require_relative "rbxl/write_only_workbook"
|
data/sig/rbxl.rbs
CHANGED
|
@@ -10,6 +10,8 @@ module Rbxl
|
|
|
10
10
|
type dimensions = { ref: String, max_col: Integer, max_row: Integer }
|
|
11
11
|
|
|
12
12
|
type editable_cell_value = String | Integer | Float | bool | nil
|
|
13
|
+
type editable_cell_input = String | Numeric | bool | Date | Time | nil
|
|
14
|
+
type style_component = Hash[Symbol | String, untyped]
|
|
13
15
|
|
|
14
16
|
def self.open: (pathish path, ?read_only: bool, ?edit: bool, ?streaming: bool, ?date_conversion: bool) -> (ReadOnlyWorkbook | EditableWorkbook)
|
|
15
17
|
| [T] (pathish path, ?read_only: bool, ?edit: bool, ?streaming: bool, ?date_conversion: bool) { (ReadOnlyWorkbook | EditableWorkbook) -> T } -> T
|
|
@@ -55,6 +57,9 @@ module Rbxl
|
|
|
55
57
|
class EditableCellTypeError < Error
|
|
56
58
|
end
|
|
57
59
|
|
|
60
|
+
class DefinedNameError < Error
|
|
61
|
+
end
|
|
62
|
+
|
|
58
63
|
class Cell
|
|
59
64
|
attr_accessor value: cell_value
|
|
60
65
|
attr_accessor coordinate: String?
|
|
@@ -80,7 +85,9 @@ module Rbxl
|
|
|
80
85
|
attr_reader value: untyped
|
|
81
86
|
attr_reader style_id: Integer?
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
attr_reader hyperlink: String?
|
|
89
|
+
|
|
90
|
+
def initialize: (untyped value, ?style_id: Integer?, ?hyperlink: String?) -> void
|
|
84
91
|
end
|
|
85
92
|
|
|
86
93
|
class Row
|
|
@@ -132,6 +139,7 @@ module Rbxl
|
|
|
132
139
|
attr_reader worksheets: Array[WriteOnlyWorksheet]
|
|
133
140
|
|
|
134
141
|
def initialize: () -> void
|
|
142
|
+
def add_style: (?font: style_component?, ?fill: style_component?, ?border: style_component?, ?alignment: style_component?, ?number_format: String?) -> Integer
|
|
135
143
|
def add_sheet: (String name) -> WriteOnlyWorksheet
|
|
136
144
|
def save: (pathish path) -> String
|
|
137
145
|
def close: () -> bool
|
|
@@ -142,6 +150,10 @@ module Rbxl
|
|
|
142
150
|
attr_reader name: String
|
|
143
151
|
|
|
144
152
|
def initialize: (name: String) -> void
|
|
153
|
+
def column_width: (Integer | Range[Integer] index_or_range, Numeric width) -> WriteOnlyWorksheet
|
|
154
|
+
def row_height: (Integer | Range[Integer] index_or_range, Numeric height) -> WriteOnlyWorksheet
|
|
155
|
+
def freeze!: (?rows: Integer, ?cols: Integer) -> WriteOnlyWorksheet
|
|
156
|
+
def merge: (String range_or_from, ?String to) -> WriteOnlyWorksheet
|
|
145
157
|
def <<: (row_input values) -> WriteOnlyWorksheet
|
|
146
158
|
def append: (row_input values) -> WriteOnlyWorksheet
|
|
147
159
|
def to_xml: () -> String
|
|
@@ -162,7 +174,11 @@ module Rbxl
|
|
|
162
174
|
def sheet: (String | Integer name_or_index) -> EditableWorksheet
|
|
163
175
|
def sheets: () { (EditableWorksheet) -> void } -> void
|
|
164
176
|
| () -> Enumerator[EditableWorksheet, void]
|
|
165
|
-
def
|
|
177
|
+
def add_sheet: (String name) -> EditableWorksheet
|
|
178
|
+
def add_style: (?font: style_component?, ?fill: style_component?, ?border: style_component?, ?alignment: style_component?, ?number_format: String?) -> Integer
|
|
179
|
+
def defined_names: () -> Array[String]
|
|
180
|
+
def defined_name: (String name, ?sheet: (String | Integer)?) -> EditableCell
|
|
181
|
+
def save: (?pathish? path, ?recalc: bool) -> String
|
|
166
182
|
def close: () -> bool
|
|
167
183
|
def closed?: () -> bool
|
|
168
184
|
end
|
|
@@ -173,9 +189,13 @@ module Rbxl
|
|
|
173
189
|
attr_reader name: String
|
|
174
190
|
attr_reader entry_path: String
|
|
175
191
|
|
|
176
|
-
|
|
192
|
+
MAX_COLUMN: Integer
|
|
193
|
+
MAX_ROW: Integer
|
|
194
|
+
|
|
195
|
+
def initialize: (workbook: EditableWorkbook, zip: untyped, entry_path: String, workbook_path: String, shared_strings: Array[String], name: String, ?source_xml: String?) -> void
|
|
177
196
|
def cell: (String coordinate) -> EditableCell
|
|
178
197
|
def []: (String coordinate) -> EditableCell
|
|
198
|
+
def write_rows: (String anchor, Array[Array[editable_cell_input]] rows) -> EditableWorksheet
|
|
179
199
|
def dirty?: () -> bool
|
|
180
200
|
def to_xml: () -> String
|
|
181
201
|
end
|
|
@@ -187,7 +207,10 @@ module Rbxl
|
|
|
187
207
|
|
|
188
208
|
def initialize: (worksheet: EditableWorksheet, coordinate: String) -> void
|
|
189
209
|
def value: () -> editable_cell_value
|
|
190
|
-
def value=: (
|
|
210
|
+
def value=: (editable_cell_input new_value) -> editable_cell_input
|
|
211
|
+
def style_id: () -> Integer
|
|
212
|
+
def style_id=: (Integer id) -> Integer
|
|
213
|
+
def style: (?font: style_component?, ?fill: style_component?, ?border: style_component?, ?alignment: style_component?, ?number_format: String?) -> EditableCell
|
|
191
214
|
end
|
|
192
215
|
|
|
193
216
|
module SharedStringsLoader
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbxl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Taro KOBAYASHI
|
|
@@ -49,8 +49,9 @@ dependencies:
|
|
|
49
49
|
- - "<"
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
51
|
version: '2.0'
|
|
52
|
-
description: rbxl is a fast, low-memory Ruby gem for row-by-row XLSX reads
|
|
53
|
-
XLSX writes, with an optional
|
|
52
|
+
description: rbxl is a fast, low-memory Ruby gem for row-by-row XLSX reads, template
|
|
53
|
+
fill-in edits of existing XLSX files, and append-only XLSX writes, with an optional
|
|
54
|
+
native extension for higher-throughput XML parsing.
|
|
54
55
|
email:
|
|
55
56
|
- taro@matzlika.co.jp
|
|
56
57
|
executables: []
|
|
@@ -66,7 +67,9 @@ files:
|
|
|
66
67
|
- ext/rbxl_native/native.c
|
|
67
68
|
- lib/rbxl.rb
|
|
68
69
|
- lib/rbxl/cell.rb
|
|
70
|
+
- lib/rbxl/date_format.rb
|
|
69
71
|
- lib/rbxl/editable_cell.rb
|
|
72
|
+
- lib/rbxl/editable_styles.rb
|
|
70
73
|
- lib/rbxl/editable_workbook.rb
|
|
71
74
|
- lib/rbxl/editable_worksheet.rb
|
|
72
75
|
- lib/rbxl/empty_cell.rb
|
|
@@ -77,10 +80,14 @@ files:
|
|
|
77
80
|
- lib/rbxl/read_only_worksheet.rb
|
|
78
81
|
- lib/rbxl/row.rb
|
|
79
82
|
- lib/rbxl/shared_strings_loader.rb
|
|
83
|
+
- lib/rbxl/style.rb
|
|
84
|
+
- lib/rbxl/style_registry.rb
|
|
85
|
+
- lib/rbxl/style_xml.rb
|
|
80
86
|
- lib/rbxl/version.rb
|
|
81
87
|
- lib/rbxl/write_only_cell.rb
|
|
82
88
|
- lib/rbxl/write_only_workbook.rb
|
|
83
89
|
- lib/rbxl/write_only_worksheet.rb
|
|
90
|
+
- lib/rbxl/xml_edit.rb
|
|
84
91
|
- sig/rbxl.rbs
|
|
85
92
|
homepage: https://github.com/matzlika/rbxl
|
|
86
93
|
licenses:
|
|
@@ -104,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
104
111
|
- !ruby/object:Gem::Version
|
|
105
112
|
version: '0'
|
|
106
113
|
requirements: []
|
|
107
|
-
rubygems_version:
|
|
114
|
+
rubygems_version: 4.0.3
|
|
108
115
|
specification_version: 4
|
|
109
116
|
summary: Fast, low-memory XLSX processing for Ruby.
|
|
110
117
|
test_files: []
|