导出excel

This commit is contained in:
daiao 2017-09-15 10:39:07 +08:00
parent 05553faf7d
commit 0204232e49
4 changed files with 43 additions and 0 deletions

View File

@ -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

View File

@ -31,6 +31,7 @@
<% end %>
</select>
<input name="sx_order" type="hidden">
<%#= link_to "导出Excel", export_excel_managements_path(:format => "xls"), :class => "task-btn task-btn-blue ml5 mt3 fr mb5 mr30" %>
</div>
<% end %>
<div class="edu-con-bg01 mt15" id="managements_classroom_classment">

View File

@ -202,6 +202,7 @@ zh:
label_issue_new: 新建问题
label_query: 自定义查询
label_issue_list_xls: Issue列表
label_course_list_xls: 课程列表
label_per_week: 每周
label_per_month: 每月
label_per_all: 所有

View File

@ -238,6 +238,7 @@ RedmineApp::Application.routes.draw do
get 'shixun_feedback'
match 'update_user',:via=>[:get,:post]
post 'support_shixuns_search'
match 'export_excel', :via => [:get, :post]
end
end
# Enable Grack support