0

I am using RubyXL gem to read and write a xlsm file.In my project there is a field Country which should diplay all list of countries in a dropdown in xlsm.I have tried with DataValidation but when I tried to open the file it is showing as 'We found a problem with some content in filename.xlsm.Do you want to try us to revcover as much as we can?' and if I clicked 'yes'it is not showing dropdown list on that cell.My code is given below.

workbook = RubyXL::Parser.parse(dest_file_path)
worksheet1 = workbook["Form"]
content = ['Afghanistan','Albania,'Algeria']
formula = RubyXL::Formula.new(expression: content)
loc = RubyXL::Reference.new(1, 1048000, 2, 2)
worksheet1.data_validations = 
RubyXL::DataValidation.new(prompt_title: nil, prompt: nil,
sqref: loc, formula1: formula,
type: 'list', show_input_message: true,
show_drop_down: true)

How should I associate DataValidation to a specific worksheet ? Is there any other way I can do this? Could anyone please help.

1 Answers1

0

RubyXL Data Validations are collection, wrapping your Data Validation in brackets should add appropriately add the data validations to worksheet1

workbook = RubyXL::Parser.parse(dest_file_path)
worksheet1 = workbook["Form"]
content = ['Afghanistan','Albania,'Algeria']
formula = RubyXL::Formula.new(expression: content)
loc = RubyXL::Reference.new(1, 1048000, 2, 2)
worksheet1.data_validations = [
RubyXL::DataValidation.new(prompt_title: nil, prompt: nil,
sqref: loc, formula1: formula,
type: 'list', show_input_message: true,
show_drop_down: true)]
drthvdr
  • 95
  • 5