You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
588 B
21 lines
588 B
class Admins::ImportItemBankExcel < BaseImportXlsx
|
|
Data = Struct.new(:item_type, :name, :difficulty, :choice_text1, :choice_text2, :choice_text3, :choice_text4, :choice_text5, :answer, :login)
|
|
|
|
def read_each(&block)
|
|
sheet.each_row_streaming(pad_cells: true, offset: 1) do |row|
|
|
data = row.map(&method(:cell_value))[0..9]
|
|
block.call Data.new(*data)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def check_sheet_valid!
|
|
raise_import_error('请按照模板格式导入') if sheet.cell(1, 9).to_s.strip != "答案"
|
|
end
|
|
|
|
def cell_value(obj)
|
|
obj&.cell_value&.to_s&.strip
|
|
end
|
|
end
|