# encoding: utf-8 wb = xlsx_package.workbook wb.add_worksheet(name: remove_illegal_utf8(survey.title[0..15])) do |sheet| row = [] survey_questions.each_with_index do |question, i| if question.type == 2 or question.type == 3 or question.type == 4 question.survey_question_options.each do |option| row << "#{i+1}. #{remove_illegal_utf8 question.title} - #{remove_illegal_utf8 option.name}" end elsif question.type == 5 question.survey_question_options.each do |option| question.survey_question_radiogroups.each do |radiogroup| row << "#{i+1}. #{remove_illegal_utf8 question.title} - #{remove_illegal_utf8 option.name} - #{remove_illegal_utf8 radiogroup.name}" end end else row << "#{i+1}. #{remove_illegal_utf8 question.title}" end if question.custom_option row << "#{i+1}. #{remove_illegal_utf8 question.title} - #{t('survey_question.use_custom_option')}" end end sheet.add_row row survey_answers.each do |answer| answer_row = [] survey_questions.each do |question| options = question.survey_question_options.collect{|o| o.name } if question.type == 2 or question.type == 4 options.collect do |o| if !answer[question.id.to_s].blank? && answer[question.id.to_s].include?(o) answer_row << '1' else answer_row << '' end end elsif question.type == 3 options.collect do |o| if !answer[question.id.to_s].blank? && answer[question.id.to_s].include?(o) answer_row << '1' else answer_row << '' end end elsif question.type == 5 question.survey_question_options.each do |option| question.survey_question_radiogroups.each do |radiogroup| if !answer[question.id.to_s].blank? && answer[question.id.to_s][option.id.to_s] == radiogroup.name answer_row << '1' else answer_row << '' end end end else if answer[question.id.to_s] answer_row << remove_illegal_utf8(answer[question.id.to_s]) else answer_row << '' end end if question.custom_option if !answer[question.id.to_s].blank? if answer[question.id.to_s].class == Array answer_row << remove_illegal_utf8((answer[question.id.to_s] - options).join) elsif answer[question.id.to_s].class == String answer_row << remove_illegal_utf8(([answer[question.id.to_s]] - options).join) end else answer_row << '' end end end sheet.add_row answer_row end end