personal-book/app/views/admin/books/excel_format.xlsx.axlsx

128 lines
2.8 KiB
Plaintext
Raw Normal View History

2015-12-15 10:08:07 +00:00
# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "Books") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
example = sheet.styles.add_style(:i => true)
row = ["user_id"]
row1 = [""]
row2 = [""]
row << "name"
row1 << ""
row2 << ""
row << t("personal_book.book_title") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("personal_book.book_title") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("personal_book.extracted_chapters") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("personal_book.extracted_chapters") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("personal_book.publisher") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("personal_book.publisher") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("personal_book.editor") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("personal_book.editor") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("personal_book.authors") + " - " + t("en")
row1 << "textarea"
row2 << ""
row << t("personal_book.authors") + " - " + t("zh_tw")
row1 << "textarea"
row2 << ""
row << t("personal_book.year")
row1 << "number"
row2 << "Example : 2015 or 2014 or 1987"
row << t("personal_book.language")
row1 << "select"
row2 << "en -> English, zh_tw -> Chinese"
row << t("personal_book.book_paper_type")
row1 << "select"
t = ""
BookType.asc(:created_at).each_with_index do |jl,i|
t = t + "#{i}" + " -> " + jl.title + ", "
end
if BookType.count > 0
t = t + " Example : 0"
else
t = "Leave this field blank"
end
row2 << t
row << t("personal_book.pages")
row1 << "number"
row2 << "Example: 10 or 20 or 100"
row << t("personal_book.author_type")
row1 << "checkbox"
t = ""
BookAuthorType.asc(:created_at).each_with_index do |jl,i|
t = t + "#{i}" + " -> " + jl.title + ", "
end
if BookAuthorType.count > 0
t = t + " Example : 0, if more than one then : 0,1"
else
t = "Leave this field blank"
end
row2 << t
row << t("personal_book.number_of_authors")
row1 << "number"
row2 << "Example: 1 or 2 or 10"
row << t("personal_book.publish_date")
row1 << "date"
row2 << "Format: YYYY/MM/DD, Example: 2015/12/10"
row << t("personal_book.isbn")
row1 << "textfield"
row2 << ""
row << t("personal_book.url")
row1 << "textfield"
row2 << "http://domain.com/path"
row << t("personal_book.keywords")
row1 << "textfield"
row2 << "Example: keyword1,keyword2"
row << t("personal_book.note")
row1 << "textarea"
row2 << ""
sheet.add_row row, :style => heading
sheet.add_row row1
sheet.add_row row2, :style => example
User.where(:user_name.ne => "rulingcom").each do |user|
r = [user.user_name]
r << user.name
sheet.add_row r
end
end