personal-research/app/views/admin/researchs/download_excel.xlsx.axlsx

66 lines
1.7 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"]
@site_in_use_locales.each do |locale|
row << t("personal_research.research_title") + " - " + t(locale.to_s)
end
@site_in_use_locales.each do |locale|
row << t("personal_research.extracted_chapters") + " - " + t(locale.to_s)
end
@site_in_use_locales.each do |locale|
row << t("personal_research.authors") + " - " + t(locale.to_s)
end
row << t("personal_research.research_category")
row << t("personal_research.year")
row << t("personal_research.language")
row << t("personal_research.publication_date")
row << t("personal_research.url")
row << t("personal_research.keywords")
row << t("personal_research.note")
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])]
@site_in_use_locales.each do |locale|
row << proj.research_title_translations[locale.to_s]
end
@site_in_use_locales.each do |locale|
row << proj.extracted_chapters_translations[locale.to_s]
end
@site_in_use_locales.each do |locale|
row << proj.authors_translations[locale.to_s]
end
row << proj.research_category.title rescue ""
row << proj.year
row << proj.language
row << proj.publication_date.strftime("%Y-%m-%d") rescue ""
row << proj.url
row << proj.keywords
row << proj.note
sheet.add_row row
end
end
end