# 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] 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| sheet.add_row infos_row , :style=> column end end