到处Excel

This commit is contained in:
sw 2015-05-28 11:07:28 +08:00
parent b182feb988
commit e1a3ed4b82
3 changed files with 37 additions and 4 deletions

View File

@ -7,12 +7,16 @@ class StudentWorkController < ApplicationController
before_filter :author_of_work, :only => [:edit, :update, :destroy]
def index
@order,sort,@name = params[:order] || "final_score",params[:sort] || "desc",params[:name] || ""
@stundet_works = search_homework_member @homework.student_works.order("#{@order} #{sort}"),@name
@order,@b_sort,@name = params[:order] || "final_score",params[:sort] || "desc",params[:name] || ""
@stundet_works = search_homework_member @homework.student_works.order("#{@order} #{@b_sort}"),@name
@homework_commons = @course.homework_commons.order("created_at desc")
@score = sort == "desc" ? "asc" : "desc"
@score = @b_sort == "desc" ? "asc" : "desc"
respond_to do |format|
format.html
format.xls {
send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}(#{l(:excel_not_rated)}).xls")
}
end
end
@ -186,4 +190,31 @@ class StudentWorkController < ApplicationController
}
select_homework
end
def homework_to_xls items
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "homework"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
count_row = 1
items.each do |homework|
sheet1[count_row,0]=homework.user.id
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
sheet1[count_row,2] = homework.user.login
sheet1[count_row,3] = homework.user.user_extensions.student_id
sheet1[count_row,4] = homework.user.mail
sheet1[count_row,5] = homework.name
sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
sheet1[count_row,9] = homework.final_score.nil? ? l(:label_without_score) : format("%.2f",homework.final_score)
sheet1[count_row,10] = format_time(homework.created_at)
count_row += 1
end
book.write xls_report
xls_report.string
end
end

View File

@ -45,7 +45,7 @@
remote: true, class: "down_btn fr", :id => "download_homework_attachments" %>
<% end%>
<a class="down_btn fr" href="javascript:void(0);">列表</a>
<%= link_to l(:label_list), student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :format => 'xls'),:class=>'down_btn fr'%>
<span class="mt3 fr " style="color:#136b3b;">导出全部:</span>
</div>
<div class="cl"></div>

View File

@ -1798,7 +1798,9 @@ zh:
excel_mail: 电子邮箱
excel_homework_name: 作品名
excel_t_score: 教师评分
excel_ta_score: 教辅评分
excel_n_score: 匿名评分
excel_f_score: 成绩
excel_commit_time: 提交时间
excel_homework_score: 作业积分
excel_class: "班级:"