olympiamanagement/app/views/olympiamanagements/_school_code.xlsx.axlsx

27 lines
1.0 KiB
Plaintext
Raw Normal View History

2020-01-31 14:56:46 +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" ]
2020-01-31 14:56:46 +00:00
@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] rescue '')
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}
export_data_rows.each do |infos_row|
2020-03-10 11:37:47 +00:00
sheet.add_row infos_row , :style=> column , :types => :string
2020-01-31 14:56:46 +00:00
end
end