xlsxrb 0.1.4 → 0.1.6
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/.devcontainer/Dockerfile +1 -1
- data/.gem_rbs_collection/ast/2.4/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/ast/2.4/ast.rbs +73 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/array.rbs +4 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/atomic_reference.rbs +16 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/executor.rbs +96 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/hash.rbs +4 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/map.rbs +68 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/promises.rbs +249 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/set.rbs +4 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/timer_task.rbs +47 -0
- data/.gem_rbs_collection/concurrent-ruby/1.1/utility/processor_counter.rbs +5 -0
- data/.gem_rbs_collection/csv/3.3/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/csv/3.3/csv.rbs +3871 -0
- data/.gem_rbs_collection/csv/3.3/manifest.yaml +3 -0
- data/.gem_rbs_collection/lint_roller/1.1/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/lint_roller/1.1/lint_roller.rbs +48 -0
- data/.gem_rbs_collection/listen/3.9/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/listen/3.9/listen.rbs +25 -0
- data/.gem_rbs_collection/listen/3.9/listener.rbs +24 -0
- data/.gem_rbs_collection/logger/1.7/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/logger/1.7/formatter.rbs +45 -0
- data/.gem_rbs_collection/logger/1.7/log_device.rbs +100 -0
- data/.gem_rbs_collection/logger/1.7/logger.rbs +796 -0
- data/.gem_rbs_collection/logger/1.7/manifest.yaml +2 -0
- data/.gem_rbs_collection/logger/1.7/period.rbs +17 -0
- data/.gem_rbs_collection/logger/1.7/severity.rbs +34 -0
- data/.gem_rbs_collection/nokogiri/1.11/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/nokogiri/1.11/nokogiri.rbs +2332 -0
- data/.gem_rbs_collection/nokogiri/1.11/patch.rbs +4 -0
- data/.gem_rbs_collection/parallel/1.20/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/parallel/1.20/parallel.rbs +86 -0
- data/.gem_rbs_collection/parser/3.2/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/parser/3.2/manifest.yaml +7 -0
- data/.gem_rbs_collection/parser/3.2/parser.rbs +194 -0
- data/.gem_rbs_collection/parser/3.2/polyfill.rbs +4 -0
- data/.gem_rbs_collection/rainbow/3.0/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/rainbow/3.0/global.rbs +7 -0
- data/.gem_rbs_collection/rainbow/3.0/presenter.rbs +209 -0
- data/.gem_rbs_collection/rainbow/3.0/rainbow.rbs +5 -0
- data/.gem_rbs_collection/rake/13.0/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/rake/13.0/manifest.yaml +2 -0
- data/.gem_rbs_collection/rake/13.0/rake.rbs +39 -0
- data/.gem_rbs_collection/regexp_parser/2.8/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/regexp_parser/2.8/regexp_parser.rbs +17 -0
- data/.gem_rbs_collection/rubocop/1.57/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/rubocop/1.57/rubocop.rbs +208 -0
- data/.gem_rbs_collection/rubocop-ast/1.46/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/rubocop-ast/1.46/rubocop-ast.rbs +903 -0
- data/.gem_rbs_collection/rubyzip/3.2/.rbs_meta.yaml +9 -0
- data/.gem_rbs_collection/rubyzip/3.2/manifest.yaml +8 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/central_directory.rbs +42 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/compressor.rbs +5 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/constants.rbs +47 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/crypto/aes_encryption.rbs +30 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/crypto/decrypted_io.rbs +9 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/crypto/encryption.rbs +7 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/crypto/null_encryption.rbs +19 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/crypto/traditional_encryption.rbs +31 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/decompressor.rbs +18 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/deflater.rbs +12 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/dirtyable.rbs +11 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/dos_time.rbs +13 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/entry.rbs +95 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/entry_set.rbs +31 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/errors.rbs +58 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/aes.rbs +24 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/generic.rbs +17 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/ntfs.rbs +23 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/old_unix.rbs +22 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/universal_time.rbs +30 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/unix.rbs +20 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/unknown.rbs +15 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field/zip64.rbs +26 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/extra_field.rbs +21 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/file.rbs +131 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/file_split.rbs +14 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/filesystem/dir.rbs +33 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/filesystem/directory_iterator.rbs +21 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/filesystem/file.rbs +63 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/filesystem/file_stat.rbs +55 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/filesystem/zip_file_name_mapper.rbs +35 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/filesystem.rbs +7 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/inflater.rbs +10 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/input_stream.rbs +22 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/ioextras/abstract_input_stream.rbs +29 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/ioextras/abstract_output_stream.rbs +17 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/ioextras.rbs +13 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/null_compressor.rbs +10 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/null_decompressor.rbs +8 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/null_input_stream.rbs +6 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/output_stream.rbs +30 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/pass_thru_compressor.rbs +10 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/pass_thru_decompressor.rbs +10 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/streamable_directory.rbs +5 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/streamable_stream.rbs +15 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip/version.rbs +3 -0
- data/.gem_rbs_collection/rubyzip/3.2/zip.rbs +40 -0
- data/CHANGELOG.md +42 -3
- data/README.md +130 -49
- data/Rakefile +23 -2
- data/Steepfile +17 -0
- data/benchmark.rb +324 -348
- data/docs/ARCHITECTURE.md +24 -0
- data/docs/DEVELOPMENT.md +58 -0
- data/docs/QUALITY_ASSURANCE.md +26 -0
- data/docs/visual/VisualGallery.md +893 -938
- data/docs/wasm/ruby.wasm +0 -0
- data/lib/xlsxrb/elements/cell.rb +113 -8
- data/lib/xlsxrb/elements/column.rb +2 -0
- data/lib/xlsxrb/elements/row.rb +52 -4
- data/lib/xlsxrb/elements/types.rb +6 -0
- data/lib/xlsxrb/elements/workbook.rb +29 -0
- data/lib/xlsxrb/elements/worksheet.rb +98 -1
- data/lib/xlsxrb/elements.rb +2 -0
- data/lib/xlsxrb/ooxml/reader.rb +8 -6
- data/lib/xlsxrb/ooxml/shared_strings_parser.rb +106 -40
- data/lib/xlsxrb/ooxml/styles_parser.rb +2 -0
- data/lib/xlsxrb/ooxml/utils.rb +2 -0
- data/lib/xlsxrb/ooxml/workbook_parser.rb +6 -1
- data/lib/xlsxrb/ooxml/workbook_writer.rb +15 -4
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +156 -23
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +207 -152
- data/lib/xlsxrb/ooxml/writer.rb +217 -5
- data/lib/xlsxrb/ooxml/xml_builder.rb +18 -10
- data/lib/xlsxrb/ooxml/xml_parser.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_generator.rb +5 -8
- data/lib/xlsxrb/ooxml/zip_reader.rb +179 -57
- data/lib/xlsxrb/ooxml/zip_writer.rb +65 -25
- data/lib/xlsxrb/ooxml.rb +3 -1
- data/lib/xlsxrb/style_builder.rb +284 -36
- data/lib/xlsxrb/version.rb +3 -1
- data/lib/xlsxrb.rb +1761 -275
- data/rbs_collection.lock.yaml +252 -0
- data/rbs_collection.yaml +19 -0
- data/sig/generated/xlsxrb/elements/cell.rbs +30 -0
- data/sig/generated/xlsxrb/elements/column.rbs +30 -0
- data/sig/generated/xlsxrb/elements/row.rbs +32 -0
- data/sig/generated/xlsxrb/elements/types.rbs +74 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +25 -0
- data/sig/generated/xlsxrb/elements/worksheet.rbs +27 -0
- data/sig/generated/xlsxrb/elements.rbs +8 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +1412 -0
- data/sig/generated/xlsxrb/ooxml/shared_strings_parser.rbs +21 -0
- data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +44 -0
- data/sig/generated/xlsxrb/ooxml/utils.rbs +40 -0
- data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +46 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +66 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +67 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +92 -0
- data/sig/generated/xlsxrb/ooxml/writer.rbs +880 -0
- data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +45 -0
- data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +30 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +38 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +45 -0
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +45 -0
- data/sig/generated/xlsxrb/ooxml.rbs +23 -0
- data/sig/generated/xlsxrb/style_builder.rbs +250 -0
- data/sig/generated/xlsxrb/version.rbs +5 -0
- data/sig/generated/xlsxrb.rbs +1276 -0
- data/sig/rexml.rbs +4 -0
- metadata +145 -4
- data/measure_memory.rb +0 -42
- data/sig/xlsxrb.rbs +0 -23
data/lib/xlsxrb/ooxml/writer.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# rbs_inline: enabled
|
|
4
|
+
|
|
3
5
|
require_relative "zip_generator"
|
|
4
6
|
|
|
5
7
|
module Xlsxrb
|
|
@@ -23,6 +25,9 @@ module Xlsxrb
|
|
|
23
25
|
MAX_ROW = 1_048_576
|
|
24
26
|
MAX_COLUMN_INDEX = 16_384 # XFD
|
|
25
27
|
|
|
28
|
+
attr_reader :fonts, :fills, :borders, :xf_entries, :num_fmts
|
|
29
|
+
|
|
30
|
+
# : () -> void
|
|
26
31
|
def initialize
|
|
27
32
|
@sheets = { "Sheet1" => {} }
|
|
28
33
|
@column_widths = { "Sheet1" => {} }
|
|
@@ -95,6 +100,7 @@ module Xlsxrb
|
|
|
95
100
|
end
|
|
96
101
|
|
|
97
102
|
# Adds a new sheet. Raises if name is already taken.
|
|
103
|
+
# : (untyped name) -> untyped
|
|
98
104
|
def add_sheet(name)
|
|
99
105
|
raise ArgumentError, "sheet already exists: #{name}" if @sheets.key?(name)
|
|
100
106
|
|
|
@@ -140,6 +146,7 @@ module Xlsxrb
|
|
|
140
146
|
end
|
|
141
147
|
|
|
142
148
|
# Registers a cell value at the given address (e.g. "A1").
|
|
149
|
+
# : (untyped cell_address, untyped value, ?sheet: untyped?) -> untyped
|
|
143
150
|
def set_cell(cell_address, value, sheet: nil)
|
|
144
151
|
validate_cell_address!(cell_address)
|
|
145
152
|
sheet_name = sheet || @sheet_order.first
|
|
@@ -149,12 +156,14 @@ module Xlsxrb
|
|
|
149
156
|
end
|
|
150
157
|
|
|
151
158
|
# Returns the registered cells for the first (or given) sheet.
|
|
159
|
+
# : (?sheet: untyped?) -> untyped
|
|
152
160
|
def cells(sheet: nil)
|
|
153
161
|
sheet_name = sheet || @sheet_order.first
|
|
154
162
|
@sheets[sheet_name] || {}
|
|
155
163
|
end
|
|
156
164
|
|
|
157
165
|
# Sets the width for a column (e.g. "A", "BC").
|
|
166
|
+
# : (untyped col_letter, untyped width, ?sheet: untyped?) -> untyped
|
|
158
167
|
def set_column_width(col_letter, width, sheet: nil)
|
|
159
168
|
raise ArgumentError, "column must be a String of uppercase letters" unless col_letter.is_a?(String) && col_letter.match?(/\A[A-Z]+\z/)
|
|
160
169
|
|
|
@@ -168,12 +177,14 @@ module Xlsxrb
|
|
|
168
177
|
end
|
|
169
178
|
|
|
170
179
|
# Returns column widths for the first (or given) sheet.
|
|
180
|
+
# : (?sheet: untyped?) -> untyped
|
|
171
181
|
def column_widths(sheet: nil)
|
|
172
182
|
sheet_name = sheet || @sheet_order.first
|
|
173
183
|
@column_widths[sheet_name] || {}
|
|
174
184
|
end
|
|
175
185
|
|
|
176
186
|
# Sets a column attribute (e.g. :hidden, :best_fit, :outline_level, :collapsed, :style).
|
|
187
|
+
# : (untyped col_letter, untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
177
188
|
def set_column_attribute(col_letter, name, value, sheet: nil)
|
|
178
189
|
raise ArgumentError, "column must be a String of uppercase letters" unless col_letter.is_a?(String) && col_letter.match?(/\A[A-Z]+\z/)
|
|
179
190
|
|
|
@@ -185,12 +196,14 @@ module Xlsxrb
|
|
|
185
196
|
end
|
|
186
197
|
|
|
187
198
|
# Returns column attributes for the first (or given) sheet.
|
|
199
|
+
# : (?sheet: untyped?) -> untyped
|
|
188
200
|
def column_attributes(sheet: nil)
|
|
189
201
|
sheet_name = sheet || @sheet_order.first
|
|
190
202
|
@column_attrs[sheet_name] || {}
|
|
191
203
|
end
|
|
192
204
|
|
|
193
205
|
# Sets a row height.
|
|
206
|
+
# : (untyped row_num, untyped height, ?sheet: untyped?) -> untyped
|
|
194
207
|
def set_row_height(row_num, height, sheet: nil)
|
|
195
208
|
sheet_name = sheet || @sheet_order.first
|
|
196
209
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -201,6 +214,7 @@ module Xlsxrb
|
|
|
201
214
|
end
|
|
202
215
|
|
|
203
216
|
# Hides a row.
|
|
217
|
+
# : (untyped row_num, ?hidden: bool, ?sheet: untyped?) -> untyped
|
|
204
218
|
def set_row_hidden(row_num, hidden: true, sheet: nil)
|
|
205
219
|
sheet_name = sheet || @sheet_order.first
|
|
206
220
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -211,6 +225,7 @@ module Xlsxrb
|
|
|
211
225
|
end
|
|
212
226
|
|
|
213
227
|
# Sets a row outline level.
|
|
228
|
+
# : (untyped row_num, untyped level, ?sheet: untyped?) -> untyped
|
|
214
229
|
def set_row_outline_level(row_num, level, sheet: nil)
|
|
215
230
|
sheet_name = sheet || @sheet_order.first
|
|
216
231
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -221,6 +236,7 @@ module Xlsxrb
|
|
|
221
236
|
end
|
|
222
237
|
|
|
223
238
|
# Sets a row collapsed state.
|
|
239
|
+
# : (untyped row_num, ?collapsed: bool, ?sheet: untyped?) -> untyped
|
|
224
240
|
def set_row_collapsed(row_num, collapsed: true, sheet: nil)
|
|
225
241
|
sheet_name = sheet || @sheet_order.first
|
|
226
242
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -231,6 +247,7 @@ module Xlsxrb
|
|
|
231
247
|
end
|
|
232
248
|
|
|
233
249
|
# Sets a row default style index (cellXfs index).
|
|
250
|
+
# : (untyped row_num, untyped style_id, ?sheet: untyped?) -> untyped
|
|
234
251
|
def set_row_style(row_num, style_id, sheet: nil)
|
|
235
252
|
sheet_name = sheet || @sheet_order.first
|
|
236
253
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -242,6 +259,7 @@ module Xlsxrb
|
|
|
242
259
|
end
|
|
243
260
|
|
|
244
261
|
# Sets a row thick top border flag.
|
|
262
|
+
# : (untyped row_num, ?thick: bool, ?sheet: untyped?) -> untyped
|
|
245
263
|
def set_row_thick_top(row_num, thick: true, sheet: nil)
|
|
246
264
|
sheet_name = sheet || @sheet_order.first
|
|
247
265
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -252,6 +270,7 @@ module Xlsxrb
|
|
|
252
270
|
end
|
|
253
271
|
|
|
254
272
|
# Sets a row thick bottom border flag.
|
|
273
|
+
# : (untyped row_num, ?thick: bool, ?sheet: untyped?) -> untyped
|
|
255
274
|
def set_row_thick_bot(row_num, thick: true, sheet: nil)
|
|
256
275
|
sheet_name = sheet || @sheet_order.first
|
|
257
276
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -262,6 +281,7 @@ module Xlsxrb
|
|
|
262
281
|
end
|
|
263
282
|
|
|
264
283
|
# Sets a row phonetic flag.
|
|
284
|
+
# : (untyped row_num, ?phonetic: bool, ?sheet: untyped?) -> untyped
|
|
265
285
|
def set_row_phonetic(row_num, phonetic: true, sheet: nil)
|
|
266
286
|
sheet_name = sheet || @sheet_order.first
|
|
267
287
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_attrs.key?(sheet_name)
|
|
@@ -272,13 +292,15 @@ module Xlsxrb
|
|
|
272
292
|
end
|
|
273
293
|
|
|
274
294
|
# Returns row attributes for the first (or given) sheet.
|
|
295
|
+
# : (?sheet: untyped?) -> untyped
|
|
275
296
|
def row_attributes(sheet: nil)
|
|
276
297
|
sheet_name = sheet || @sheet_order.first
|
|
277
298
|
@row_attrs[sheet_name] || {}
|
|
278
299
|
end
|
|
279
300
|
|
|
280
301
|
# Merges a range of cells (e.g. "A1:B2").
|
|
281
|
-
|
|
302
|
+
# : (untyped range, ?sheet: untyped?) -> untyped
|
|
303
|
+
def merge(range, sheet: nil)
|
|
282
304
|
raise ArgumentError, "range must be a String like 'A1:B2'" unless range.is_a?(String) && range.match?(/\A[A-Z]+\d+:[A-Z]+\d+\z/)
|
|
283
305
|
|
|
284
306
|
sheet_name = sheet || @sheet_order.first
|
|
@@ -288,13 +310,15 @@ module Xlsxrb
|
|
|
288
310
|
end
|
|
289
311
|
|
|
290
312
|
# Returns merged cell ranges for the first (or given) sheet.
|
|
313
|
+
# : (?sheet: untyped?) -> untyped
|
|
291
314
|
def merged_cells(sheet: nil)
|
|
292
315
|
sheet_name = sheet || @sheet_order.first
|
|
293
316
|
@merge_cells[sheet_name] || []
|
|
294
317
|
end
|
|
295
318
|
|
|
296
319
|
# Adds a hyperlink on a cell.
|
|
297
|
-
|
|
320
|
+
# : (untyped cell_address, ?untyped? url, ?sheet: untyped?, ?display: untyped?, ?tooltip: untyped?, ?location: untyped?) -> untyped
|
|
321
|
+
def hyperlink(cell_address, url = nil, sheet: nil, display: nil, tooltip: nil, location: nil)
|
|
298
322
|
validate_cell_address!(cell_address)
|
|
299
323
|
sheet_name = sheet || @sheet_order.first
|
|
300
324
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @hyperlinks.key?(sheet_name)
|
|
@@ -309,12 +333,14 @@ module Xlsxrb
|
|
|
309
333
|
end
|
|
310
334
|
|
|
311
335
|
# Returns hyperlinks for the first (or given) sheet.
|
|
336
|
+
# : (?sheet: untyped?) -> untyped
|
|
312
337
|
def hyperlinks(sheet: nil)
|
|
313
338
|
sheet_name = sheet || @sheet_order.first
|
|
314
339
|
@hyperlinks[sheet_name] || {}
|
|
315
340
|
end
|
|
316
341
|
|
|
317
342
|
# Sets an autoFilter range (e.g. "A1:B10") for the given sheet.
|
|
343
|
+
# : (untyped range, ?sheet: untyped?) -> untyped
|
|
318
344
|
def set_auto_filter(range, sheet: nil)
|
|
319
345
|
raise ArgumentError, "range must be a String like 'A1:B10'" unless range.is_a?(String) && range.match?(/\A[A-Z]+\d+:[A-Z]+\d+\z/)
|
|
320
346
|
|
|
@@ -325,6 +351,7 @@ module Xlsxrb
|
|
|
325
351
|
end
|
|
326
352
|
|
|
327
353
|
# Returns the autoFilter range for the first (or given) sheet.
|
|
354
|
+
# : (?sheet: untyped?) -> untyped
|
|
328
355
|
def auto_filter(sheet: nil)
|
|
329
356
|
sheet_name = sheet || @sheet_order.first
|
|
330
357
|
@auto_filters[sheet_name]
|
|
@@ -339,6 +366,7 @@ module Xlsxrb
|
|
|
339
366
|
# { type: :custom, filters: [{ operator: "greaterThan", val: "10" }, { operator: "lessThan", val: "100" }], and: true }
|
|
340
367
|
# { type: :dynamic, dynamic_type: "today" }
|
|
341
368
|
# { type: :top10, top: true, percent: false, val: 10 }
|
|
369
|
+
# : (untyped col_id, untyped filter, ?sheet: untyped?) -> untyped
|
|
342
370
|
def add_filter_column(col_id, filter, sheet: nil)
|
|
343
371
|
sheet_name = sheet || @sheet_order.first
|
|
344
372
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @filter_columns.key?(sheet_name)
|
|
@@ -347,6 +375,7 @@ module Xlsxrb
|
|
|
347
375
|
end
|
|
348
376
|
|
|
349
377
|
# Returns filter columns for the first (or given) sheet.
|
|
378
|
+
# : (?sheet: untyped?) -> untyped
|
|
350
379
|
def filter_columns(sheet: nil)
|
|
351
380
|
sheet_name = sheet || @sheet_order.first
|
|
352
381
|
@filter_columns[sheet_name] || {}
|
|
@@ -354,6 +383,7 @@ module Xlsxrb
|
|
|
354
383
|
|
|
355
384
|
# Sets a sort state for the sheet. ref: sort range, sort_conditions: array of { ref:, descending: }.
|
|
356
385
|
# Options: column_sort:, case_sensitive:, sort_method:
|
|
386
|
+
# : (untyped ref, untyped sort_conditions, ?sheet: untyped?, **untyped opts) -> untyped
|
|
357
387
|
def set_sort_state(ref, sort_conditions, sheet: nil, **opts)
|
|
358
388
|
sheet_name = sheet || @sheet_order.first
|
|
359
389
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sort_state.key?(sheet_name)
|
|
@@ -366,12 +396,14 @@ module Xlsxrb
|
|
|
366
396
|
end
|
|
367
397
|
|
|
368
398
|
# Returns sort state for the first (or given) sheet.
|
|
399
|
+
# : (?sheet: untyped?) -> untyped
|
|
369
400
|
def sort_state(sheet: nil)
|
|
370
401
|
sheet_name = sheet || @sheet_order.first
|
|
371
402
|
@sort_state[sheet_name]
|
|
372
403
|
end
|
|
373
404
|
|
|
374
405
|
# Registers a custom number format and returns its numFmtId (starting at 164).
|
|
406
|
+
# : (untyped format_code) -> untyped
|
|
375
407
|
def add_number_format(format_code)
|
|
376
408
|
existing = @num_fmts.find { |nf| nf[:format_code] == format_code }
|
|
377
409
|
return existing[:num_fmt_id] if existing
|
|
@@ -382,6 +414,7 @@ module Xlsxrb
|
|
|
382
414
|
end
|
|
383
415
|
|
|
384
416
|
# Sets a number format on a cell. num_fmt_id is from add_number_format or a built-in id.
|
|
417
|
+
# : (untyped cell_address, untyped num_fmt_id, ?sheet: untyped?) -> untyped
|
|
385
418
|
def set_cell_format(cell_address, num_fmt_id, sheet: nil)
|
|
386
419
|
validate_cell_address!(cell_address)
|
|
387
420
|
sheet_name = sheet || @sheet_order.first
|
|
@@ -391,6 +424,7 @@ module Xlsxrb
|
|
|
391
424
|
end
|
|
392
425
|
|
|
393
426
|
# Registers a font and returns its font_id. Opts: bold, italic, sz, color, name.
|
|
427
|
+
# : (**untyped opts) -> untyped
|
|
394
428
|
def add_font(**opts)
|
|
395
429
|
existing = @fonts.index(opts)
|
|
396
430
|
return existing if existing
|
|
@@ -400,6 +434,7 @@ module Xlsxrb
|
|
|
400
434
|
end
|
|
401
435
|
|
|
402
436
|
# Registers a fill and returns its fill_id. Opts: pattern, fg_color, bg_color.
|
|
437
|
+
# : (**untyped opts) -> untyped
|
|
403
438
|
def add_fill(**opts)
|
|
404
439
|
existing = @fills.index(opts)
|
|
405
440
|
return existing if existing
|
|
@@ -410,6 +445,7 @@ module Xlsxrb
|
|
|
410
445
|
|
|
411
446
|
# Registers a border and returns its border_id.
|
|
412
447
|
# Opts: left, right, top, bottom (each a hash with :style and optional :color).
|
|
448
|
+
# : (**untyped opts) -> untyped
|
|
413
449
|
def add_border(**opts)
|
|
414
450
|
existing = @borders.index(opts)
|
|
415
451
|
return existing if existing
|
|
@@ -420,6 +456,7 @@ module Xlsxrb
|
|
|
420
456
|
|
|
421
457
|
# Registers a cell style (xf entry) and returns its index for use with set_cell_style.
|
|
422
458
|
# Opts: font_id, fill_id, border_id, num_fmt_id, alignment (hash with horizontal, vertical, wrap_text, text_rotation, indent, shrink_to_fit).
|
|
459
|
+
# : (**untyped opts) -> untyped
|
|
423
460
|
def add_cell_style(**opts)
|
|
424
461
|
entry = {
|
|
425
462
|
num_fmt_id: opts[:num_fmt_id] || 0,
|
|
@@ -441,6 +478,7 @@ module Xlsxrb
|
|
|
441
478
|
|
|
442
479
|
# Registers a base style definition (cellStyleXf) and a named cellStyle.
|
|
443
480
|
# Returns the xfId for the new base style.
|
|
481
|
+
# : (name: untyped, ?num_fmt_id: ::Integer, ?font_id: ::Integer, ?fill_id: ::Integer, ?border_id: ::Integer, ?builtin_id: untyped?, ?i_level: untyped?, ?hidden: untyped?, ?custom_builtin: untyped?) -> untyped
|
|
444
482
|
def add_named_cell_style(name:, num_fmt_id: 0, font_id: 0, fill_id: 0, border_id: 0, builtin_id: nil,
|
|
445
483
|
i_level: nil, hidden: nil, custom_builtin: nil)
|
|
446
484
|
entry = { num_fmt_id: num_fmt_id, font_id: font_id, fill_id: fill_id, border_id: border_id }
|
|
@@ -456,6 +494,7 @@ module Xlsxrb
|
|
|
456
494
|
end
|
|
457
495
|
|
|
458
496
|
# Sets a cell style by xf index (from add_cell_style).
|
|
497
|
+
# : (untyped cell_address, untyped style_id, ?sheet: untyped?) -> untyped
|
|
459
498
|
def set_cell_style(cell_address, style_id, sheet: nil)
|
|
460
499
|
validate_cell_address!(cell_address)
|
|
461
500
|
sheet_name = sheet || @sheet_order.first
|
|
@@ -465,6 +504,7 @@ module Xlsxrb
|
|
|
465
504
|
end
|
|
466
505
|
|
|
467
506
|
# Marks a cell as containing phonetic text (ph="1" on the <c> element).
|
|
507
|
+
# : (untyped cell_address, ?sheet: untyped?) -> untyped
|
|
468
508
|
def set_cell_phonetic(cell_address, sheet: nil)
|
|
469
509
|
validate_cell_address!(cell_address)
|
|
470
510
|
sheet_name = sheet || @sheet_order.first
|
|
@@ -475,6 +515,7 @@ module Xlsxrb
|
|
|
475
515
|
|
|
476
516
|
# Registers a differential format (dxf) for conditional formatting. Returns dxf_id.
|
|
477
517
|
# Opts: font (hash), fill (hash), border (hash), num_fmt (hash).
|
|
518
|
+
# : (**untyped opts) -> untyped
|
|
478
519
|
def add_dxf(**opts)
|
|
479
520
|
@dxfs << opts
|
|
480
521
|
@dxfs.size - 1
|
|
@@ -482,29 +523,34 @@ module Xlsxrb
|
|
|
482
523
|
|
|
483
524
|
# Sets the indexed colors palette (array of ARGB hex strings, e.g. ["FF000000", "FFFFFFFF"]).
|
|
484
525
|
# rubocop:disable Naming/AccessorMethodName
|
|
526
|
+
# : (untyped colors) -> untyped
|
|
485
527
|
def set_indexed_colors(colors)
|
|
486
528
|
@indexed_colors = colors
|
|
487
529
|
end
|
|
488
530
|
# rubocop:enable Naming/AccessorMethodName
|
|
489
531
|
|
|
490
532
|
# Returns the indexed colors palette.
|
|
533
|
+
# : () -> untyped
|
|
491
534
|
def indexed_colors
|
|
492
535
|
@indexed_colors.dup
|
|
493
536
|
end
|
|
494
537
|
|
|
495
538
|
# Sets the MRU (most recently used) colors (array of color hashes, e.g. [{rgb: "FFFF0000"}]).
|
|
496
539
|
# rubocop:disable Naming/AccessorMethodName
|
|
540
|
+
# : (untyped colors) -> untyped
|
|
497
541
|
def set_mru_colors(colors)
|
|
498
542
|
@mru_colors = colors
|
|
499
543
|
end
|
|
500
544
|
# rubocop:enable Naming/AccessorMethodName
|
|
501
545
|
|
|
502
546
|
# Returns the MRU colors.
|
|
547
|
+
# : () -> untyped
|
|
503
548
|
def mru_colors
|
|
504
549
|
@mru_colors.map(&:dup)
|
|
505
550
|
end
|
|
506
551
|
|
|
507
552
|
# Sets table styles options (defaultTableStyle, defaultPivotStyle).
|
|
553
|
+
# : (untyped name, untyped value) -> untyped
|
|
508
554
|
def set_table_styles_option(name, value)
|
|
509
555
|
raise ArgumentError, "name must be a Symbol" unless name.is_a?(Symbol)
|
|
510
556
|
|
|
@@ -513,6 +559,7 @@ module Xlsxrb
|
|
|
513
559
|
|
|
514
560
|
# Adds a table style definition. Returns the style name.
|
|
515
561
|
# elements: array of { type:, dxf_id:, size: }
|
|
562
|
+
# : (name: untyped, ?elements: untyped, ?pivot: untyped?, ?table: untyped?) -> untyped
|
|
516
563
|
def add_table_style(name:, elements: [], pivot: nil, table: nil)
|
|
517
564
|
@table_styles[:styles] ||= []
|
|
518
565
|
style = { name: name, elements: elements }
|
|
@@ -523,6 +570,7 @@ module Xlsxrb
|
|
|
523
570
|
end
|
|
524
571
|
|
|
525
572
|
# Returns table styles configuration.
|
|
573
|
+
# : () -> untyped
|
|
526
574
|
def table_styles
|
|
527
575
|
deep_copy = {}
|
|
528
576
|
@table_styles.each do |k, v|
|
|
@@ -532,40 +580,47 @@ module Xlsxrb
|
|
|
532
580
|
end
|
|
533
581
|
|
|
534
582
|
# Sets a core property.
|
|
535
|
-
|
|
583
|
+
# : (untyped name, untyped value) -> untyped
|
|
584
|
+
def core_property(name, value)
|
|
536
585
|
raise ArgumentError, "name must be a Symbol" unless name.is_a?(Symbol)
|
|
537
586
|
|
|
538
587
|
@core_properties[name] = value
|
|
539
588
|
end
|
|
540
589
|
|
|
541
590
|
# Returns core properties hash.
|
|
591
|
+
# : () -> untyped
|
|
542
592
|
def core_properties
|
|
543
593
|
@core_properties.dup
|
|
544
594
|
end
|
|
545
595
|
|
|
546
596
|
# Sets an app property.
|
|
547
|
-
|
|
597
|
+
# : (untyped name, untyped value) -> untyped
|
|
598
|
+
def app_property(name, value)
|
|
548
599
|
raise ArgumentError, "name must be a Symbol" unless name.is_a?(Symbol)
|
|
549
600
|
|
|
550
601
|
@app_properties[name] = value
|
|
551
602
|
end
|
|
552
603
|
|
|
553
604
|
# Returns app properties hash.
|
|
605
|
+
# : () -> untyped
|
|
554
606
|
def app_properties
|
|
555
607
|
@app_properties.dup
|
|
556
608
|
end
|
|
557
609
|
|
|
558
610
|
# Adds a custom document property. type: :string (default), :number, :bool, :date.
|
|
559
|
-
|
|
611
|
+
# : (untyped name, untyped value, ?type: ::Symbol) -> untyped
|
|
612
|
+
def custom_property(name, value, type: :string)
|
|
560
613
|
@custom_properties << { name: name, value: value, type: type }
|
|
561
614
|
end
|
|
562
615
|
|
|
563
616
|
# Returns custom properties array.
|
|
617
|
+
# : () -> untyped
|
|
564
618
|
def custom_properties
|
|
565
619
|
@custom_properties.map(&:dup)
|
|
566
620
|
end
|
|
567
621
|
|
|
568
622
|
# Sets a sheet-level property (e.g. :tab_color, :summary_below, :summary_right).
|
|
623
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
569
624
|
def set_sheet_property(name, value, sheet: nil)
|
|
570
625
|
sheet_name = sheet || @sheet_order.first
|
|
571
626
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheet_properties.key?(sheet_name)
|
|
@@ -574,12 +629,14 @@ module Xlsxrb
|
|
|
574
629
|
end
|
|
575
630
|
|
|
576
631
|
# Returns sheet properties for the first (or given) sheet.
|
|
632
|
+
# : (?sheet: untyped?) -> untyped
|
|
577
633
|
def sheet_properties(sheet: nil)
|
|
578
634
|
sheet_name = sheet || @sheet_order.first
|
|
579
635
|
(@sheet_properties[sheet_name] || {}).dup
|
|
580
636
|
end
|
|
581
637
|
|
|
582
638
|
# Sets phonetic properties for a sheet (e.g. :font_id, :type, :alignment).
|
|
639
|
+
# : (untyped props, ?sheet: untyped?) -> untyped
|
|
583
640
|
def set_phonetic_properties(props, sheet: nil)
|
|
584
641
|
sheet_name = sheet || @sheet_order.first
|
|
585
642
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @phonetic_properties.key?(sheet_name)
|
|
@@ -588,12 +645,14 @@ module Xlsxrb
|
|
|
588
645
|
end
|
|
589
646
|
|
|
590
647
|
# Returns phonetic properties for the first (or given) sheet.
|
|
648
|
+
# : (?sheet: untyped?) -> untyped
|
|
591
649
|
def phonetic_properties(sheet: nil)
|
|
592
650
|
sheet_name = sheet || @sheet_order.first
|
|
593
651
|
@phonetic_properties[sheet_name]&.dup
|
|
594
652
|
end
|
|
595
653
|
|
|
596
654
|
# Sets a sheet format property (e.g. :default_row_height, :default_col_width, :base_col_width).
|
|
655
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
597
656
|
def set_sheet_format(name, value, sheet: nil)
|
|
598
657
|
sheet_name = sheet || @sheet_order.first
|
|
599
658
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheet_formats.key?(sheet_name)
|
|
@@ -602,12 +661,14 @@ module Xlsxrb
|
|
|
602
661
|
end
|
|
603
662
|
|
|
604
663
|
# Returns sheet format properties for the first (or given) sheet.
|
|
664
|
+
# : (?sheet: untyped?) -> untyped
|
|
605
665
|
def sheet_format(sheet: nil)
|
|
606
666
|
sheet_name = sheet || @sheet_order.first
|
|
607
667
|
(@sheet_formats[sheet_name] || {}).dup
|
|
608
668
|
end
|
|
609
669
|
|
|
610
670
|
# Sets a sheet view property (e.g. :show_grid_lines, :show_row_col_headers, :right_to_left, :zoom_scale).
|
|
671
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
611
672
|
def set_sheet_view(name, value, sheet: nil)
|
|
612
673
|
sheet_name = sheet || @sheet_order.first
|
|
613
674
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheet_views.key?(sheet_name)
|
|
@@ -616,12 +677,14 @@ module Xlsxrb
|
|
|
616
677
|
end
|
|
617
678
|
|
|
618
679
|
# Returns sheet view properties for the first (or given) sheet.
|
|
680
|
+
# : (?sheet: untyped?) -> untyped
|
|
619
681
|
def sheet_view(sheet: nil)
|
|
620
682
|
sheet_name = sheet || @sheet_order.first
|
|
621
683
|
(@sheet_views[sheet_name] || {}).dup
|
|
622
684
|
end
|
|
623
685
|
|
|
624
686
|
# Sets a freeze pane. row: rows to freeze from top, col: columns to freeze from left.
|
|
687
|
+
# : (?row: ::Integer, ?col: ::Integer, ?sheet: untyped?) -> untyped
|
|
625
688
|
def set_freeze_pane(row: 0, col: 0, sheet: nil)
|
|
626
689
|
sheet_name = sheet || @sheet_order.first
|
|
627
690
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @freeze_panes.key?(sheet_name)
|
|
@@ -631,6 +694,7 @@ module Xlsxrb
|
|
|
631
694
|
|
|
632
695
|
# Sets a split pane (non-frozen). x_split/y_split are in 1/20th of a point (twips).
|
|
633
696
|
# top_left_cell: the cell at top-left of the bottom-right pane.
|
|
697
|
+
# : (?x_split: ::Integer, ?y_split: ::Integer, ?top_left_cell: untyped?, ?sheet: untyped?) -> untyped
|
|
634
698
|
def set_split_pane(x_split: 0, y_split: 0, top_left_cell: nil, sheet: nil)
|
|
635
699
|
sheet_name = sheet || @sheet_order.first
|
|
636
700
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @freeze_panes.key?(sheet_name)
|
|
@@ -639,12 +703,14 @@ module Xlsxrb
|
|
|
639
703
|
end
|
|
640
704
|
|
|
641
705
|
# Returns freeze pane settings for the first (or given) sheet.
|
|
706
|
+
# : (?sheet: untyped?) -> untyped
|
|
642
707
|
def freeze_pane(sheet: nil)
|
|
643
708
|
sheet_name = sheet || @sheet_order.first
|
|
644
709
|
@freeze_panes[sheet_name]
|
|
645
710
|
end
|
|
646
711
|
|
|
647
712
|
# Sets the active cell selection.
|
|
713
|
+
# : (untyped active_cell, ?sqref: untyped?, ?pane: untyped?, ?active_cell_id: untyped?, ?sheet: untyped?) -> untyped
|
|
648
714
|
def set_selection(active_cell, sqref: nil, pane: nil, active_cell_id: nil, sheet: nil)
|
|
649
715
|
sheet_name = sheet || @sheet_order.first
|
|
650
716
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @selections.key?(sheet_name)
|
|
@@ -656,12 +722,14 @@ module Xlsxrb
|
|
|
656
722
|
end
|
|
657
723
|
|
|
658
724
|
# Returns selection for the first (or given) sheet.
|
|
725
|
+
# : (?sheet: untyped?) -> untyped
|
|
659
726
|
def selection(sheet: nil)
|
|
660
727
|
sheet_name = sheet || @sheet_order.first
|
|
661
728
|
@selections[sheet_name]
|
|
662
729
|
end
|
|
663
730
|
|
|
664
731
|
# Sets a print option (e.g. :grid_lines, :headings, :horizontal_centered, :vertical_centered).
|
|
732
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
665
733
|
def set_print_option(name, value, sheet: nil)
|
|
666
734
|
sheet_name = sheet || @sheet_order.first
|
|
667
735
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @print_options.key?(sheet_name)
|
|
@@ -670,12 +738,14 @@ module Xlsxrb
|
|
|
670
738
|
end
|
|
671
739
|
|
|
672
740
|
# Returns print options for the first (or given) sheet.
|
|
741
|
+
# : (?sheet: untyped?) -> untyped
|
|
673
742
|
def print_options(sheet: nil)
|
|
674
743
|
sheet_name = sheet || @sheet_order.first
|
|
675
744
|
(@print_options[sheet_name] || {}).dup
|
|
676
745
|
end
|
|
677
746
|
|
|
678
747
|
# Sets page margins (all values in inches).
|
|
748
|
+
# : (?left: untyped?, ?right: untyped?, ?top: untyped?, ?bottom: untyped?, ?header: untyped?, ?footer: untyped?, ?sheet: untyped?) -> untyped
|
|
679
749
|
def set_page_margins(left: nil, right: nil, top: nil, bottom: nil, header: nil, footer: nil, sheet: nil)
|
|
680
750
|
sheet_name = sheet || @sheet_order.first
|
|
681
751
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @page_margins.key?(sheet_name)
|
|
@@ -691,12 +761,14 @@ module Xlsxrb
|
|
|
691
761
|
end
|
|
692
762
|
|
|
693
763
|
# Returns page margins for the first (or given) sheet.
|
|
764
|
+
# : (?sheet: untyped?) -> untyped
|
|
694
765
|
def page_margins(sheet: nil)
|
|
695
766
|
sheet_name = sheet || @sheet_order.first
|
|
696
767
|
@page_margins[sheet_name]
|
|
697
768
|
end
|
|
698
769
|
|
|
699
770
|
# Sets a page setup property (e.g. :orientation, :paper_size, :scale, :fit_to_width, :fit_to_height).
|
|
771
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
700
772
|
def set_page_setup(name, value, sheet: nil)
|
|
701
773
|
sheet_name = sheet || @sheet_order.first
|
|
702
774
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @page_setup.key?(sheet_name)
|
|
@@ -705,12 +777,14 @@ module Xlsxrb
|
|
|
705
777
|
end
|
|
706
778
|
|
|
707
779
|
# Returns page setup for the first (or given) sheet.
|
|
780
|
+
# : (?sheet: untyped?) -> untyped
|
|
708
781
|
def page_setup(sheet: nil)
|
|
709
782
|
sheet_name = sheet || @sheet_order.first
|
|
710
783
|
(@page_setup[sheet_name] || {}).dup
|
|
711
784
|
end
|
|
712
785
|
|
|
713
786
|
# Sets header/footer text (:odd_header, :odd_footer, :even_header, :even_footer).
|
|
787
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
714
788
|
def set_header_footer(name, value, sheet: nil)
|
|
715
789
|
sheet_name = sheet || @sheet_order.first
|
|
716
790
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @header_footer.key?(sheet_name)
|
|
@@ -719,12 +793,14 @@ module Xlsxrb
|
|
|
719
793
|
end
|
|
720
794
|
|
|
721
795
|
# Returns header/footer for the first (or given) sheet.
|
|
796
|
+
# : (?sheet: untyped?) -> untyped
|
|
722
797
|
def header_footer(sheet: nil)
|
|
723
798
|
sheet_name = sheet || @sheet_order.first
|
|
724
799
|
(@header_footer[sheet_name] || {}).dup
|
|
725
800
|
end
|
|
726
801
|
|
|
727
802
|
# Adds a row break (page break before a given row number).
|
|
803
|
+
# : (untyped row_num, ?sheet: untyped?) -> untyped
|
|
728
804
|
def add_row_break(row_num, sheet: nil)
|
|
729
805
|
sheet_name = sheet || @sheet_order.first
|
|
730
806
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @row_breaks.key?(sheet_name)
|
|
@@ -733,12 +809,14 @@ module Xlsxrb
|
|
|
733
809
|
end
|
|
734
810
|
|
|
735
811
|
# Returns row breaks for the first (or given) sheet.
|
|
812
|
+
# : (?sheet: untyped?) -> untyped
|
|
736
813
|
def row_breaks(sheet: nil)
|
|
737
814
|
sheet_name = sheet || @sheet_order.first
|
|
738
815
|
@row_breaks[sheet_name] || []
|
|
739
816
|
end
|
|
740
817
|
|
|
741
818
|
# Adds a column break (page break before a given column index, 1-based).
|
|
819
|
+
# : (untyped col_index, ?sheet: untyped?) -> untyped
|
|
742
820
|
def add_col_break(col_index, sheet: nil)
|
|
743
821
|
sheet_name = sheet || @sheet_order.first
|
|
744
822
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @col_breaks.key?(sheet_name)
|
|
@@ -747,6 +825,7 @@ module Xlsxrb
|
|
|
747
825
|
end
|
|
748
826
|
|
|
749
827
|
# Returns column breaks for the first (or given) sheet.
|
|
828
|
+
# : (?sheet: untyped?) -> untyped
|
|
750
829
|
def col_breaks(sheet: nil)
|
|
751
830
|
sheet_name = sheet || @sheet_order.first
|
|
752
831
|
@col_breaks[sheet_name] || []
|
|
@@ -756,6 +835,7 @@ module Xlsxrb
|
|
|
756
835
|
# sqref: cell range (e.g. "A1:A100")
|
|
757
836
|
# Options: type:, operator:, formula1:, formula2:, allow_blank:, show_input_message:,
|
|
758
837
|
# show_error_message:, error_style:, error_title:, error:, prompt_title:, prompt:
|
|
838
|
+
# : (untyped sqref, ?sheet: untyped?, **untyped opts) -> untyped
|
|
759
839
|
def add_data_validation(sqref, sheet: nil, **opts)
|
|
760
840
|
sheet_name = sheet || @sheet_order.first
|
|
761
841
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @data_validations.key?(sheet_name)
|
|
@@ -764,12 +844,14 @@ module Xlsxrb
|
|
|
764
844
|
end
|
|
765
845
|
|
|
766
846
|
# Returns data validations for the first (or given) sheet.
|
|
847
|
+
# : (?sheet: untyped?) -> untyped
|
|
767
848
|
def data_validations(sheet: nil)
|
|
768
849
|
sheet_name = sheet || @sheet_order.first
|
|
769
850
|
@data_validations[sheet_name] || []
|
|
770
851
|
end
|
|
771
852
|
|
|
772
853
|
# Sets a data validations container option (e.g. disable_prompts, x_window, y_window).
|
|
854
|
+
# : (untyped name, untyped value, ?sheet: untyped?) -> untyped
|
|
773
855
|
def set_data_validations_option(name, value, sheet: nil)
|
|
774
856
|
sheet_name = sheet || @sheet_order.first
|
|
775
857
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @data_validations_options.key?(sheet_name)
|
|
@@ -780,6 +862,7 @@ module Xlsxrb
|
|
|
780
862
|
# Adds a conditional formatting rule to the specified range.
|
|
781
863
|
# Options: type (:cell_is, :expression, :color_scale, :data_bar, :icon_set),
|
|
782
864
|
# operator, priority, formula/formulas, format_id, color_scale, data_bar, icon_set.
|
|
865
|
+
# : (untyped sqref, ?sheet: untyped?, **untyped opts) -> untyped
|
|
783
866
|
def add_conditional_format(sqref, sheet: nil, **opts)
|
|
784
867
|
sheet_name = sheet || @sheet_order.first
|
|
785
868
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @conditional_formats.key?(sheet_name)
|
|
@@ -788,6 +871,7 @@ module Xlsxrb
|
|
|
788
871
|
end
|
|
789
872
|
|
|
790
873
|
# Returns conditional formatting rules for the first (or given) sheet.
|
|
874
|
+
# : (?sheet: untyped?) -> untyped
|
|
791
875
|
def conditional_formats(sheet: nil)
|
|
792
876
|
sheet_name = sheet || @sheet_order.first
|
|
793
877
|
@conditional_formats[sheet_name] || []
|
|
@@ -795,6 +879,7 @@ module Xlsxrb
|
|
|
795
879
|
|
|
796
880
|
# Adds a table definition to a sheet.
|
|
797
881
|
# columns: array of column name strings.
|
|
882
|
+
# : (untyped ref, columns: untyped, ?name: untyped?, ?display_name: untyped?, ?sheet: untyped?, ?totals_row_count: ::Integer, ?style: untyped?, **untyped opts) -> untyped
|
|
798
883
|
def add_table(ref, columns:, name: nil, display_name: nil, sheet: nil, totals_row_count: 0, style: nil, **opts)
|
|
799
884
|
sheet_name = sheet || @sheet_order.first
|
|
800
885
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @tables.key?(sheet_name)
|
|
@@ -817,17 +902,20 @@ module Xlsxrb
|
|
|
817
902
|
end
|
|
818
903
|
|
|
819
904
|
# Returns table definitions for the first (or given) sheet.
|
|
905
|
+
# : (?sheet: untyped?) -> untyped
|
|
820
906
|
def tables(sheet: nil)
|
|
821
907
|
sheet_name = sheet || @sheet_order.first
|
|
822
908
|
@tables[sheet_name] || []
|
|
823
909
|
end
|
|
824
910
|
|
|
825
911
|
# Enables shared string table mode (strings stored in sharedStrings.xml).
|
|
912
|
+
# : () -> untyped
|
|
826
913
|
def use_shared_strings!
|
|
827
914
|
@use_shared_strings = true
|
|
828
915
|
end
|
|
829
916
|
|
|
830
917
|
# Sets a sheet's visibility state (:visible, :hidden, :very_hidden).
|
|
918
|
+
# : (untyped sheet_name, untyped state) -> untyped
|
|
831
919
|
def set_sheet_state(sheet_name, state)
|
|
832
920
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
833
921
|
raise ArgumentError, "state must be :visible, :hidden, or :very_hidden" unless %i[visible hidden very_hidden].include?(state)
|
|
@@ -836,11 +924,13 @@ module Xlsxrb
|
|
|
836
924
|
end
|
|
837
925
|
|
|
838
926
|
# Returns the sheet state for a given sheet.
|
|
927
|
+
# : (untyped sheet_name) -> untyped
|
|
839
928
|
def sheet_state(sheet_name)
|
|
840
929
|
@sheet_states[sheet_name] || :visible
|
|
841
930
|
end
|
|
842
931
|
|
|
843
932
|
# Adds a defined name. Options: sheet: (local scope), hidden: true, value: (formula or constant).
|
|
933
|
+
# : (untyped name, untyped value, ?sheet: untyped?, ?hidden: bool, **untyped opts) -> untyped
|
|
844
934
|
def add_defined_name(name, value, sheet: nil, hidden: false, **opts)
|
|
845
935
|
entry = { name: name, value: value, hidden: hidden }
|
|
846
936
|
%i[comment description function vb_procedure xlm shortcut_key publish_to_server workbook_parameter
|
|
@@ -857,12 +947,14 @@ module Xlsxrb
|
|
|
857
947
|
end
|
|
858
948
|
|
|
859
949
|
# Returns defined names array.
|
|
950
|
+
# : () -> untyped
|
|
860
951
|
def defined_names
|
|
861
952
|
@defined_names.map(&:dup)
|
|
862
953
|
end
|
|
863
954
|
|
|
864
955
|
# Sets the print area for a sheet. range should be like "A1:D20".
|
|
865
956
|
# Generates the _xlnm.Print_Area defined name automatically.
|
|
957
|
+
# : (untyped range, ?sheet: untyped?) -> untyped
|
|
866
958
|
def set_print_area(range, sheet: nil)
|
|
867
959
|
sheet_name = sheet || @sheet_order.first
|
|
868
960
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -876,6 +968,7 @@ module Xlsxrb
|
|
|
876
968
|
|
|
877
969
|
# Sets print titles (rows and/or columns to repeat on each page).
|
|
878
970
|
# rows: "1:3" repeats rows 1-3, cols: "A:B" repeats columns A-B.
|
|
971
|
+
# : (?rows: untyped?, ?cols: untyped?, ?sheet: untyped?) -> untyped
|
|
879
972
|
def set_print_titles(rows: nil, cols: nil, sheet: nil)
|
|
880
973
|
sheet_name = sheet || @sheet_order.first
|
|
881
974
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -892,61 +985,73 @@ module Xlsxrb
|
|
|
892
985
|
end
|
|
893
986
|
|
|
894
987
|
# Sets a workbook property (e.g. :date1904, :default_theme_version).
|
|
988
|
+
# : (untyped name, untyped value) -> untyped
|
|
895
989
|
def set_workbook_property(name, value)
|
|
896
990
|
@workbook_properties[name] = value
|
|
897
991
|
end
|
|
898
992
|
|
|
899
993
|
# Returns workbook properties hash.
|
|
994
|
+
# : () -> untyped
|
|
900
995
|
def workbook_properties
|
|
901
996
|
@workbook_properties.dup
|
|
902
997
|
end
|
|
903
998
|
|
|
904
999
|
# Sets a file version property (e.g. :app_name, :last_edited, :lowest_edited, :rup_build, :code_name).
|
|
1000
|
+
# : (untyped name, untyped value) -> untyped
|
|
905
1001
|
def set_file_version(name, value)
|
|
906
1002
|
@file_version[name] = value
|
|
907
1003
|
end
|
|
908
1004
|
|
|
909
1005
|
# Returns file version hash.
|
|
1006
|
+
# : () -> untyped
|
|
910
1007
|
def file_version
|
|
911
1008
|
@file_version.dup
|
|
912
1009
|
end
|
|
913
1010
|
|
|
914
1011
|
# Sets a file sharing property (e.g. :read_only_recommended, :user_name).
|
|
1012
|
+
# : (untyped name, untyped value) -> untyped
|
|
915
1013
|
def set_file_sharing(name, value)
|
|
916
1014
|
@file_sharing[name] = value
|
|
917
1015
|
end
|
|
918
1016
|
|
|
919
1017
|
# Returns file sharing hash.
|
|
1018
|
+
# : () -> untyped
|
|
920
1019
|
def file_sharing
|
|
921
1020
|
@file_sharing.dup
|
|
922
1021
|
end
|
|
923
1022
|
|
|
924
1023
|
# Sets a workbook view property (e.g. :active_tab, :first_sheet).
|
|
1024
|
+
# : (untyped name, untyped value) -> untyped
|
|
925
1025
|
def set_workbook_view(name, value)
|
|
926
1026
|
@workbook_views[name] = value
|
|
927
1027
|
end
|
|
928
1028
|
|
|
929
1029
|
# Returns workbook view properties hash.
|
|
1030
|
+
# : () -> untyped
|
|
930
1031
|
def workbook_views
|
|
931
1032
|
@workbook_views.dup
|
|
932
1033
|
end
|
|
933
1034
|
|
|
934
1035
|
# Sets a calc property (e.g. :calc_id, :full_calc_on_load).
|
|
1036
|
+
# : (untyped name, untyped value) -> untyped
|
|
935
1037
|
def set_calc_property(name, value)
|
|
936
1038
|
@calc_properties[name] = value
|
|
937
1039
|
end
|
|
938
1040
|
|
|
939
1041
|
# Returns calc properties hash.
|
|
1042
|
+
# : () -> untyped
|
|
940
1043
|
def calc_properties
|
|
941
1044
|
@calc_properties.dup
|
|
942
1045
|
end
|
|
943
1046
|
|
|
944
1047
|
# Sets a file recovery property (e.g. :auto_recover, :crash_save).
|
|
1048
|
+
# : (untyped name, untyped value) -> untyped
|
|
945
1049
|
def set_file_recovery_property(name, value)
|
|
946
1050
|
@file_recovery_properties[name] = value
|
|
947
1051
|
end
|
|
948
1052
|
|
|
949
1053
|
# Returns file recovery properties hash.
|
|
1054
|
+
# : () -> untyped
|
|
950
1055
|
def file_recovery_properties
|
|
951
1056
|
@file_recovery_properties.dup
|
|
952
1057
|
end
|
|
@@ -956,6 +1061,7 @@ module Xlsxrb
|
|
|
956
1061
|
# :format_rows, :insert_columns, :insert_rows, :insert_hyperlinks,
|
|
957
1062
|
# :delete_columns, :delete_rows, :select_locked_cells, :sort, :auto_filter,
|
|
958
1063
|
# :pivot_tables, :select_unlocked_cells, :algorithm_name, :hash_value, :salt_value, :spin_count
|
|
1064
|
+
# : (?sheet: untyped?, **untyped opts) -> untyped
|
|
959
1065
|
def set_sheet_protection(sheet: nil, **opts)
|
|
960
1066
|
sheet_name = sheet || @sheet_order.first
|
|
961
1067
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -964,6 +1070,7 @@ module Xlsxrb
|
|
|
964
1070
|
end
|
|
965
1071
|
|
|
966
1072
|
# Returns sheet protection settings for the given sheet.
|
|
1073
|
+
# : (?sheet: untyped?) -> untyped
|
|
967
1074
|
def sheet_protection(sheet: nil)
|
|
968
1075
|
sheet_name = sheet || @sheet_order.first
|
|
969
1076
|
@sheet_protection[sheet_name]&.dup
|
|
@@ -972,6 +1079,7 @@ module Xlsxrb
|
|
|
972
1079
|
# Adds a protected range to the given sheet.
|
|
973
1080
|
# Required: name:, sqref:
|
|
974
1081
|
# Optional: algorithm_name:, hash_value:, salt_value:, spin_count:, security_descriptors: []
|
|
1082
|
+
# : (?sheet: untyped?, **untyped opts) -> untyped
|
|
975
1083
|
def add_protected_range(sheet: nil, **opts)
|
|
976
1084
|
sheet_name = sheet || @sheet_order.first
|
|
977
1085
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -982,12 +1090,14 @@ module Xlsxrb
|
|
|
982
1090
|
end
|
|
983
1091
|
|
|
984
1092
|
# Returns protected ranges for the given sheet.
|
|
1093
|
+
# : (?sheet: untyped?) -> untyped
|
|
985
1094
|
def protected_ranges(sheet: nil)
|
|
986
1095
|
sheet_name = sheet || @sheet_order.first
|
|
987
1096
|
(@protected_ranges[sheet_name] || []).map(&:dup)
|
|
988
1097
|
end
|
|
989
1098
|
|
|
990
1099
|
# Adds a cell watch to the given sheet.
|
|
1100
|
+
# : (untyped cell_ref, ?sheet: untyped?) -> untyped
|
|
991
1101
|
def add_cell_watch(cell_ref, sheet: nil)
|
|
992
1102
|
sheet_name = sheet || @sheet_order.first
|
|
993
1103
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -996,6 +1106,7 @@ module Xlsxrb
|
|
|
996
1106
|
end
|
|
997
1107
|
|
|
998
1108
|
# Returns cell watches for the given sheet.
|
|
1109
|
+
# : (?sheet: untyped?) -> untyped
|
|
999
1110
|
def cell_watches(sheet: nil)
|
|
1000
1111
|
sheet_name = sheet || @sheet_order.first
|
|
1001
1112
|
(@cell_watches[sheet_name] || []).dup
|
|
@@ -1004,6 +1115,7 @@ module Xlsxrb
|
|
|
1004
1115
|
# Adds an ignored error entry for the given sheet.
|
|
1005
1116
|
# Options: sqref:, eval_error:, two_digit_text_year:, number_stored_as_text:, formula:,
|
|
1006
1117
|
# formula_range:, unlocked_formula:, empty_cell_reference:, list_data_validation:, calculated_column:
|
|
1118
|
+
# : (?sheet: untyped?, **untyped opts) -> untyped
|
|
1007
1119
|
def add_ignored_error(sheet: nil, **opts)
|
|
1008
1120
|
sheet_name = sheet || @sheet_order.first
|
|
1009
1121
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -1013,6 +1125,7 @@ module Xlsxrb
|
|
|
1013
1125
|
end
|
|
1014
1126
|
|
|
1015
1127
|
# Returns ignored errors for the given sheet.
|
|
1128
|
+
# : (?sheet: untyped?) -> untyped
|
|
1016
1129
|
def ignored_errors(sheet: nil)
|
|
1017
1130
|
sheet_name = sheet || @sheet_order.first
|
|
1018
1131
|
(@ignored_errors[sheet_name] || []).dup
|
|
@@ -1020,6 +1133,7 @@ module Xlsxrb
|
|
|
1020
1133
|
|
|
1021
1134
|
# Sets data consolidation options for the given sheet.
|
|
1022
1135
|
# Options: function:, start_labels:, top_labels:, link:, data_refs: [{ref:, name:, sheet:}]
|
|
1136
|
+
# : (?sheet: untyped?, **untyped opts) -> untyped
|
|
1023
1137
|
def set_data_consolidate(sheet: nil, **opts)
|
|
1024
1138
|
sheet_name = sheet || @sheet_order.first
|
|
1025
1139
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -1028,6 +1142,7 @@ module Xlsxrb
|
|
|
1028
1142
|
end
|
|
1029
1143
|
|
|
1030
1144
|
# Returns data consolidation settings for the given sheet.
|
|
1145
|
+
# : (?sheet: untyped?) -> untyped
|
|
1031
1146
|
def data_consolidate(sheet: nil)
|
|
1032
1147
|
sheet_name = sheet || @sheet_order.first
|
|
1033
1148
|
@data_consolidate[sheet_name]&.dup
|
|
@@ -1035,6 +1150,7 @@ module Xlsxrb
|
|
|
1035
1150
|
|
|
1036
1151
|
# Sets scenarios for the given sheet.
|
|
1037
1152
|
# Options: current:, show:, sqref:, scenarios: [{name:, input_cells: [{r:, val:, ...}], ...}]
|
|
1153
|
+
# : (?sheet: untyped?, **untyped opts) -> untyped
|
|
1038
1154
|
def set_scenarios(sheet: nil, **opts)
|
|
1039
1155
|
sheet_name = sheet || @sheet_order.first
|
|
1040
1156
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @sheets.key?(sheet_name)
|
|
@@ -1043,6 +1159,7 @@ module Xlsxrb
|
|
|
1043
1159
|
end
|
|
1044
1160
|
|
|
1045
1161
|
# Returns scenarios for the given sheet.
|
|
1162
|
+
# : (?sheet: untyped?) -> untyped
|
|
1046
1163
|
def scenarios(sheet: nil)
|
|
1047
1164
|
sheet_name = sheet || @sheet_order.first
|
|
1048
1165
|
@scenarios[sheet_name]&.dup
|
|
@@ -1050,19 +1167,23 @@ module Xlsxrb
|
|
|
1050
1167
|
|
|
1051
1168
|
# Sets workbook protection options.
|
|
1052
1169
|
# Options: :lock_structure, :lock_windows, :password, :algorithm_name, :hash_value, :salt_value, :spin_count
|
|
1170
|
+
# : (**untyped opts) -> untyped
|
|
1053
1171
|
def set_workbook_protection(**opts)
|
|
1054
1172
|
@workbook_protection = opts
|
|
1055
1173
|
end
|
|
1056
1174
|
|
|
1057
1175
|
# Returns workbook protection settings.
|
|
1176
|
+
# : () -> untyped
|
|
1058
1177
|
def workbook_protection
|
|
1059
1178
|
@workbook_protection&.dup
|
|
1060
1179
|
end
|
|
1061
1180
|
|
|
1062
1181
|
# Returns ordered sheet names.
|
|
1182
|
+
# : untyped
|
|
1063
1183
|
attr_reader :sheet_order
|
|
1064
1184
|
|
|
1065
1185
|
# Adds a raw ZIP entry to be included in the output (for pass-through retention).
|
|
1186
|
+
# : (untyped path, untyped content, ?content_type: untyped?) -> (nil | untyped)
|
|
1066
1187
|
def add_raw_entry(path, content, content_type: nil)
|
|
1067
1188
|
@extra_entries[path] = content
|
|
1068
1189
|
return unless content_type
|
|
@@ -1077,6 +1198,7 @@ module Xlsxrb
|
|
|
1077
1198
|
|
|
1078
1199
|
# Copies all ZIP entries from an existing XLSX file as pass-through.
|
|
1079
1200
|
# Generated parts override pass-through parts with the same path.
|
|
1201
|
+
# : (untyped filepath) -> untyped
|
|
1080
1202
|
def copy_entries_from(filepath)
|
|
1081
1203
|
reader = Xlsxrb::Ooxml::Reader.new(filepath)
|
|
1082
1204
|
reader.entry_names.each do |name|
|
|
@@ -1091,6 +1213,7 @@ module Xlsxrb
|
|
|
1091
1213
|
# Inserts an image from file data into the given sheet.
|
|
1092
1214
|
# file_data: raw image bytes. ext: file extension (e.g. "png").
|
|
1093
1215
|
# from_col/from_row: anchor start. to_col/to_row: anchor end.
|
|
1216
|
+
# : (untyped file_data, ?ext: ::String, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, ?from_col_off: untyped?, ?from_row_off: untyped?, ?to_col_off: untyped?, ?to_row_off: untyped?, ?name: untyped?, ?description: untyped?, ?title: untyped?, ?hidden: untyped?, ?macro: untyped?, ?no_change_aspect: bool, ?no_crop: untyped?, ?line_color: untyped?, ?line_width: untyped?, ?rotation: untyped?, ?edit_as: untyped?, ?published: untyped?, ?locks_with_sheet: untyped?, ?prints_with_sheet: untyped?, ?src_rect: untyped?, ?alpha_mod_fix: untyped?, ?sheet: untyped?) -> untyped
|
|
1094
1217
|
def insert_image(file_data, ext: "png", from_col: 0, from_row: 0, to_col: 5, to_row: 10, from_col_off: nil, from_row_off: nil, to_col_off: nil, to_row_off: nil, name: nil, description: nil, title: nil, hidden: nil, macro: nil, no_change_aspect: true, no_crop: nil, line_color: nil, line_width: nil, rotation: nil, edit_as: nil, published: nil, locks_with_sheet: nil, prints_with_sheet: nil, src_rect: nil, alpha_mod_fix: nil, sheet: nil)
|
|
1095
1218
|
sheet_name = sheet || @sheet_order.first
|
|
1096
1219
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @images.key?(sheet_name)
|
|
@@ -1124,6 +1247,7 @@ module Xlsxrb
|
|
|
1124
1247
|
end
|
|
1125
1248
|
|
|
1126
1249
|
# Returns images for the first (or given) sheet.
|
|
1250
|
+
# : (?sheet: untyped?) -> untyped
|
|
1127
1251
|
def images(sheet: nil)
|
|
1128
1252
|
sheet_name = sheet || @sheet_order.first
|
|
1129
1253
|
@images[sheet_name] || []
|
|
@@ -1132,6 +1256,7 @@ module Xlsxrb
|
|
|
1132
1256
|
# Adds a chart to the given sheet.
|
|
1133
1257
|
# type: :bar, :line, :pie. title: chart title string.
|
|
1134
1258
|
# data_ref: e.g. "Sheet1!$A$1:$B$4". cat_ref/val_ref for explicit series.
|
|
1259
|
+
# : (?type: ::Symbol, ?title: untyped?, ?title_overlay: untyped?, ?title_font: untyped?, ?title_fill_color: untyped?, ?title_no_fill: untyped?, ?title_line_color: untyped?, ?title_line_width: untyped?, ?title_line_dash: untyped?, ?title_rotation: untyped?, ?auto_title_deleted: untyped?, ?cat_ref: untyped?, ?val_ref: untyped?, ?series: untyped?, ?legend: untyped?, ?data_labels: untyped?, ?cat_axis_title: untyped?, ?val_axis_title: untyped?, ?cat_axis_title_font: untyped?, ?cat_axis_title_fill: untyped?, ?cat_axis_title_no_fill: untyped?, ?cat_axis_title_line_color: untyped?, ?cat_axis_title_line_width: untyped?, ?cat_axis_title_line_dash: untyped?, ?cat_axis_title_rotation: untyped?, ?val_axis_title_font: untyped?, ?val_axis_title_fill: untyped?, ?val_axis_title_no_fill: untyped?, ?val_axis_title_line_color: untyped?, ?val_axis_title_line_width: untyped?, ?val_axis_title_line_dash: untyped?, ?val_axis_title_rotation: untyped?, ?cat_axis_tick_lbl_pos: untyped?, ?val_axis_tick_lbl_pos: untyped?, ?cat_axis_major_gridlines: untyped?, ?val_axis_major_gridlines: untyped?, ?cat_axis_minor_gridlines: untyped?, ?val_axis_minor_gridlines: untyped?, ?cat_axis_delete: untyped?, ?val_axis_delete: untyped?, ?cat_axis_orientation: untyped?, ?val_axis_orientation: untyped?, ?cat_axis_num_fmt: untyped?, ?val_axis_num_fmt: untyped?, ?cat_axis_major_tick_mark: untyped?, ?cat_axis_minor_tick_mark: untyped?, ?val_axis_major_tick_mark: untyped?, ?val_axis_minor_tick_mark: untyped?, ?cat_axis_crosses: untyped?, ?val_axis_crosses: untyped?, ?cat_axis_crosses_at: untyped?, ?val_axis_crosses_at: untyped?, ?cat_axis_tick_lbl_skip: untyped?, ?cat_axis_tick_mark_skip: untyped?, ?cat_axis_lbl_offset: untyped?, ?cat_axis_auto: untyped?, ?cat_axis_lbl_algn: untyped?, ?cat_axis_no_multi_lvl_lbl: untyped?, ?val_axis_cross_between: untyped?, ?val_axis_major_unit: untyped?, ?val_axis_minor_unit: untyped?, ?cat_axis_scaling_max: untyped?, ?cat_axis_scaling_min: untyped?, ?val_axis_scaling_max: untyped?, ?val_axis_scaling_min: untyped?, ?cat_axis_log_base: untyped?, ?val_axis_log_base: untyped?, ?val_axis_disp_units: untyped?, ?gap_width: untyped?, ?gap_depth: untyped?, ?overlap: untyped?, ?first_slice_ang: untyped?, ?hole_size: untyped?, ?smooth: untyped?, ?marker: untyped?, ?scatter_style: untyped?, ?radar_style: untyped?, ?bar_shape: untyped?, ?bubble_3d: untyped?, ?bubble_scale: untyped?, ?show_neg_bubbles: untyped?, ?size_represents: untyped?, ?wireframe: untyped?, ?grouping: untyped?, ?bar_dir: untyped?, ?vary_colors: untyped?, ?style: untyped?, ?rounded_corners: untyped?, ?view_3d: untyped?, ?cat_axis_pos: untyped?, ?val_axis_pos: untyped?, ?name: untyped?, ?description: untyped?, ?frame_title: untyped?, ?frame_hidden: untyped?, ?frame_macro: untyped?, ?frame_no_grp: untyped?, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, ?from_col_off: untyped?, ?from_row_off: untyped?, ?to_col_off: untyped?, ?to_row_off: untyped?, ?edit_as: untyped?, ?published: untyped?, ?locks_with_sheet: untyped?, ?prints_with_sheet: untyped?, ?plot_vis_only: untyped?, ?disp_blanks_as: untyped?, ?show_d_lbls_over_max: untyped?, ?data_table: untyped?, ?plot_area_fill: untyped?, ?plot_area_no_fill: untyped?, ?plot_area_line_color: untyped?, ?plot_area_line_width: untyped?, ?plot_area_line_dash: untyped?, ?plot_area_layout: untyped?, ?floor: untyped?, ?side_wall: untyped?, ?back_wall: untyped?, ?drop_lines: untyped?, ?hi_low_lines: untyped?, ?ser_lines: untyped?, ?up_down_bars: untyped?, ?band_fmts: untyped?, ?of_pie_type: untyped?, ?split_type: untyped?, ?split_pos: untyped?, ?cust_split: untyped?, ?second_pie_size: untyped?, ?cat_axis_label_rotation: untyped?, ?val_axis_label_rotation: untyped?, ?cat_axis_font: untyped?, ?val_axis_font: untyped?, ?cat_axis_line_color: untyped?, ?cat_axis_line_width: untyped?, ?cat_axis_line_dash: untyped?, ?val_axis_line_color: untyped?, ?val_axis_line_width: untyped?, ?val_axis_line_dash: untyped?, ?cat_axis_fill: untyped?, ?cat_axis_no_fill: untyped?, ?val_axis_fill: untyped?, ?val_axis_no_fill: untyped?, ?cat_axis_type: untyped?, ?cat_axis_base_time_unit: untyped?, ?cat_axis_major_time_unit: untyped?, ?cat_axis_minor_time_unit: untyped?, ?cat_axis_major_unit: untyped?, ?cat_axis_minor_unit: untyped?, ?chart_fill: untyped?, ?chart_no_fill: untyped?, ?chart_line_color: untyped?, ?chart_line_width: untyped?, ?chart_line_dash: untyped?, ?protection: untyped?, ?print_settings: untyped?, ?chart_font: untyped?, ?sheet: untyped?) -> untyped
|
|
1135
1260
|
def add_chart(type: :bar, title: nil, title_overlay: nil, title_font: nil, title_fill_color: nil, title_no_fill: nil, title_line_color: nil, title_line_width: nil, title_line_dash: nil, title_rotation: nil, auto_title_deleted: nil, cat_ref: nil, val_ref: nil, series: nil, legend: nil, data_labels: nil, cat_axis_title: nil, val_axis_title: nil, cat_axis_title_font: nil, cat_axis_title_fill: nil, cat_axis_title_no_fill: nil, cat_axis_title_line_color: nil, cat_axis_title_line_width: nil, cat_axis_title_line_dash: nil, cat_axis_title_rotation: nil, val_axis_title_font: nil, val_axis_title_fill: nil, val_axis_title_no_fill: nil, val_axis_title_line_color: nil, val_axis_title_line_width: nil, val_axis_title_line_dash: nil, val_axis_title_rotation: nil, cat_axis_tick_lbl_pos: nil, val_axis_tick_lbl_pos: nil, cat_axis_major_gridlines: nil, val_axis_major_gridlines: nil, cat_axis_minor_gridlines: nil, val_axis_minor_gridlines: nil, cat_axis_delete: nil, val_axis_delete: nil, cat_axis_orientation: nil, val_axis_orientation: nil, cat_axis_num_fmt: nil, val_axis_num_fmt: nil, cat_axis_major_tick_mark: nil, cat_axis_minor_tick_mark: nil, val_axis_major_tick_mark: nil, val_axis_minor_tick_mark: nil, cat_axis_crosses: nil, val_axis_crosses: nil, cat_axis_crosses_at: nil, val_axis_crosses_at: nil, cat_axis_tick_lbl_skip: nil, cat_axis_tick_mark_skip: nil, cat_axis_lbl_offset: nil, cat_axis_auto: nil, cat_axis_lbl_algn: nil, cat_axis_no_multi_lvl_lbl: nil, val_axis_cross_between: nil, val_axis_major_unit: nil, val_axis_minor_unit: nil, cat_axis_scaling_max: nil, cat_axis_scaling_min: nil, val_axis_scaling_max: nil, val_axis_scaling_min: nil, cat_axis_log_base: nil, val_axis_log_base: nil, val_axis_disp_units: nil, gap_width: nil, gap_depth: nil, overlap: nil, first_slice_ang: nil, hole_size: nil, smooth: nil, marker: nil, scatter_style: nil, radar_style: nil, bar_shape: nil, bubble_3d: nil, bubble_scale: nil, show_neg_bubbles: nil, size_represents: nil, wireframe: nil, grouping: nil, bar_dir: nil, vary_colors: nil, style: nil, rounded_corners: nil, view_3d: nil, cat_axis_pos: nil, val_axis_pos: nil, name: nil, description: nil, frame_title: nil, frame_hidden: nil, frame_macro: nil, frame_no_grp: nil, from_col: 0, from_row: 0, to_col: 10, to_row: 15, from_col_off: nil, from_row_off: nil, to_col_off: nil, to_row_off: nil, edit_as: nil, published: nil, locks_with_sheet: nil, prints_with_sheet: nil, plot_vis_only: nil, disp_blanks_as: nil, show_d_lbls_over_max: nil, data_table: nil, plot_area_fill: nil, plot_area_no_fill: nil, plot_area_line_color: nil, plot_area_line_width: nil, plot_area_line_dash: nil, plot_area_layout: nil, floor: nil, side_wall: nil, back_wall: nil, drop_lines: nil, hi_low_lines: nil, ser_lines: nil, up_down_bars: nil, band_fmts: nil, of_pie_type: nil, split_type: nil, split_pos: nil, cust_split: nil, second_pie_size: nil, cat_axis_label_rotation: nil, val_axis_label_rotation: nil, cat_axis_font: nil, val_axis_font: nil, cat_axis_line_color: nil, cat_axis_line_width: nil, cat_axis_line_dash: nil, val_axis_line_color: nil, val_axis_line_width: nil, val_axis_line_dash: nil, cat_axis_fill: nil, cat_axis_no_fill: nil, val_axis_fill: nil, val_axis_no_fill: nil, cat_axis_type: nil, cat_axis_base_time_unit: nil, cat_axis_major_time_unit: nil, cat_axis_minor_time_unit: nil, cat_axis_major_unit: nil, cat_axis_minor_unit: nil, chart_fill: nil, chart_no_fill: nil, chart_line_color: nil, chart_line_width: nil, chart_line_dash: nil, protection: nil, print_settings: nil, chart_font: nil, sheet: nil)
|
|
1136
1261
|
sheet_name = sheet || @sheet_order.first
|
|
1137
1262
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @charts_data.key?(sheet_name)
|
|
@@ -1295,6 +1420,7 @@ module Xlsxrb
|
|
|
1295
1420
|
end
|
|
1296
1421
|
|
|
1297
1422
|
# Returns chart definitions for the first (or given) sheet.
|
|
1423
|
+
# : (?sheet: untyped?) -> untyped
|
|
1298
1424
|
def charts(sheet: nil)
|
|
1299
1425
|
sheet_name = sheet || @sheet_order.first
|
|
1300
1426
|
@charts_data[sheet_name] || []
|
|
@@ -1304,6 +1430,7 @@ module Xlsxrb
|
|
|
1304
1430
|
# preset: preset geometry name (e.g. "rect", "ellipse", "roundRect").
|
|
1305
1431
|
# text: optional text body string.
|
|
1306
1432
|
# from_col/from_row/to_col/to_row: anchor coordinates.
|
|
1433
|
+
# : (?preset: ::String, ?text: untyped?, ?name: untyped?, ?description: untyped?, ?title: untyped?, ?hidden: untyped?, ?macro: untyped?, ?textlink: untyped?, ?f_locks_text: untyped?, ?no_grp: untyped?, ?no_rot: untyped?, ?fill_color: untyped?, ?fill_alpha: untyped?, ?fill_color_transforms: untyped?, ?no_fill: untyped?, ?gradient_fill: untyped?, ?pattern_fill: untyped?, ?line_color: untyped?, ?line_alpha: untyped?, ?line_color_transforms: untyped?, ?line_width: untyped?, ?no_line: untyped?, ?line_dash: untyped?, ?line_custom_dash: untyped?, ?line_cap: untyped?, ?line_align: untyped?, ?line_compound: untyped?, ?line_join: untyped?, ?line_miter_limit: untyped?, ?head_end: untyped?, ?tail_end: untyped?, ?rotation: untyped?, ?text_wrap: untyped?, ?text_anchor: untyped?, ?text_vert_overflow: untyped?, ?text_horz_overflow: untyped?, ?text_spc_first_last_para: untyped?, ?text_num_col: untyped?, ?text_spc_col: untyped?, ?text_rtl_col: untyped?, ?text_from_word_art: untyped?, ?text_upright: untyped?, ?text_compat_ln_spc: untyped?, ?text_force_aa: untyped?, ?text_warp: untyped?, ?text_vertical: untyped?, ?text_insets: untyped?, ?text_rot: untyped?, ?adjust_values: untyped?, ?text_font: untyped?, ?text_end_para_rpr: untyped?, ?text_def_rpr: untyped?, ?text_align: untyped?, ?text_font_align: untyped?, ?text_def_tab_sz: untyped?, ?text_indent: untyped?, ?text_anchor_ctr: untyped?, ?text_spacing: untyped?, ?text_rtl: untyped?, ?text_ea_ln_brk: untyped?, ?text_latin_ln_brk: untyped?, ?text_hanging_punct: untyped?, ?text_tab_stops: untyped?, ?text_bullet: untyped?, ?text_level: untyped?, ?text_paragraphs: untyped?, ?autofit: untyped?, ?outer_shadow: untyped?, ?inner_shadow: untyped?, ?glow: untyped?, ?soft_edge: untyped?, ?reflection: untyped?, ?blur: untyped?, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, ?from_col_off: untyped?, ?from_row_off: untyped?, ?to_col_off: untyped?, ?to_row_off: untyped?, ?edit_as: untyped?, ?published: untyped?, ?locks_with_sheet: untyped?, ?prints_with_sheet: untyped?, ?sheet: untyped?) -> untyped
|
|
1307
1434
|
def add_shape(preset: "rect", text: nil, name: nil, description: nil, title: nil, hidden: nil, macro: nil, textlink: nil, f_locks_text: nil, no_grp: nil, no_rot: nil, fill_color: nil, fill_alpha: nil, fill_color_transforms: nil, no_fill: nil, gradient_fill: nil, pattern_fill: nil, line_color: nil, line_alpha: nil, line_color_transforms: nil, line_width: nil, no_line: nil, line_dash: nil, line_custom_dash: nil, line_cap: nil, line_align: nil, line_compound: nil, line_join: nil, line_miter_limit: nil, head_end: nil, tail_end: nil, rotation: nil, text_wrap: nil, text_anchor: nil, text_vert_overflow: nil, text_horz_overflow: nil, text_spc_first_last_para: nil, text_num_col: nil, text_spc_col: nil, text_rtl_col: nil, text_from_word_art: nil, text_upright: nil, text_compat_ln_spc: nil, text_force_aa: nil, text_warp: nil, text_vertical: nil, text_insets: nil, text_rot: nil, adjust_values: nil, text_font: nil, text_end_para_rpr: nil, text_def_rpr: nil, text_align: nil, text_font_align: nil, text_def_tab_sz: nil, text_indent: nil, text_anchor_ctr: nil, text_spacing: nil, text_rtl: nil, text_ea_ln_brk: nil, text_latin_ln_brk: nil, text_hanging_punct: nil, text_tab_stops: nil, text_bullet: nil, text_level: nil, text_paragraphs: nil, autofit: nil, outer_shadow: nil, inner_shadow: nil, glow: nil, soft_edge: nil, reflection: nil, blur: nil, from_col: 0, from_row: 0, to_col: 5, to_row: 5, from_col_off: nil, from_row_off: nil, to_col_off: nil, to_row_off: nil, edit_as: nil, published: nil, locks_with_sheet: nil, prints_with_sheet: nil, sheet: nil)
|
|
1308
1435
|
sheet_name = sheet || @sheet_order.first
|
|
1309
1436
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @shapes_data.key?(sheet_name)
|
|
@@ -1396,12 +1523,14 @@ module Xlsxrb
|
|
|
1396
1523
|
end
|
|
1397
1524
|
|
|
1398
1525
|
# Returns shape definitions for the first (or given) sheet.
|
|
1526
|
+
# : (?sheet: untyped?) -> untyped
|
|
1399
1527
|
def shapes(sheet: nil)
|
|
1400
1528
|
sheet_name = sheet || @sheet_order.first
|
|
1401
1529
|
@shapes_data[sheet_name] || []
|
|
1402
1530
|
end
|
|
1403
1531
|
|
|
1404
1532
|
# Adds a comment on a cell.
|
|
1533
|
+
# : (untyped cell_address, untyped text, ?author: ::String, ?sheet: untyped?, ?guid: untyped?, ?shape_id: untyped?) -> untyped
|
|
1405
1534
|
def add_comment(cell_address, text, author: "Author", sheet: nil, guid: nil, shape_id: nil)
|
|
1406
1535
|
validate_cell_address!(cell_address)
|
|
1407
1536
|
sheet_name = sheet || @sheet_order.first
|
|
@@ -1414,6 +1543,7 @@ module Xlsxrb
|
|
|
1414
1543
|
end
|
|
1415
1544
|
|
|
1416
1545
|
# Returns comment definitions for the first (or given) sheet.
|
|
1546
|
+
# : (?sheet: untyped?) -> untyped
|
|
1417
1547
|
def comments(sheet: nil)
|
|
1418
1548
|
sheet_name = sheet || @sheet_order.first
|
|
1419
1549
|
@comments_data[sheet_name] || []
|
|
@@ -1426,6 +1556,7 @@ module Xlsxrb
|
|
|
1426
1556
|
# col_fields: array of 0-based field indices for column axis.
|
|
1427
1557
|
# field_names: array of field name strings (for cache definition).
|
|
1428
1558
|
# items: hash mapping field index to array of item values.
|
|
1559
|
+
# : (untyped source_ref, row_fields: untyped, data_fields: untyped, ?col_fields: untyped, ?dest_ref: ::String, ?name: untyped?, ?field_names: untyped?, ?items: untyped?, ?sheet: untyped?, **untyped opts) -> untyped
|
|
1429
1560
|
def add_pivot_table(source_ref, row_fields:, data_fields:, col_fields: [], dest_ref: "E1", name: nil, field_names: nil, items: nil, sheet: nil, **opts)
|
|
1430
1561
|
sheet_name = sheet || @sheet_order.first
|
|
1431
1562
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @pivot_tables_data.key?(sheet_name)
|
|
@@ -1480,6 +1611,7 @@ module Xlsxrb
|
|
|
1480
1611
|
end
|
|
1481
1612
|
|
|
1482
1613
|
# Returns pivot table definitions for the first (or given) sheet.
|
|
1614
|
+
# : (?sheet: untyped?) -> untyped
|
|
1483
1615
|
def pivot_tables(sheet: nil)
|
|
1484
1616
|
sheet_name = sheet || @sheet_order.first
|
|
1485
1617
|
@pivot_tables_data[sheet_name] || []
|
|
@@ -1488,26 +1620,31 @@ module Xlsxrb
|
|
|
1488
1620
|
# Adds an external link reference to another workbook.
|
|
1489
1621
|
# target: path or URI to the external workbook (e.g. "Book2.xlsx").
|
|
1490
1622
|
# sheet_names: array of sheet name strings in the external workbook.
|
|
1623
|
+
# : (target: untyped, ?sheet_names: untyped) -> untyped
|
|
1491
1624
|
def add_external_link(target:, sheet_names: [])
|
|
1492
1625
|
@external_links << { target: target, sheet_names: sheet_names }
|
|
1493
1626
|
end
|
|
1494
1627
|
|
|
1495
1628
|
# Returns external link definitions.
|
|
1629
|
+
# : () -> untyped
|
|
1496
1630
|
def external_links
|
|
1497
1631
|
@external_links.dup
|
|
1498
1632
|
end
|
|
1499
1633
|
|
|
1500
1634
|
# Enables macro preservation mode. Required when copy_entries_from loads a .xlsm file.
|
|
1635
|
+
# : () -> untyped
|
|
1501
1636
|
def preserve_macros!
|
|
1502
1637
|
@preserve_macros = true
|
|
1503
1638
|
end
|
|
1504
1639
|
|
|
1505
1640
|
# Returns whether macro preservation is enabled.
|
|
1641
|
+
# : () -> untyped
|
|
1506
1642
|
def preserve_macros?
|
|
1507
1643
|
@preserve_macros
|
|
1508
1644
|
end
|
|
1509
1645
|
|
|
1510
1646
|
# Writes the workbook as an XLSX file to the given path.
|
|
1647
|
+
# : (untyped filepath) -> untyped
|
|
1511
1648
|
def write(filepath)
|
|
1512
1649
|
# Pre-register date/datetime formats if any sheet contains Date or Time values.
|
|
1513
1650
|
needs_date = false
|
|
@@ -1729,6 +1866,7 @@ module Xlsxrb
|
|
|
1729
1866
|
|
|
1730
1867
|
private
|
|
1731
1868
|
|
|
1869
|
+
# : (?::Hash[untyped, untyped] all_entries) -> untyped
|
|
1732
1870
|
def generate_content_types_xml(all_entries = {})
|
|
1733
1871
|
defaults = {
|
|
1734
1872
|
"rels" => "application/vnd.openxmlformats-package.relationships+xml",
|
|
@@ -1830,6 +1968,7 @@ module Xlsxrb
|
|
|
1830
1968
|
parts.join
|
|
1831
1969
|
end
|
|
1832
1970
|
|
|
1971
|
+
# : () -> untyped
|
|
1833
1972
|
def generate_rels_root
|
|
1834
1973
|
rid_counter = 1
|
|
1835
1974
|
parts = [
|
|
@@ -1853,6 +1992,7 @@ module Xlsxrb
|
|
|
1853
1992
|
parts.join
|
|
1854
1993
|
end
|
|
1855
1994
|
|
|
1995
|
+
# : (?::Integer pivot_cache_count) -> untyped
|
|
1856
1996
|
def generate_workbook_xml(pivot_cache_count = 0)
|
|
1857
1997
|
wb_attrs = %(xmlns="#{SSML_NS}" xmlns:r="#{DOC_REL_NS}")
|
|
1858
1998
|
wb_attrs << %( conformance="#{@workbook_properties[:conformance]}") if @workbook_properties[:conformance]
|
|
@@ -2057,6 +2197,7 @@ module Xlsxrb
|
|
|
2057
2197
|
parts.join
|
|
2058
2198
|
end
|
|
2059
2199
|
|
|
2200
|
+
# : (?has_calc_chain: bool) -> untyped
|
|
2060
2201
|
def generate_workbook_rels(has_calc_chain: false)
|
|
2061
2202
|
parts = [
|
|
2062
2203
|
XML_HEADER,
|
|
@@ -2088,6 +2229,7 @@ module Xlsxrb
|
|
|
2088
2229
|
parts.join
|
|
2089
2230
|
end
|
|
2090
2231
|
|
|
2232
|
+
# : () -> (nil | untyped)
|
|
2091
2233
|
def generate_calc_chain_xml
|
|
2092
2234
|
chain_entries = []
|
|
2093
2235
|
@sheet_order.each_with_index do |sheet_name, i|
|
|
@@ -2105,6 +2247,7 @@ module Xlsxrb
|
|
|
2105
2247
|
parts.join
|
|
2106
2248
|
end
|
|
2107
2249
|
|
|
2250
|
+
# : (untyped sheet_cells, untyped sheet_col_widths, untyped sheet_col_attrs, untyped sheet_row_attrs, untyped sheet_auto_filter, untyped sheet_filter_cols, untyped sheet_sort, untyped sheet_merge_cells, untyped sheet_hyperlinks, untyped sheet_cell_styles, untyped sheet_props, untyped sheet_fmt, untyped sheet_sv, untyped sheet_fp, untyped sheet_sel, untyped sheet_po, untyped sheet_pm, untyped sheet_ps, untyped sheet_hf, untyped sheet_rb, untyped sheet_cb, untyped sheet_dv, untyped sheet_cf, ?untyped? sst, ?untyped sheet_tables, ?::Integer hyperlink_count, ?has_drawing: bool, ?has_comments: bool, ?sheet_prot: untyped?, ?vml_rid: untyped?, ?phonetic_pr: untyped?, ?dv_options: ::Hash[untyped, untyped], ?prot_ranges: untyped, ?cell_watches: untyped, ?ignored_errors: untyped, ?data_consol: untyped?, ?sheet_scenarios: untyped?, ?cell_phonetic: ::Hash[untyped, untyped]) -> untyped
|
|
2108
2251
|
def generate_worksheet_xml(sheet_cells, sheet_col_widths, sheet_col_attrs, sheet_row_attrs, sheet_auto_filter, sheet_filter_cols, sheet_sort, sheet_merge_cells, sheet_hyperlinks, sheet_cell_styles, sheet_props, sheet_fmt, sheet_sv, sheet_fp, sheet_sel, sheet_po, sheet_pm, sheet_ps, sheet_hf, sheet_rb, sheet_cb, sheet_dv, sheet_cf, sst = nil, sheet_tables = [], hyperlink_count = 0, has_drawing: false, has_comments: false, sheet_prot: nil, vml_rid: nil, phonetic_pr: nil, dv_options: {}, prot_ranges: [], cell_watches: [], ignored_errors: [], data_consol: nil, sheet_scenarios: nil, cell_phonetic: {})
|
|
2109
2252
|
needs_r_ns = !sheet_hyperlinks.empty? || sheet_tables.any? || has_drawing || has_comments
|
|
2110
2253
|
worksheet_attrs = %(xmlns="#{SSML_NS}")
|
|
@@ -2685,6 +2828,7 @@ module Xlsxrb
|
|
|
2685
2828
|
parts.join
|
|
2686
2829
|
end
|
|
2687
2830
|
|
|
2831
|
+
# : () -> ::Array[untyped]
|
|
2688
2832
|
def build_shared_string_table
|
|
2689
2833
|
rt_sst = {}.compare_by_identity # Xlsxrb::Elements::RichText object -> global index
|
|
2690
2834
|
str_sst = {} # String -> global index
|
|
@@ -2707,6 +2851,7 @@ module Xlsxrb
|
|
|
2707
2851
|
[rt_sst, str_sst]
|
|
2708
2852
|
end
|
|
2709
2853
|
|
|
2854
|
+
# : (untyped sst) -> untyped
|
|
2710
2855
|
def generate_shared_strings_xml(sst)
|
|
2711
2856
|
rt_sst, str_sst = sst
|
|
2712
2857
|
total = rt_sst.size + str_sst.size
|
|
@@ -2726,6 +2871,7 @@ module Xlsxrb
|
|
|
2726
2871
|
parts.join
|
|
2727
2872
|
end
|
|
2728
2873
|
|
|
2874
|
+
# : (untyped tbl) -> untyped
|
|
2729
2875
|
def generate_table_xml(tbl)
|
|
2730
2876
|
trc = tbl[:totals_row_count].to_i
|
|
2731
2877
|
table_attrs = %(xmlns="#{SSML_NS}" id="#{tbl[:id]}" name="#{xml_escape(tbl[:name])}" displayName="#{xml_escape(tbl[:display_name])}" ref="#{tbl[:ref]}")
|
|
@@ -2791,6 +2937,7 @@ module Xlsxrb
|
|
|
2791
2937
|
parts.join
|
|
2792
2938
|
end
|
|
2793
2939
|
|
|
2940
|
+
# : (untyped sheet_hyperlinks, ?untyped sheet_tables, ?::Integer table_start_index) -> untyped
|
|
2794
2941
|
def generate_worksheet_rels(sheet_hyperlinks, sheet_tables = [], table_start_index = 0)
|
|
2795
2942
|
parts = [
|
|
2796
2943
|
XML_HEADER,
|
|
@@ -2811,6 +2958,7 @@ module Xlsxrb
|
|
|
2811
2958
|
parts.join
|
|
2812
2959
|
end
|
|
2813
2960
|
|
|
2961
|
+
# : (untyped sheet_name, untyped sheet_tables, untyped table_start_index, untyped drawing_idx, untyped comment_idx, untyped pivot_start, untyped pivot_count) -> untyped
|
|
2814
2962
|
def build_sheet_rels_parts_v2(sheet_name, sheet_tables, table_start_index, drawing_idx, comment_idx, pivot_start, pivot_count)
|
|
2815
2963
|
rels = []
|
|
2816
2964
|
@hyperlinks[sheet_name].each do |(_cell_ref, link)|
|
|
@@ -2833,6 +2981,7 @@ module Xlsxrb
|
|
|
2833
2981
|
rels
|
|
2834
2982
|
end
|
|
2835
2983
|
|
|
2984
|
+
# : (untyped rels_data) -> untyped
|
|
2836
2985
|
def generate_generic_rels(rels_data)
|
|
2837
2986
|
parts = [XML_HEADER, %(<Relationships xmlns="#{REL_NS}">)]
|
|
2838
2987
|
rels_data.each_with_index do |rel, i|
|
|
@@ -2843,6 +2992,7 @@ module Xlsxrb
|
|
|
2843
2992
|
parts.join
|
|
2844
2993
|
end
|
|
2845
2994
|
|
|
2995
|
+
# : (untyped drawing_parts) -> untyped
|
|
2846
2996
|
def generate_drawing_xml(drawing_parts)
|
|
2847
2997
|
parts = [
|
|
2848
2998
|
XML_HEADER,
|
|
@@ -3156,6 +3306,7 @@ module Xlsxrb
|
|
|
3156
3306
|
parts.join
|
|
3157
3307
|
end
|
|
3158
3308
|
|
|
3309
|
+
# : (untyped para) -> ::String
|
|
3159
3310
|
def paragraph_xml(para)
|
|
3160
3311
|
ppr_attrs = +""
|
|
3161
3312
|
ppr_attrs << %( algn="#{xml_escape(para[:align])}") if para[:align]
|
|
@@ -3237,6 +3388,7 @@ module Xlsxrb
|
|
|
3237
3388
|
"<a:p>#{ppr_xml}#{runs_xml}#{end_para_rpr_xml}</a:p>"
|
|
3238
3389
|
end
|
|
3239
3390
|
|
|
3391
|
+
# : (untyped tag, untyped font) -> untyped
|
|
3240
3392
|
def text_char_props_xml(tag, font)
|
|
3241
3393
|
attrs = +""
|
|
3242
3394
|
attrs << %( b="1") if font[:bold]
|
|
@@ -3344,10 +3496,12 @@ module Xlsxrb
|
|
|
3344
3496
|
end
|
|
3345
3497
|
end
|
|
3346
3498
|
|
|
3499
|
+
# : (untyped tag, untyped col, untyped row, ?col_off: ::Integer, ?row_off: ::Integer) -> ::String
|
|
3347
3500
|
def anchor_xml(tag, col, row, col_off: 0, row_off: 0)
|
|
3348
3501
|
"<xdr:#{tag}><xdr:col>#{col}</xdr:col><xdr:colOff>#{col_off}</xdr:colOff><xdr:row>#{row}</xdr:row><xdr:rowOff>#{row_off}</xdr:rowOff></xdr:#{tag}>"
|
|
3349
3502
|
end
|
|
3350
3503
|
|
|
3504
|
+
# : (untyped obj) -> ::String
|
|
3351
3505
|
def client_data_xml(obj)
|
|
3352
3506
|
cd_attrs = +""
|
|
3353
3507
|
cd_attrs << ' fLocksWithSheet="0"' if obj[:locks_with_sheet] == false
|
|
@@ -3357,6 +3511,7 @@ module Xlsxrb
|
|
|
3357
3511
|
"<xdr:clientData#{cd_attrs}/>"
|
|
3358
3512
|
end
|
|
3359
3513
|
|
|
3514
|
+
# : (untyped rels_data) -> untyped
|
|
3360
3515
|
def generate_drawing_rels(rels_data)
|
|
3361
3516
|
parts = [XML_HEADER, %(<Relationships xmlns="#{REL_NS}">)]
|
|
3362
3517
|
rels_data.each_with_index do |rel, i|
|
|
@@ -3370,6 +3525,7 @@ module Xlsxrb
|
|
|
3370
3525
|
parts.join
|
|
3371
3526
|
end
|
|
3372
3527
|
|
|
3528
|
+
# : (untyped title_spec, ?overlay: bool) -> untyped
|
|
3373
3529
|
def build_chart_title_xml(title_spec, overlay: false)
|
|
3374
3530
|
overlay_val = overlay ? 1 : 0
|
|
3375
3531
|
if title_spec.is_a?(Hash)
|
|
@@ -3397,6 +3553,7 @@ module Xlsxrb
|
|
|
3397
3553
|
end
|
|
3398
3554
|
end
|
|
3399
3555
|
|
|
3556
|
+
# : (untyped title_spec, untyped chart, untyped prefix) -> untyped
|
|
3400
3557
|
def merge_flat_title_styling(title_spec, chart, prefix)
|
|
3401
3558
|
font_key = :"#{prefix}_font"
|
|
3402
3559
|
fill_key = :"#{prefix}_fill"
|
|
@@ -3419,6 +3576,7 @@ module Xlsxrb
|
|
|
3419
3576
|
spec
|
|
3420
3577
|
end
|
|
3421
3578
|
|
|
3579
|
+
# : (untyped spec) -> untyped
|
|
3422
3580
|
def build_title_sp_pr(spec)
|
|
3423
3581
|
children = +""
|
|
3424
3582
|
children << %(<a:solidFill>#{color_xml(spec[:fill_color])}</a:solidFill>) if spec[:fill_color]
|
|
@@ -3432,6 +3590,7 @@ module Xlsxrb
|
|
|
3432
3590
|
children.empty? ? "" : "<c:spPr>#{children}</c:spPr>"
|
|
3433
3591
|
end
|
|
3434
3592
|
|
|
3593
|
+
# : (untyped layout) -> ("" | untyped)
|
|
3435
3594
|
def build_title_layout_xml(layout)
|
|
3436
3595
|
return "" unless layout.is_a?(Hash)
|
|
3437
3596
|
|
|
@@ -3443,6 +3602,7 @@ module Xlsxrb
|
|
|
3443
3602
|
ml.empty? ? "" : "<c:layout><c:manualLayout>#{ml}</c:manualLayout></c:layout>"
|
|
3444
3603
|
end
|
|
3445
3604
|
|
|
3605
|
+
# : (untyped tag, untyped spec) -> ("" | untyped)
|
|
3446
3606
|
def gridlines_xml(tag, spec)
|
|
3447
3607
|
return "" unless spec
|
|
3448
3608
|
|
|
@@ -3461,6 +3621,7 @@ module Xlsxrb
|
|
|
3461
3621
|
end
|
|
3462
3622
|
|
|
3463
3623
|
# Resolves a cell reference like "Sheet1!$A$1:$A$5" to an array of values from @sheets.
|
|
3624
|
+
# : (untyped ref) -> (nil | untyped)
|
|
3464
3625
|
def resolve_sheet_ref(ref)
|
|
3465
3626
|
return nil unless ref
|
|
3466
3627
|
|
|
@@ -3487,6 +3648,7 @@ module Xlsxrb
|
|
|
3487
3648
|
cells.map { |addr| @sheets[sheet_name][addr] }
|
|
3488
3649
|
end
|
|
3489
3650
|
|
|
3651
|
+
# : (untyped start_cell, untyped end_cell) -> (::Array[untyped] | untyped)
|
|
3490
3652
|
def enumerate_cell_range(start_cell, end_cell)
|
|
3491
3653
|
sc = start_cell.match(/\A([A-Z]+)(\d+)\z/)
|
|
3492
3654
|
ec = end_cell.match(/\A([A-Z]+)(\d+)\z/)
|
|
@@ -3505,6 +3667,7 @@ module Xlsxrb
|
|
|
3505
3667
|
cells
|
|
3506
3668
|
end
|
|
3507
3669
|
|
|
3670
|
+
# : (untyped ref) -> ("" | ::String)
|
|
3508
3671
|
def num_cache_xml(ref)
|
|
3509
3672
|
values = resolve_sheet_ref(ref)
|
|
3510
3673
|
return "" unless values
|
|
@@ -3517,6 +3680,7 @@ module Xlsxrb
|
|
|
3517
3680
|
%(<c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="#{values.size}"/>#{pts.join}</c:numCache>)
|
|
3518
3681
|
end
|
|
3519
3682
|
|
|
3683
|
+
# : (untyped ref) -> ("" | ::String)
|
|
3520
3684
|
def str_cache_xml(ref)
|
|
3521
3685
|
values = resolve_sheet_ref(ref)
|
|
3522
3686
|
return "" unless values
|
|
@@ -3529,6 +3693,7 @@ module Xlsxrb
|
|
|
3529
3693
|
%(<c:strCache><c:ptCount val="#{values.size}"/>#{pts.join}</c:strCache>)
|
|
3530
3694
|
end
|
|
3531
3695
|
|
|
3696
|
+
# : (untyped color, ?alpha: untyped?, ?transforms: untyped?) -> untyped
|
|
3532
3697
|
def color_xml(color, alpha: nil, transforms: nil)
|
|
3533
3698
|
if color.is_a?(Hash) && color[:scheme]
|
|
3534
3699
|
tag = "schemeClr"
|
|
@@ -3550,6 +3715,7 @@ module Xlsxrb
|
|
|
3550
3715
|
end
|
|
3551
3716
|
end
|
|
3552
3717
|
|
|
3718
|
+
# : (untyped color) -> untyped
|
|
3553
3719
|
def normalize_drawing_rgb(color)
|
|
3554
3720
|
str = color.to_s
|
|
3555
3721
|
hex = str.delete_prefix("#")
|
|
@@ -3567,6 +3733,7 @@ module Xlsxrb
|
|
|
3567
3733
|
|
|
3568
3734
|
alias srgb_clr_xml color_xml
|
|
3569
3735
|
|
|
3736
|
+
# : (untyped rotation, untyped font) -> ("" | ::String)
|
|
3570
3737
|
def build_axis_txpr(rotation, font)
|
|
3571
3738
|
return "" unless rotation || font
|
|
3572
3739
|
|
|
@@ -3588,6 +3755,7 @@ module Xlsxrb
|
|
|
3588
3755
|
%(<c:txPr><a:bodyPr#{body_attrs}/><a:lstStyle/><a:p><a:pPr>#{def_rpr}</a:pPr><a:endParaRPr/></a:p></c:txPr>)
|
|
3589
3756
|
end
|
|
3590
3757
|
|
|
3758
|
+
# : (untyped chart) -> untyped
|
|
3591
3759
|
def generate_chart_xml(chart)
|
|
3592
3760
|
chart_type = CHART_TYPE_MAP[chart[:type]] || "barChart"
|
|
3593
3761
|
no_axes = NO_AXIS_CHARTS.include?(chart_type)
|
|
@@ -4349,6 +4517,7 @@ module Xlsxrb
|
|
|
4349
4517
|
parts.join
|
|
4350
4518
|
end
|
|
4351
4519
|
|
|
4520
|
+
# : (untyped sheet_comments) -> untyped
|
|
4352
4521
|
def generate_comments_xml(sheet_comments)
|
|
4353
4522
|
authors = sheet_comments.map { |c| c[:author] }.uniq
|
|
4354
4523
|
parts = [
|
|
@@ -4374,6 +4543,7 @@ module Xlsxrb
|
|
|
4374
4543
|
parts.join
|
|
4375
4544
|
end
|
|
4376
4545
|
|
|
4546
|
+
# : (untyped sheet_comments) -> untyped
|
|
4377
4547
|
def generate_vml_drawing_xml(sheet_comments)
|
|
4378
4548
|
parts = [
|
|
4379
4549
|
'<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel">',
|
|
@@ -4402,6 +4572,7 @@ module Xlsxrb
|
|
|
4402
4572
|
parts.join
|
|
4403
4573
|
end
|
|
4404
4574
|
|
|
4575
|
+
# : (untyped cell_ref) -> (::Array[0] | ::Array[untyped])
|
|
4405
4576
|
def cell_to_col_row(cell_ref)
|
|
4406
4577
|
m = cell_ref.match(/\A([A-Z]+)(\d+)\z/)
|
|
4407
4578
|
return [0, 0] unless m
|
|
@@ -4411,6 +4582,7 @@ module Xlsxrb
|
|
|
4411
4582
|
[col, row]
|
|
4412
4583
|
end
|
|
4413
4584
|
|
|
4585
|
+
# : (untyped pivot_table, untyped cache_id) -> untyped
|
|
4414
4586
|
def generate_pivot_table_xml(pivot_table, cache_id)
|
|
4415
4587
|
data_caption = pivot_table[:data_caption] || (pivot_table[:data_fields].first ? pivot_table[:data_fields].first[:name] : "Values")
|
|
4416
4588
|
pt_attrs = %( xmlns="#{SSML_NS}" name="#{xml_escape(pivot_table[:name])}" cacheId="#{cache_id}" dataCaption="#{xml_escape(data_caption)}")
|
|
@@ -4554,6 +4726,7 @@ module Xlsxrb
|
|
|
4554
4726
|
parts.join
|
|
4555
4727
|
end
|
|
4556
4728
|
|
|
4729
|
+
# : (untyped pivot_table, untyped _cache_id) -> untyped
|
|
4557
4730
|
def generate_pivot_cache_definition_xml(pivot_table, _cache_id)
|
|
4558
4731
|
pcd_attrs = %( xmlns="#{SSML_NS}" xmlns:r="#{DOC_REL_NS}" r:id="rId1" refreshOnLoad="1")
|
|
4559
4732
|
pcd_attrs << ' saveData="0"' if pivot_table[:cache_save_data] == false
|
|
@@ -4609,6 +4782,7 @@ module Xlsxrb
|
|
|
4609
4782
|
parts.join
|
|
4610
4783
|
end
|
|
4611
4784
|
|
|
4785
|
+
# : (untyped pivot_table) -> untyped
|
|
4612
4786
|
def generate_pivot_cache_records_xml(pivot_table)
|
|
4613
4787
|
items = pivot_table[:items]
|
|
4614
4788
|
if items&.values&.any? { |v| v && !v.empty? }
|
|
@@ -4634,6 +4808,7 @@ module Xlsxrb
|
|
|
4634
4808
|
end
|
|
4635
4809
|
end
|
|
4636
4810
|
|
|
4811
|
+
# : (untyped cache_id) -> untyped
|
|
4637
4812
|
def generate_pivot_cache_rels(cache_id)
|
|
4638
4813
|
[
|
|
4639
4814
|
XML_HEADER,
|
|
@@ -4643,6 +4818,7 @@ module Xlsxrb
|
|
|
4643
4818
|
].join
|
|
4644
4819
|
end
|
|
4645
4820
|
|
|
4821
|
+
# : (untyped cache_id) -> untyped
|
|
4646
4822
|
def generate_pivot_table_rels(cache_id)
|
|
4647
4823
|
[
|
|
4648
4824
|
XML_HEADER,
|
|
@@ -4652,6 +4828,7 @@ module Xlsxrb
|
|
|
4652
4828
|
].join
|
|
4653
4829
|
end
|
|
4654
4830
|
|
|
4831
|
+
# : (untyped ext_link) -> untyped
|
|
4655
4832
|
def generate_external_link_xml(ext_link)
|
|
4656
4833
|
parts = [
|
|
4657
4834
|
XML_HEADER,
|
|
@@ -4668,6 +4845,7 @@ module Xlsxrb
|
|
|
4668
4845
|
parts.join
|
|
4669
4846
|
end
|
|
4670
4847
|
|
|
4848
|
+
# : (untyped ext_link) -> untyped
|
|
4671
4849
|
def generate_external_link_rels(ext_link)
|
|
4672
4850
|
[
|
|
4673
4851
|
XML_HEADER,
|
|
@@ -4677,6 +4855,7 @@ module Xlsxrb
|
|
|
4677
4855
|
].join
|
|
4678
4856
|
end
|
|
4679
4857
|
|
|
4858
|
+
# : (untyped ct_xml) -> untyped
|
|
4680
4859
|
def parse_extra_content_types(ct_xml)
|
|
4681
4860
|
ct_xml.scan(/<Default\s+Extension="([^"]+)"\s+ContentType="([^"]+)"/).each do |ext, ct|
|
|
4682
4861
|
@extra_ct_defaults[ext] ||= ct
|
|
@@ -4686,6 +4865,7 @@ module Xlsxrb
|
|
|
4686
4865
|
end
|
|
4687
4866
|
end
|
|
4688
4867
|
|
|
4868
|
+
# : (untyped element, untyped opts) -> ("" | ::String)
|
|
4689
4869
|
def build_line_end_xml(element, opts)
|
|
4690
4870
|
return "" unless opts
|
|
4691
4871
|
|
|
@@ -4696,8 +4876,10 @@ module Xlsxrb
|
|
|
4696
4876
|
"<a:#{element}#{attrs}/>"
|
|
4697
4877
|
end
|
|
4698
4878
|
|
|
4879
|
+
# : (untyped value) -> untyped
|
|
4699
4880
|
def xml_escape(value)
|
|
4700
4881
|
value.to_s
|
|
4882
|
+
.gsub(/[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/, "")
|
|
4701
4883
|
.gsub("&", "&")
|
|
4702
4884
|
.gsub("<", "<")
|
|
4703
4885
|
.gsub(">", ">")
|
|
@@ -4705,6 +4887,7 @@ module Xlsxrb
|
|
|
4705
4887
|
.gsub("'", "'")
|
|
4706
4888
|
end
|
|
4707
4889
|
|
|
4890
|
+
# : (untyped rich_text) -> untyped
|
|
4708
4891
|
def rich_text_xml(rich_text)
|
|
4709
4892
|
rich_text.runs.map do |run|
|
|
4710
4893
|
font = run[:font]
|
|
@@ -4733,6 +4916,7 @@ module Xlsxrb
|
|
|
4733
4916
|
end.join
|
|
4734
4917
|
end
|
|
4735
4918
|
|
|
4919
|
+
# : (untyped cell_ref, untyped value, untyped style_idx, ?untyped? sst, ?ph: untyped?) -> untyped
|
|
4736
4920
|
def cell_xml(cell_ref, value, style_idx, sst = nil, ph: nil) # rubocop:disable Naming/MethodParameterName
|
|
4737
4921
|
s_attr = style_idx ? %( s="#{style_idx}") : ""
|
|
4738
4922
|
ph_attr = ph ? ' ph="1"' : ""
|
|
@@ -4805,16 +4989,19 @@ module Xlsxrb
|
|
|
4805
4989
|
end
|
|
4806
4990
|
|
|
4807
4991
|
# Returns the numFmtId for dates, registering it on first use.
|
|
4992
|
+
# : () -> untyped
|
|
4808
4993
|
def date_num_fmt_id
|
|
4809
4994
|
@date_num_fmt_id ||= add_number_format(Xlsxrb::Ooxml::Utils::DEFAULT_DATE_FORMAT)
|
|
4810
4995
|
end
|
|
4811
4996
|
|
|
4812
4997
|
# Returns the numFmtId for datetime, registering it on first use.
|
|
4998
|
+
# : () -> untyped
|
|
4813
4999
|
def datetime_num_fmt_id
|
|
4814
5000
|
@datetime_num_fmt_id ||= add_number_format(Xlsxrb::Ooxml::Utils::DEFAULT_DATETIME_FORMAT)
|
|
4815
5001
|
end
|
|
4816
5002
|
|
|
4817
5003
|
# Maps a numFmtId to a cellXfs index. Index 0 is the default (no format).
|
|
5004
|
+
# : (untyped style_value) -> (nil | untyped)
|
|
4818
5005
|
def resolve_style_index(style_value)
|
|
4819
5006
|
return nil if style_value.nil?
|
|
4820
5007
|
|
|
@@ -4839,6 +5026,7 @@ module Xlsxrb
|
|
|
4839
5026
|
@xf_index_map[num_fmt_id]
|
|
4840
5027
|
end
|
|
4841
5028
|
|
|
5029
|
+
# : (untyped filter) -> untyped
|
|
4842
5030
|
def emit_filter_xml(filter)
|
|
4843
5031
|
case filter[:type]
|
|
4844
5032
|
when :filters
|
|
@@ -4901,6 +5089,7 @@ module Xlsxrb
|
|
|
4901
5089
|
end
|
|
4902
5090
|
end
|
|
4903
5091
|
|
|
5092
|
+
# : (untyped parts, untyped rule) -> untyped
|
|
4904
5093
|
def emit_cf_rule(parts, rule)
|
|
4905
5094
|
type = rule[:type]
|
|
4906
5095
|
if type.is_a?(String) || type.is_a?(Symbol)
|
|
@@ -4990,6 +5179,7 @@ module Xlsxrb
|
|
|
4990
5179
|
end
|
|
4991
5180
|
|
|
4992
5181
|
# Emits a <color> element for CF rules, accepting either a plain RGB string or a hash.
|
|
5182
|
+
# : (untyped color) -> (untyped | ::String)
|
|
4993
5183
|
def emit_cf_color_xml(color)
|
|
4994
5184
|
if color.is_a?(Hash)
|
|
4995
5185
|
emit_color_xml(color)
|
|
@@ -4998,6 +5188,7 @@ module Xlsxrb
|
|
|
4998
5188
|
end
|
|
4999
5189
|
end
|
|
5000
5190
|
|
|
5191
|
+
# : (untyped sheet_cells) -> ("A1" | ::String)
|
|
5001
5192
|
def compute_dimension(sheet_cells)
|
|
5002
5193
|
return "A1" if sheet_cells.empty?
|
|
5003
5194
|
|
|
@@ -5019,6 +5210,7 @@ module Xlsxrb
|
|
|
5019
5210
|
"#{start_col}#{min_row}:#{end_col}#{max_row}"
|
|
5020
5211
|
end
|
|
5021
5212
|
|
|
5213
|
+
# : (untyped index) -> untyped
|
|
5022
5214
|
def index_to_column_letter(index)
|
|
5023
5215
|
result = +""
|
|
5024
5216
|
while index.positive?
|
|
@@ -5029,6 +5221,7 @@ module Xlsxrb
|
|
|
5029
5221
|
result
|
|
5030
5222
|
end
|
|
5031
5223
|
|
|
5224
|
+
# : () -> untyped
|
|
5032
5225
|
def generate_core_properties_xml
|
|
5033
5226
|
parts = [
|
|
5034
5227
|
XML_HEADER,
|
|
@@ -5050,6 +5243,7 @@ module Xlsxrb
|
|
|
5050
5243
|
parts.join
|
|
5051
5244
|
end
|
|
5052
5245
|
|
|
5246
|
+
# : () -> untyped
|
|
5053
5247
|
def generate_app_properties_xml
|
|
5054
5248
|
parts = [
|
|
5055
5249
|
XML_HEADER,
|
|
@@ -5078,6 +5272,7 @@ module Xlsxrb
|
|
|
5078
5272
|
parts.join
|
|
5079
5273
|
end
|
|
5080
5274
|
|
|
5275
|
+
# : () -> untyped
|
|
5081
5276
|
def generate_custom_properties_xml
|
|
5082
5277
|
custom_ns = "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
|
|
5083
5278
|
parts = [
|
|
@@ -5106,6 +5301,7 @@ module Xlsxrb
|
|
|
5106
5301
|
parts.join
|
|
5107
5302
|
end
|
|
5108
5303
|
|
|
5304
|
+
# : () -> untyped
|
|
5109
5305
|
def generate_styles_xml
|
|
5110
5306
|
parts = [
|
|
5111
5307
|
XML_HEADER,
|
|
@@ -5238,6 +5434,7 @@ module Xlsxrb
|
|
|
5238
5434
|
parts.join
|
|
5239
5435
|
end
|
|
5240
5436
|
|
|
5437
|
+
# : (untyped alignment) -> ::String
|
|
5241
5438
|
def emit_alignment_xml(alignment)
|
|
5242
5439
|
attrs = []
|
|
5243
5440
|
attrs << %(horizontal="#{alignment[:horizontal]}") if alignment[:horizontal]
|
|
@@ -5252,6 +5449,7 @@ module Xlsxrb
|
|
|
5252
5449
|
"<alignment #{attrs.join(" ")}/>"
|
|
5253
5450
|
end
|
|
5254
5451
|
|
|
5452
|
+
# : (untyped protection) -> ::String
|
|
5255
5453
|
def emit_protection_xml(protection)
|
|
5256
5454
|
attrs = []
|
|
5257
5455
|
attrs << %(locked="#{protection[:locked] ? "1" : "0"}") unless protection[:locked].nil?
|
|
@@ -5259,6 +5457,7 @@ module Xlsxrb
|
|
|
5259
5457
|
"<protection #{attrs.join(" ")}/>"
|
|
5260
5458
|
end
|
|
5261
5459
|
|
|
5460
|
+
# : (untyped source, ?tag: ::String) -> (::String | ::String | ::String | ::String | "")
|
|
5262
5461
|
def emit_color_xml(source, tag: "color")
|
|
5263
5462
|
if source[:auto]
|
|
5264
5463
|
%(<#{tag} auto="1"/>)
|
|
@@ -5275,6 +5474,7 @@ module Xlsxrb
|
|
|
5275
5474
|
end
|
|
5276
5475
|
end
|
|
5277
5476
|
|
|
5477
|
+
# : (untyped font) -> untyped
|
|
5278
5478
|
def emit_font_xml(font)
|
|
5279
5479
|
parts = ["<font>"]
|
|
5280
5480
|
parts << "<b/>" if font[:bold]
|
|
@@ -5302,6 +5502,7 @@ module Xlsxrb
|
|
|
5302
5502
|
parts.join
|
|
5303
5503
|
end
|
|
5304
5504
|
|
|
5505
|
+
# : (untyped fill) -> (untyped | ::String)
|
|
5305
5506
|
def emit_fill_xml(fill)
|
|
5306
5507
|
return emit_gradient_fill_xml(fill[:gradient]) if fill[:gradient]
|
|
5307
5508
|
|
|
@@ -5319,6 +5520,7 @@ module Xlsxrb
|
|
|
5319
5520
|
parts.join
|
|
5320
5521
|
end
|
|
5321
5522
|
|
|
5523
|
+
# : (untyped tag, untyped fill, untyped prefix) -> (::String | ::String | ::String | ::String | "")
|
|
5322
5524
|
def emit_fill_color_xml(tag, fill, prefix)
|
|
5323
5525
|
if fill[:"#{prefix}_color"]
|
|
5324
5526
|
%(<#{tag} rgb="#{fill[:"#{prefix}_color"]}"/>)
|
|
@@ -5335,6 +5537,7 @@ module Xlsxrb
|
|
|
5335
5537
|
end
|
|
5336
5538
|
end
|
|
5337
5539
|
|
|
5540
|
+
# : (untyped gradient) -> untyped
|
|
5338
5541
|
def emit_gradient_fill_xml(gradient)
|
|
5339
5542
|
attrs = []
|
|
5340
5543
|
attrs << %(type="#{gradient[:type]}") if gradient[:type]
|
|
@@ -5358,6 +5561,7 @@ module Xlsxrb
|
|
|
5358
5561
|
parts.join
|
|
5359
5562
|
end
|
|
5360
5563
|
|
|
5564
|
+
# : (untyped brk, default_max: untyped) -> ::String
|
|
5361
5565
|
def emit_brk_xml(brk, default_max:)
|
|
5362
5566
|
if brk.is_a?(Hash)
|
|
5363
5567
|
attrs = %(id="#{brk[:id]}")
|
|
@@ -5371,6 +5575,7 @@ module Xlsxrb
|
|
|
5371
5575
|
end
|
|
5372
5576
|
end
|
|
5373
5577
|
|
|
5578
|
+
# : (untyped bdr) -> untyped
|
|
5374
5579
|
def emit_border_xml(bdr)
|
|
5375
5580
|
border_attrs = []
|
|
5376
5581
|
border_attrs << ' diagonalUp="1"' if bdr[:diagonal_up]
|
|
@@ -5391,6 +5596,7 @@ module Xlsxrb
|
|
|
5391
5596
|
parts.join
|
|
5392
5597
|
end
|
|
5393
5598
|
|
|
5599
|
+
# : (untyped dxf) -> untyped
|
|
5394
5600
|
def emit_dxf_xml(dxf)
|
|
5395
5601
|
parts = ["<dxf>"]
|
|
5396
5602
|
parts << emit_font_xml(dxf[:font]) if dxf[:font]
|
|
@@ -5406,6 +5612,7 @@ module Xlsxrb
|
|
|
5406
5612
|
parts.join
|
|
5407
5613
|
end
|
|
5408
5614
|
|
|
5615
|
+
# : (untyped cell_address) -> untyped
|
|
5409
5616
|
def validate_cell_address!(cell_address)
|
|
5410
5617
|
raise ArgumentError, "cell address must be a String" unless cell_address.is_a?(String)
|
|
5411
5618
|
|
|
@@ -5419,26 +5626,31 @@ module Xlsxrb
|
|
|
5419
5626
|
raise ArgumentError, "column out of range: #{match[1]}" unless col_index.between?(1, MAX_COLUMN_INDEX)
|
|
5420
5627
|
end
|
|
5421
5628
|
|
|
5629
|
+
# : (untyped letters) -> untyped
|
|
5422
5630
|
def column_letter_to_index(letters)
|
|
5423
5631
|
letters.chars.reduce(0) { |sum, char| (sum * 26) + (char.ord - "A".ord + 1) }
|
|
5424
5632
|
end
|
|
5425
5633
|
|
|
5426
5634
|
# Extracts the column letter(s) from a cell address, e.g. "A" from "A1".
|
|
5635
|
+
# : (untyped cell_address) -> untyped
|
|
5427
5636
|
def extract_column_letter(cell_address)
|
|
5428
5637
|
cell_address.match(/^([A-Z]+)/)[1]
|
|
5429
5638
|
end
|
|
5430
5639
|
|
|
5431
5640
|
# Extracts the row number from a cell address, e.g. 1 from "A1".
|
|
5641
|
+
# : (untyped cell_address) -> untyped
|
|
5432
5642
|
def extract_row_number(cell_address)
|
|
5433
5643
|
cell_address.match(/(\d+)$/)[1].to_i
|
|
5434
5644
|
end
|
|
5435
5645
|
|
|
5436
5646
|
# Converts a range like "A1:D20" to absolute "$A$1:$D$20".
|
|
5647
|
+
# : (untyped range) -> untyped
|
|
5437
5648
|
def absolute_range(range)
|
|
5438
5649
|
range.split(":").map { |part| absolute_cell(part) }.join(":")
|
|
5439
5650
|
end
|
|
5440
5651
|
|
|
5441
5652
|
# Converts "A1" to "$A$1".
|
|
5653
|
+
# : (untyped cell_ref) -> ::String
|
|
5442
5654
|
def absolute_cell(cell_ref)
|
|
5443
5655
|
m = cell_ref.match(/\A([A-Z]+)(\d+)\z/)
|
|
5444
5656
|
raise ArgumentError, "invalid cell reference: #{cell_ref}" unless m
|