2017-04-11 06:10:01 +00:00
|
|
|
# encoding: utf-8
|
2021-09-12 12:20:03 +00:00
|
|
|
require 'axlsx'
|
2017-04-11 06:10:01 +00:00
|
|
|
wb = xlsx_package.workbook
|
2021-09-12 12:20:03 +00:00
|
|
|
title = survey.title
|
|
|
|
title = "WorkSheet1" if title.blank?
|
|
|
|
wb.add_worksheet(name: title) do |sheet|
|
2021-11-09 14:48:29 +00:00
|
|
|
row = [I18n.t("survey.taken_by"), I18n.t("survey.taken_date")]
|
2021-11-08 11:36:29 +00:00
|
|
|
row2 = ["", ""]
|
2021-11-09 14:48:29 +00:00
|
|
|
if survey.enable_consent_feature
|
|
|
|
row << survey.consent_contents
|
|
|
|
row2 << ""
|
|
|
|
end
|
2021-11-14 04:59:03 +00:00
|
|
|
row << I18n.t("survey.type.0")
|
|
|
|
row2 << ""
|
2017-04-11 06:10:01 +00:00
|
|
|
survey_questions.each_with_index do |question, i|
|
2021-09-12 12:20:03 +00:00
|
|
|
qnum = question.title.match(/^\d+./).nil? ? "#{i+1}. " : ""
|
|
|
|
start_col = row2.count
|
|
|
|
if question.type == 2 or question.type == 3 or question.type == 4
|
|
|
|
col_size = question.survey_question_options.count - 1
|
|
|
|
sheet.merge_cells "#{Axlsx::cell_r(start_col,0)}:#{Axlsx::cell_r(start_col+col_size,0)}"
|
2017-04-11 06:10:01 +00:00
|
|
|
question.survey_question_options.each do |option|
|
2021-09-12 12:20:03 +00:00
|
|
|
row << "#{qnum}#{question.title}"
|
|
|
|
row2 << "#{option.name}"
|
2017-04-11 06:10:01 +00:00
|
|
|
end
|
|
|
|
elsif question.type == 5
|
2021-09-12 12:20:03 +00:00
|
|
|
col_size = question.survey_question_options.count * question.survey_question_radiogroups.count - 1
|
|
|
|
sheet.merge_cells "#{Axlsx::cell_r(start_col,0)}:#{Axlsx::cell_r(start_col+col_size,0)}"
|
2017-04-11 06:10:01 +00:00
|
|
|
question.survey_question_options.each do |option|
|
|
|
|
question.survey_question_radiogroups.each do |radiogroup|
|
2021-09-12 12:20:03 +00:00
|
|
|
row << "#{qnum}#{question.title}"
|
|
|
|
row2 << "#{option.name} - #{radiogroup.name}"
|
2017-04-11 06:10:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2021-09-12 12:20:03 +00:00
|
|
|
row << "#{qnum}#{question.title}"
|
|
|
|
row2 << ""
|
2017-04-11 06:10:01 +00:00
|
|
|
end
|
2021-07-08 13:31:27 +00:00
|
|
|
if question.custom_option_new_option
|
2021-09-12 12:20:03 +00:00
|
|
|
row << "#{qnum}#{question.title}"
|
|
|
|
row2 << "#{t('survey_question.use_custom_option')}"
|
2017-04-11 06:10:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sheet.add_row row
|
2021-09-12 12:20:03 +00:00
|
|
|
sheet.add_row row2
|
2021-07-08 13:31:27 +00:00
|
|
|
wrap = wb.styles.add_style alignment: {wrap_text: true}
|
2017-04-11 06:10:01 +00:00
|
|
|
survey_answers.each do |answer|
|
|
|
|
answer_row = []
|
|
|
|
|
2021-07-08 13:31:27 +00:00
|
|
|
sheet.add_row answer.values.flatten, style: wrap
|
2017-04-11 06:10:01 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|