personal_writing/app/views/admin/writings/download_excel.xlsx.axlsx

43 lines
1.2 KiB
Plaintext

# encoding: utf-8
wb = xlsx_package.workbook
@data.each_with_index do |role,idx|
data = role["data"]
wb.add_worksheet(name: role["name"] + "-" + idx.to_s) do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
row = ["Name",t(:category)]
@site_in_use_locales.each do |locale|
row << t("personal_writing.writing_title") + " - " + t(locale.to_s)
end
@site_in_use_locales.each do |locale|
row << t("personal_writing.other") + " - " + t(locale.to_s)
end
row << t("personal_writing.year")
row << t("personal_writing.month")
row << t("personal_writing.url")
sheet.add_row row, :style => heading
data.each do |proj|
row = [(proj.member_profile_id.class == Array ? proj.member_profile_id.map{|member_id| MemberProfile.find(member_id).name rescue ""} : [proj.member_profile.name])]
row << (proj.category.title rescue "")
@site_in_use_locales.each do |locale|
row << proj.writing_title_translations[locale.to_s]
end
@site_in_use_locales.each do |locale|
row << proj.other_translations[locale.to_s]
end
row << proj.year
row << proj.month
row << proj.url
sheet.add_row row
end
end
end