diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b04334ee0..f291c7d5c 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -803,6 +803,18 @@ end end end + # 导出excel + def export_excel + @course = params[:course] + respond_to do |format| + format.xls { + @course = @course.reorder("#{Tracker.table_name}.position, #{Course.table_name}.id").all + filename = "#{l(:label_course_list_xls)}.xls" + send_data(course_list_xls(@course), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) + } + end + end + # 0 全部;1 活动的; 2 已注册; 3 锁定 def users @menu_type @@ -1336,4 +1348,32 @@ end render_404 end + def course_list_xls course + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "course" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + sheet1.row(0).concat([l(:issue_xls_id),l(:issue_xls_tracker_id),l(:issue_xls_title),l(:issue_xls_description),l(:issue_xls_status),l(:issue_xls_assign),l(:issue_xls_priority),l(:issue_xls_author),l(:issue_xls_created_at),l(:milestone),l(:issue_xls_start),l(:issue_xls_due),l(:issue_xls_ratio)]) + count_row = 1 + issues.each do |issue| + sheet1[count_row,0] = issue.id + sheet1[count_row,1] = issue_tracker_change(issue.tracker_id) + sheet1[count_row,2] = issue.subject + sheet1[count_row,3] = (issue.description.gsub(/<\/?.*?>/,"")).html_safe + sheet1[count_row,4] = issue_status_change(issue.status_id) + sheet1[count_row,5] = issue.assigned_to.try(:show_name) + sheet1[count_row,6] = issue_priority_change(issue.priority_id) + sheet1[count_row,7] = issue.author.show_name + sheet1[count_row,8] = issue.created_on.nil? ? issue.created_on : issue.created_on.strftime('%Y-%m-%d %H:%M:%S') + sheet1[count_row,9] = issue.fixed_version.try(:name) + sheet1[count_row,10] = issue.start_date.nil? ? issue.start_date : issue.start_date.strftime('%Y-%m-%d') + sheet1[count_row,11] = issue.due_date.nil? ? issue.due_date : issue.due_date.strftime('%Y-%m-%d') + sheet1[count_row,12] = issue_ratio_change(issue.done_ratio, issue.status_id) + count_row += 1 + end + book.write xls_report + xls_report.string + end + end diff --git a/app/views/managements/classroom_classment.html.erb b/app/views/managements/classroom_classment.html.erb index cff28197a..764f8f7ac 100644 --- a/app/views/managements/classroom_classment.html.erb +++ b/app/views/managements/classroom_classment.html.erb @@ -31,6 +31,7 @@ <% end %> + <%#= link_to "导出Excel", export_excel_managements_path(:format => "xls"), :class => "task-btn task-btn-blue ml5 mt3 fr mb5 mr30" %> <% end %>