Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support data validation where source is within same sheet or reference to other sheet #131

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ sheet1 = Sheet.with_name("First")
|> Sheet.set_cell("A2", "cat")
|> Sheet.set_cell("A3", "cow")
|> Sheet.add_data_validations("A1", "A10", ["dog", "cat", "cow"])
# within same sheet
|> Sheet.add_data_validations("A1", "A10", "=$A$2:$A$16")
# reference to other sheet "=#{sheet.name}!$A$2:$A$16"
|> Sheet.add_data_validations("A1", "A10", "=sheet2!$A$2:$A$16")

workbook = %Workbook{sheets: [sheet1]}

Expand Down
2 changes: 1 addition & 1 deletion lib/elixlsx/sheet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Elixlsx.Sheet do
merge_cells: [{String.t(), String.t()}],
pane_freeze: {number, number} | nil,
show_grid_lines: boolean(),
data_validations: list({String.t(), String.t(), list(String.t())})
data_validations: list({String.t(), String.t(), list(String.t()) | String.t()})
}
@type rowcol_group :: Range.t() | {Range.t(), opts :: keyword}

Expand Down
10 changes: 10 additions & 0 deletions lib/elixlsx/xml_templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ defmodule Elixlsx.XMLTemplates do
"""
end

defp make_data_validation({start_cell, end_cell, values}) when is_bitstring(values) do
"""
<dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="#{start_cell}:#{
end_cell
}">
<formula1>#{values}</formula1>
</dataValidation>
"""
end

defp make_data_validation({start_cell, end_cell, values}) do
joined_values =
values
Expand Down