survey/app/views/survey_export/export.xlsx.axlsx

37 lines
1009 B
Plaintext

# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "WorkSheet1") 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}. #{question.title} - #{option.name}"
end
elsif question.type == 5
question.survey_question_options.each do |option|
question.survey_question_radiogroups.each do |radiogroup|
row << "#{i+1}. #{question.title} - #{option.name} - #{radiogroup.name}"
end
end
else
row << "#{i+1}. #{question.title}"
end
if question.custom_option_new_option
row << "#{i+1}. #{question.title} - #{t('survey_question.use_custom_option')}"
end
end
sheet.add_row row
wrap = wb.styles.add_style alignment: {wrap_text: true}
survey_answers.each do |answer|
answer_row = []
sheet.add_row answer.values.flatten, style: wrap
end
end