From b2c5ed169cbce41ed9e304ddcc13e841f465adb0 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Hühne Date: Thu, 24 May 2012 09:38:53 +0200 Subject: Only render possible attributes for the given type. --- lib/axlsx/workbook/worksheet/data_validation.rb | 27 +++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb index 908fdcf6..c2c1cb0e 100644 --- a/lib/axlsx/workbook/worksheet/data_validation.rb +++ b/lib/axlsx/workbook/worksheet/data_validation.rb @@ -181,7 +181,7 @@ module Axlsx def error=(v); Axlsx::validate_string(v); @error = v end # @see errorStyle - def errorStyle=(v); Axlsx::validate_data_validation_errorStyle(v); @errorStyle = v end + def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end # @see errorTitle def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end @@ -214,12 +214,31 @@ module Axlsx # @param [String] str # @return [String] def to_xml_string(str = '') + valid_attributes = get_valid_attributes + str << '' - str << '' << self.formula1 << '' if @formula1 - str << '' << self.formula2 << '' if @formula2 + str << '' << self.formula1 << '' if @formula1 and valid_attributes.include?(:formula1) + str << '' << self.formula2 << '' if @formula2 and valid_attributes.include?(:formula2) str << '' end + + private + def get_valid_attributes + attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type ] + + if [:whole, :decimal, :data, :time, :textLength].include?(@type) + attributes << [:operator, :formula1, :formula2] + elsif @type == :list + attributes << [:showDropDown, :formula1] + elsif @type == :custom + attributes << :formula1 + else + attributes = [] + end + + attributes.flatten! + end end end \ No newline at end of file -- cgit v1.2.3