universal_table/app/views/utable_export/export.xlsx.axlsx

111 lines
3.4 KiB
Plaintext
Raw Normal View History

2017-04-13 10:50:32 +00:00
# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "Structure") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
type = sheet.styles.add_style(:i => true)
2024-07-21 07:26:48 +00:00
wrap = sheet.styles.add_style alignment: {wrap_text: true}
2017-04-13 10:50:32 +00:00
row = []
row1 = []
row2 = []
table.table_columns.asc(:order).each do |column|
case column.type
when "text"
site_in_use_locales.sort.each do |locale|
row << column.title + " - " + t(locale.to_s)
row1 << column.key
row2 << column.type + "-#{locale}"
end
2022-02-25 06:49:00 +00:00
when "integer"
row << column.title
row1 << column.key
row2 << column.type
2017-04-13 10:50:32 +00:00
when "editor"
site_in_use_locales.sort.each do |locale|
row << column.title + " - " + t(locale.to_s)
row1 << column.key
row2 << column.type + "-#{locale}"
end
when "image"
row << column.title
row1 << column.key
row2 << "Please leave this column blank. Upload the image manually."
when "date"
row << column.title
row1 << column.key
row2 << column.type + " : " + column.date_format.upcase
when "period"
row << column.title + "-From ~ To"
row1 << column.key
row2 << column.type + " : " + column.date_format.upcase + "-period_from ~ period_to"
2024-07-21 07:26:48 +00:00
when "file"
row << column.title
row1 << column.key
row2 << "Please leave this column blank. Upload the files manually."
2017-04-13 10:50:32 +00:00
end
end
sheet.add_row row, :style => heading
sheet.add_row row1
sheet.add_row row2, :style => type
table.table_entries.asc(:created_at).each do |entry|
row = []
table.table_columns.asc(:order).each do |col|
column = entry.column_entries.where(:table_column_id => col.id).first
case col.type
when "text"
site_in_use_locales.sort.each do |locale|
2017-04-13 12:27:07 +00:00
row << (column.text_translations[locale.to_s] rescue "")
2017-04-13 10:50:32 +00:00
end
2022-02-25 06:49:00 +00:00
when "integer"
row << column.number
2017-04-13 10:50:32 +00:00
when "editor"
site_in_use_locales.sort.each do |locale|
2017-04-13 12:27:07 +00:00
row << (column.content_translations[locale.to_s] rescue "")
2017-04-13 10:50:32 +00:00
end
when "image"
if !column.image.url.nil?
row << url + column.image.url
else
row << ""
end
when "date"
case col.date_format
when "yyyy/MM/dd hh:mm"
row << (column.date.strftime("%Y/%m/%d %H:%M") rescue "")
when "yyyy/MM/dd"
row << (column.date.strftime("%Y/%m/%d") rescue "")
when "yyyy/MM"
row << (column.date.strftime("%Y/%m/") rescue "")
when "yyyy"
row << (column.date.strftime("%Y") rescue "")
end
when "period"
case col.date_format
when "yyyy/MM/dd hh:mm"
row << (column.period_from.strftime("%Y/%m/%d %H:%M")rescue "") + " ~ " + (column.period_to.strftime("%Y/%m/%d %H:%M") rescue "")
when "yyyy/MM/dd"
row << (column.period_from.strftime("%Y/%m/%d")rescue "") + " ~ " + (column.period_to.strftime("%Y/%m/%d") rescue "")
when "yyyy/MM"
row << (column.period_from.strftime("%Y/%m")rescue "") + " ~ " + (column.period_to.strftime("%Y/%m") rescue "")
when "yyyy"
row << (column.period_from.strftime("%Y")rescue "") + " ~ " + (column.period_to.strftime("%Y") rescue "")
end
2024-07-21 07:26:48 +00:00
when "file"
file_links = []
locale = I18n.locale.to_s
column.column_entry_files.desc(:sort_number).each do |entry_file|
next unless entry_file.choose_lang_display(locale)
file_links << (url + entry_file.get_link)
end
row << file_links.join("\r\n")
2017-04-13 10:50:32 +00:00
end
end
2024-07-21 07:26:48 +00:00
sheet.add_row row, style: wrap
2017-04-13 10:50:32 +00:00
end
end