olympiamanagement/app/views/admin/olympiamanagements/_school_export.xlsx.axlsx

27 lines
1.2 KiB
Plaintext
Raw Normal View History

2020-01-31 10:52:53 +00:00
# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "school_class") do |sheet|
row = []
title = sheet.styles.add_style(:bg_color => "FFFF00",:border=>{ :style => :thin, :color => "666666" },:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true})
column = sheet.styles.add_style(:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true},:border=>{ :style => :thin, :color => "666666" })
@fields = [ "school_code", "school_name" , "school_address" ,"class_number","enrollment_limited","school_contact_person_name","department_job_title","office_tel_number","fax","mobile_number","email","enrollment"]
@fields.each do |field|
row << t('olympiamanagement.'+field)
end
#export data start
export_data_rows = []
@OlympiaSchoolDataFields.each do |school_data_field|
temp_row = []
@fields.each do |field_key|
temp_row << (school_data_field[field_key].to_s rescue '')
2020-01-31 10:52:53 +00:00
end
export_data_rows << temp_row
end
#export data end
sheet.add_row row , :style=> title,:widths => row.map{|cell| (cell.length* 11/ 2).round} , :types => :string
2020-01-31 10:52:53 +00:00
export_data_rows.each do |infos_row|
sheet.add_row infos_row , :style=> column , :types => :string
2020-01-31 10:52:53 +00:00
end
end