ask/app/views/admin/asks/do_export.xlsx.axlsx

56 lines
1.6 KiB
Plaintext
Raw Normal View History

# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "Ask Question") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
heads = []
fields_with_key_group.each do |cat_id, fields_with_key|
fields_with_key.each do |type, fs|
fs.each do |key, field|
heads << field if !heads.include?(field)
end
end
end
sheet.add_row heads, :style => heading
ask_questions.each do |ask_question|
row = []
row_group = {}
s = ask_category_settings[ask_question.category_id]
fields_with_key_group[ask_question.category_id]['default_values'].each do |key, field|
text = ''
case key
when 'ask_time'
text = ask_question.created_at.strftime('%Y/%m/%d %H:%M')
when 'title','name','mail','phone','appointment'
text = ask_question.send(key).to_s
when 'ask_category_id'
text = categories[ask_question.ask_category_id].title rescue ''
when 'sex'
text = ask_question.sex
if ['male','female'].include? sex.to_s
text = I18n.t("mongoid.attributes.ask_question.#{sex}")
else
text = ''
end
when 'agree_show'
if ask_question.agree_show
text = I18n.t('ask.yes')
else
text = I18n.t('ask.no')
end
end
row_group[field] = text
end
fields_with_key_group[ask_question.category_id]['custom_values'].each do |key, field|
row_group[field] = Admin::AsksHelper.show_on_front(key, s.custom_fields[key], ask_question, true)
end
row = heads.collect do |head|
row_group[head]
end
sheet.add_row row
end
end