course_evaluation = @course_evaluation

wb = xlsx_package.workbook
wb.styles do |style|
  base_style_attr = {
    sz: 11, height: 16, alignment: { horizontal: :center },
    border: { style: :thin, color: '000000' }
  }
  bg_style = style.add_style(base_style_attr.merge(bg_color: '90EE90'))
  normal_style = style.add_style(base_style_attr)

  wb.add_worksheet(name: "#{course_evaluation.name}成绩导入模板") do |sheet|
    name       = course_evaluation.name
    items_size = course_evaluation.ec_course_evaluation_subitems.count

    sheet.add_row name, style: bg_style
    sheet.merge_cells wb.rows.first.cells[(1..(items_size * course_evaluation.evaluation_count))]

    data       = []
    item_names = course_evaluation.ec_course_evaluation_subitems.pluck(:name)
    course_evaluation.evaluation_count.times do |times|
      data += item_names.map { |str| "#{name}#{times + 1}#{str}" }
    end
    sheet.add_row data, style: bg_style

    sheet.add_row [''] * (items_size * course_evaluation.evaluation_count), style: normal_style
  end
end