Skip to content

Commit 2832fb1

Browse files
committed
Docs
1 parent bd2545a commit 2832fb1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/spreadsheet_exporter/xlsx.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def self.from_spreadsheet(spreadsheet, options = {})
3636
worksheet.write_row(row + 1, 0, Array(values))
3737
end
3838

39-
data_sources = add_data_sources(workbook, header_format, options)
39+
data_sources = add_data_sources(workbook, header_format, options.fetch("data_sources", {}) || {})
4040
pp data_sources
4141
add_worksheet_validation(workbook, worksheet, column_indexes, data_sources, header_format, options)
4242

@@ -52,8 +52,20 @@ def self.sanitize_defined_name(raw)
5252
raw.gsub(/[^A-Za-z0-9_]/, "_")
5353
end
5454

55-
def self.add_data_sources(workbook, header_format, options = {})
56-
data_sources = options.fetch("data_sources", {}) || {}
55+
# Write each data_source to the `data` worksheet and reference it with a named range
56+
#
57+
# `data_sources` is a hash in the format
58+
#
59+
# { 'data_source_id' => ['data', 'source', 'options'] }
60+
#
61+
# For data sources dependent on the value in another column, the format is
62+
#
63+
# { 'data_source_id' => {
64+
# 'other_col_val_1' => ['options', 'when', 'val is 1'],
65+
# 'other_col_val_2' => ['options', 'when', 'val is 2']
66+
# }
67+
# }
68+
def self.add_data_sources(workbook, header_format, data_sources)
5769
return {} if data_sources.empty?
5870

5971
unless (data_sheet = workbook.worksheet_by_name(DATA_WORKSHEET_NAME))

0 commit comments

Comments
 (0)