From cef466486b489ed012b20b5bef341f4cee1d802d Mon Sep 17 00:00:00 2001 From: randym Date: Thu, 15 Feb 2018 13:29:44 +0900 Subject: chore(examples): update data validation example to show raw list validation --- examples/data_validation.rb | 95 ++++++++++++++++++++++++++------------------- examples/example.rb | 1 + 2 files changed, 56 insertions(+), 40 deletions(-) (limited to 'examples') diff --git a/examples/data_validation.rb b/examples/data_validation.rb index 56248ec3..c91b6c43 100644 --- a/examples/data_validation.rb +++ b/examples/data_validation.rb @@ -4,47 +4,62 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'axlsx' p = Axlsx::Package.new -p.workbook.add_worksheet do |ws| - ws.add_data_validation("A10", { - :type => :whole, - :operator => :between, - :formula1 => '5', - :formula2 => '10', - :showErrorMessage => true, - :errorTitle => 'Wrong input', - :error => 'Only values between 5 and 10', - :errorStyle => :information, - :showInputMessage => true, - :promptTitle => 'Be carful!', - :prompt => 'Only values between 5 and 10'}) - - ws.add_data_validation("B10", { - :type => :textLength, - :operator => :greaterThan, - :formula1 => '10', - :showErrorMessage => true, - :errorTitle => 'Text is too long', - :error => 'Max text length is 10 characters', - :errorStyle => :stop, - :showInputMessage => true, - :promptTitle => 'Text length', - :prompt => 'Max text length is 10 characters'}) - - 8.times do |i| - ws.add_row [nil, nil, i*2] +p.workbook.add_worksheet do |ws| + + ws.add_row ["between", "lessThan", "bound list", "raw list"] + + 4.times do |i| + ws.add_row [nil, nil, nil, nil, (i+1) * 2] end - - ws.add_data_validation("C10", { - :type => :list, - :formula1 => 'C1:C8', + + ws.add_data_validation("A2:A5", { + :type => :whole, + :operator => :between, + :formula1 => '5', + :formula2 => '10', + :showErrorMessage => true, + :errorTitle => 'Wrong input', + :error => 'Only values between 5 and 10', + :errorStyle => :information, + :showInputMessage => true, + :promptTitle => 'Be careful!', + :prompt => 'We really want a value between 5 and 10, but it is OK if you want to break the rules.'}) + + ws.add_data_validation("B1:B5", { + :type => :textLength, + :operator => :lessThan, + :formula1 => '10', + :showErrorMessage => true, + :errorTitle => 'Text is too long', + :error => 'Max text length is 10 characters', + :errorStyle => :stop, + :showInputMessage => true, + :promptTitle => 'Text length', + :prompt => 'Max text length is 10 characters'}) + + ws.add_data_validation("C2:C5", { + :type => :list, + :formula1 => 'E2:E5', + :showDropDown => false, + :showErrorMessage => true, + :errorTitle => '', + :error => 'Only values from E2:E5', + :errorStyle => :stop, + :showInputMessage => true, + :promptTitle => '', + :prompt => 'Only values from E2:E5'}) + + ws.add_data_validation("D2:D5", { + :type => :list, + :formula1 => '"Red, Orange, NavyBlue"', :showDropDown => false, - :showErrorMessage => true, - :errorTitle => '', - :error => 'Only values from C1:C8', - :errorStyle => :stop, - :showInputMessage => true, - :promptTitle => '', - :prompt => 'Only values from C1:C8'}) + :showErrorMessage => true, + :errorTitle => '', + :error => 'Please use the dropdown selector to choose the value', + :errorStyle => :stop, + :showInputMessage => true, + :prompt => 'Choose the value from the dropdown'}) + end -p.serialize 'data_validation.xlsx' \ No newline at end of file +p.serialize 'data_validation.xlsx' diff --git a/examples/example.rb b/examples/example.rb index 4d4c2630..92848aed 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -873,3 +873,4 @@ if examples.include? :tab_color p.serialize 'tab_color.xlsx' end ##``` + -- cgit v1.2.3