Class: Axlsx::DataValidation
- Inherits:
-
Object
- Object
- Axlsx::DataValidation
- Defined in:
- lib/axlsx/workbook/worksheet/data_validation.rb
Overview
The recommended way to manage data validations is via Worksheet#add_data_validation
Data validation allows the validation of cell data
Constant Summary collapse
- CHILD_ELEMENTS =
instance values that must be serialized as their own elements - e.g. not attributes.
[:formula1, :formula2]
Instance Attribute Summary collapse
-
#allowBlank ⇒ Boolean
Allow Blank A boolean value indicating whether the data validation allows the use of empty or blank entries.
-
#error ⇒ String
Error Message Message text of error alert.
-
#errorStyle ⇒ Symbol
Error Style (ST_DataValidationErrorStyle) The style of error alert used for this data validation.
-
#errorTitle ⇒ String
Error Title Title bar text of error alert.
-
#formula1 ⇒ String
Formula1 Available for type whole, decimal, date, time, textLength, list, custom default nil.
-
#formula2 ⇒ String
Formula2 Available for type whole, decimal, date, time, textLength default nil.
-
#operator ⇒ Symbol
Operator (ST_DataValidationOperator) The relational operator used with this data validation.
-
#prompt ⇒ String
Input prompt Message text of input prompt.
-
#promptTitle ⇒ String
Prompt title Title bar text of input prompt.
-
#showDropDown ⇒ Boolean
Show drop down A boolean value indicating whether to display a dropdown combo box for a list type data validation.
-
#showErrorMessage ⇒ Boolean
Show error message A boolean value indicating whether to display the error alert message when an invalid value has been entered, according to the criteria specified.
-
#showInputMessage ⇒ Boolean
Show input message A boolean value indicating whether to display the input prompt message.
-
#sqref ⇒ String
Range over which data validation is applied, in "A1:B2" format Available for type whole, decimal, date, time, textLength, list, custom default nil.
-
#type ⇒ Symbol
The type (ST_DataValidationType) of data validation.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DataValidation
constructor
Creates a new DataValidation object.
-
#to_xml_string(str = '') ⇒ String
Serializes the data validation.
Constructor Details
#initialize(options = {}) ⇒ DataValidation
Creates a new Axlsx::DataValidation object
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 158 def initialize(={}) # defaults @formula1 = @formula2 = @error = @errorTitle = @operator = @prompt = @promptTitle = @sqref = nil @allowBlank = @showErrorMessage = true @showDropDown = @showInputMessage = false @type = :none @errorStyle = :stop .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end end |
Instance Attribute Details
#allowBlank ⇒ Boolean
Allow Blank A boolean value indicating whether the data validation allows the use of empty or blank entries. 1 means empty entries are OK and do not violate the validation constraints. Available for type whole, decimal, date, time, textLength, list, custom default true
33 34 35 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 33 def allowBlank @allowBlank end |
#error ⇒ String
Error Message Message text of error alert. Available for type whole, decimal, date, time, textLength, list, custom default nil
41 42 43 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 41 def error @error end |
#errorStyle ⇒ Symbol
Error Style (ST_DataValidationErrorStyle) The style of error alert used for this data validation. Options are:
- information: This data validation error style uses an information icon in the error alert.
- stop: This data validation error style uses a stop icon in the error alert.
- warning: This data validation error style uses a warning icon in the error alert. Available for type whole, decimal, date, time, textLength, list, custom default :stop
53 54 55 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 53 def errorStyle @errorStyle end |
#errorTitle ⇒ String
Error Title Title bar text of error alert. Available for type whole, decimal, date, time, textLength, list, custom default nil
61 62 63 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 61 def errorTitle @errorTitle end |
#formula1 ⇒ String
Formula1 Available for type whole, decimal, date, time, textLength, list, custom default nil
17 18 19 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 17 def formula1 @formula1 end |
#formula2 ⇒ String
Formula2 Available for type whole, decimal, date, time, textLength default nil
24 25 26 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 24 def formula2 @formula2 end |
#operator ⇒ Symbol
Operator (ST_DataValidationOperator) The relational operator used with this data validation. Options are:
- between: Data validation which checks if a value is between two other values.
- equal: Data validation which checks if a value is equal to a specified value.
- greater_than: Data validation which checks if a value is greater than a specified value.
- greater_than_or_equal: Data validation which checks if a value is greater than or equal to a specified value.
- less_than: Data validation which checks if a value is less than a specified value.
- less_than_or_equal: Data validation which checks if a value is less than or equal to a specified value.
- not_between: Data validation which checks if a value is not between two other values.
- not_equal: Data validation which checks if a value is not equal to a specified value. Available for type whole, decimal, date, time, textLength default nil
78 79 80 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 78 def operator @operator end |
#prompt ⇒ String
Input prompt Message text of input prompt. Available for type whole, decimal, date, time, textLength, list, custom default nil
86 87 88 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 86 def prompt @prompt end |
#promptTitle ⇒ String
Prompt title Title bar text of input prompt. Available for type whole, decimal, date, time, textLength, list, custom default nil
94 95 96 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 94 def promptTitle @promptTitle end |
#showDropDown ⇒ Boolean
Show drop down A boolean value indicating whether to display a dropdown combo box for a list type data validation. Be careful: false shows the dropdown list! Available for type list default false
103 104 105 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 103 def showDropDown @showDropDown end |
#showErrorMessage ⇒ Boolean
Show error message A boolean value indicating whether to display the error alert message when an invalid value has been entered, according to the criteria specified. Available for type whole, decimal, date, time, textLength, list, custom default false
112 113 114 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 112 def showErrorMessage @showErrorMessage end |
#showInputMessage ⇒ Boolean
Show input message A boolean value indicating whether to display the input prompt message. Available for type whole, decimal, date, time, textLength, list, custom default false
120 121 122 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 120 def showInputMessage @showInputMessage end |
#sqref ⇒ String
Range over which data validation is applied, in "A1:B2" format Available for type whole, decimal, date, time, textLength, list, custom default nil
127 128 129 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 127 def sqref @sqref end |
#type ⇒ Symbol
The type (ST_DataValidationType) of data validation. Options are:
- custom: Data validation which uses a custom formula to check the cell value.
- date: Data validation which checks for date values satisfying the given condition.
- decimal: Data validation which checks for decimal values satisfying the given condition.
- list: Data validation which checks for a value matching one of list of values.
- none: No data validation.
- textLength: Data validation which checks for text values, whose length satisfies the given condition.
- time: Data validation which checks for time values satisfying the given condition.
- whole: Data validation which checks for whole number values satisfying the given condition. default none
141 142 143 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 141 def type @type end |
Instance Method Details
#to_xml_string(str = '') ⇒ String
Serializes the data validation
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/axlsx/workbook/worksheet/data_validation.rb', line 216 def to_xml_string(str = '') valid_attributes = get_valid_attributes str << '<dataValidation ' str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' if (valid_attributes.include?(key.to_sym) and not CHILD_ELEMENTS.include?(key.to_sym)) }.join(' ') str << '>' str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1) str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2) str << '</dataValidation>' end |