wb = xlsx_package.workbook
wb.use_shared_strings = true
wb.styles do |s|
  no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center }
  sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
  row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center }
  blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center}

  #课堂信息摘要
  wb.add_worksheet(name:course_info[0]) do |sheet|
    sheet.sheet_view.show_grid_lines = false
    course_main_info = course_info[1]
    course_group_info = course_info[2]
    group_info_d = course_group_info[0]
    group_info_detail = course_group_info[1]
    course_main_info.each do |c|
      sheet.add_row c, :style => sz_all  #用户id
    end
    sheet["A1:A7"].each { |c| c.style = row_cell }
    sheet.add_row [],:style => sz_all
    if group_info_detail.count > 0
      sheet.add_row group_info_d, :style => blue_cell
      group_info_detail.each do |group|
        sheet.add_row group, :style => sz_all  #用户id
      end
      sheet.column_info.second.width = 40
    end
  end  #add_worksheet

  #课堂活跃度统计
  wb.add_worksheet(name:activity_level[0]) do |sheet|
    sheet.sheet_view.show_grid_lines = false
    sheet_title = activity_level[1]
    sheet_content = activity_level[2]
    sheet.add_row sheet_title, :height => 25,:style => blue_cell
    if sheet_content.count > 0
      sheet_content.each_with_index do |c,index|
        c_1 = (index+1)
        c_2 = [c_1] + c.values
        sheet.add_row c_2, :height => 25, :style => sz_all  #用户id
      end
      sheet.column_widths *([20]*sheet.column_info.count)
      sheet.column_info.first.width = 8
    end
  end  #add_worksheet

  #学生总成绩
  wb.add_worksheet(name:course_scores[0]) do |sheet|
    sheet.sheet_view.show_grid_lines = false
    sheet_title = course_scores[1]  #头部标题
    sheet_title_counts = course_scores[2]   #总成绩的作业数（包含每一项的总得分）如实训作业的作业数+总成绩
    sheet_content = course_scores[3]
    sheet_length = sheet_title.count
    sheet.add_row [""]*sheet_length, :style => blue_cell
    sheet.add_row [""]*sheet_length, :style => blue_cell
    sheet.merge_cells("A1:A2")
    sheet.merge_cells("B1:B2")
    sheet.merge_cells("C1:C2")
    sheet.merge_cells("D1:D2")
    sheet.merge_cells("E1:E2")
    sheet.merge_cells("F1:F2")
    sheet.merge_cells("G1:G2")
    sheet.merge_cells (Axlsx::cell_r(sheet_length-1,0) + ':' + Axlsx::cell_r(sheet_length-1,1))   #最后一行的合并
    sheet_first = sheet.rows.first  #第一行
    sheet_second = sheet.rows.second  #第二行
    work_head_title = %w(实训作业 普通作业 分组作业 毕设任务 试卷)
    (0..(sheet_length-1)).each do |i|
      if i <= 6 || i == sheet_length-1
        sheet_first.cells[i].value = sheet_title[i]
      else
        sheet_second.cells[i].value = sheet_title[i]
      end
    end
    st_col = 7
    sheet_title_counts.each_with_index do |c,index|
      end_col = (st_col + c - 1)
      sheet.merge_cells sheet_first.cells[(st_col..end_col)]
      sheet_first.cells[st_col].value = work_head_title[index.to_i]
      st_col = end_col + 1
    end

    if sheet_content.count > 0
      sheet_content.each_with_index do |c,index|
        c_1 = (index+1)
        c_2 = [c_1] + c
        sheet.add_row c_2, :height => 25,:style => sz_all  #用户id
      end
    end
    sheet.column_widths *([15]*sheet.column_info.count)
    sheet.column_info.first.width = 8
    sheet.rows[1].height = 40
  end  #add_worksheet

  #实训作业
  if shixun_works.count > 0
    shixun_works.each do |shixun|
      wb.add_worksheet(name:shixun[0]) do |sheet|
        head_title = shixun[1]
        content_shixun = shixun[2]
        sheet.sheet_view.show_grid_lines = false
        sheet.add_row head_title, :style => blue_cell
        if content_shixun.count > 0
          content_shixun.each do |user|
            sheet.add_row user, :height => 25,:style => sz_all
          end  #each_widh_index
        end
        sheet.column_widths *([20]*sheet.column_info.count)
        sheet.column_info.first.width = 12
      end #add_worksheet
    end
  end

  #普通作业
  if common_works.count > 0
    common_works.each do |work|
      wb.add_worksheet(name:work[0]) do |sheet|
        head_title = work[1]
        content_ = work[2]
        sheet.sheet_view.show_grid_lines = false
        sheet.add_row head_title, :style => blue_cell
        if content_.count > 0
          content_.each do |user|
            sheet.add_row user, :height => 25,:style => no_wrap_sz
          end  #each_widh_index
        end
        sheet.column_widths *([20]*sheet.column_info.count)
        sheet.column_info.first.width = 12
      end #add_worksheet
    end
  end

  #分组作业
  if group_works.count > 0
    group_works.each do |work|
      wb.add_worksheet(name:work[0]) do |sheet|
        head_title = work[1]
        content_ = work[2]
        sheet.sheet_view.show_grid_lines = false
        sheet.add_row head_title, :style => blue_cell
        if content_.count > 0
          content_.each do |user|
            sheet.add_row user, :height => 25,:style => sz_all
          end  #each_widh_index
        end
        sheet.column_widths *([20]*sheet.column_info.count)
        sheet.column_info.first.width = 12
      end #add_worksheet
    end
  end

  #毕设任务
  if task_works.count > 0
    task_works.each do |task|
      wb.add_worksheet(name:task[0]) do |sheet|
        sheet.sheet_view.show_grid_lines = false
        content_ = task[2]
        sheet.add_row task[1], :style => blue_cell
        content_.each do |user|
          sheet.add_row user, :height => 25,:style => sz_all
        end  #each_widh_index
        sheet.column_widths *([20]*sheet.column_info.count)
        sheet.column_info.first.width = 12
      end  #add_worksheet
    end
  end

  #试卷
  if exercise_works.count > 0
    exercise_works.each do |ex|
      wb.add_worksheet(name: ex[0]) do |sheet|
        sheet.sheet_view.show_grid_lines = false
        content_ = ex[2]
        sheet.add_row ex[1], :style => blue_cell
        content_.each do |user|
          sheet.add_row user, :height => 25,:style => sz_all  #用户id
        end  #each_widh_index
        sheet.column_widths *([20]*sheet.column_info.count)
        sheet.column_info.first.width = 12
      end  #add_worksheet
    end
  end
end
