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|
|
|
|
|
row = [I18n.t("survey.taken_by")]
|
|
|
|
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
|
|
|
|
|