问卷调查结果导出功能
This commit is contained in:
parent
f18367d550
commit
857d3d5f62
|
@ -1,8 +1,8 @@
|
||||||
class PollController < ApplicationController
|
class PollController < ApplicationController
|
||||||
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll]
|
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll,:export_poll]
|
||||||
before_filter :find_container, :only => [:new,:create, :index]
|
before_filter :find_container, :only => [:new,:create, :index]
|
||||||
before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
|
before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
|
||||||
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll]
|
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll]
|
||||||
include PollHelper
|
include PollHelper
|
||||||
def index
|
def index
|
||||||
if @course
|
if @course
|
||||||
|
@ -360,6 +360,17 @@ class PollController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#导出问卷
|
||||||
|
def export_poll
|
||||||
|
poll_questions = @poll.poll_questions
|
||||||
|
respond_to do |format|
|
||||||
|
format.xls {
|
||||||
|
send_data(poll_to_xls(poll_questions), :type => "text/excel;charset=utf-8; header=present",
|
||||||
|
:filename => "#{@poll.polls_name}.xls")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_poll_and_course
|
def find_poll_and_course
|
||||||
@poll = Poll.find params[:id]
|
@poll = Poll.find params[:id]
|
||||||
|
@ -438,4 +449,41 @@ class PollController < ApplicationController
|
||||||
end
|
end
|
||||||
pu
|
pu
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#将poll中题目转换为Excel
|
||||||
|
def poll_to_xls poll_questions
|
||||||
|
xls_report = StringIO.new
|
||||||
|
book = Spreadsheet::Workbook.new
|
||||||
|
sheet1 = book.create_worksheet :name => "poll"
|
||||||
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||||
|
count_row = 0
|
||||||
|
poll_questions.each do |poll_question|
|
||||||
|
if poll_question.question_type == 1 || poll_question.question_type == 2
|
||||||
|
sheet1.row(count_row).default_format = blue
|
||||||
|
sheet1[count_row,0]= l(:label_poll_question_num,:num => poll_question.question_number)
|
||||||
|
sheet1[count_row + 1,0] = l(:label_poll_subtotal)
|
||||||
|
sheet1[count_row + 2,0] = l(:label_poll_proportion)
|
||||||
|
poll_question.poll_answers.each_with_index do |poll_answer,i|
|
||||||
|
sheet1[count_row, i + 1] = poll_answer.answer_text
|
||||||
|
sheet1[count_row + 1, i + 1] = poll_answer.poll_votes.count
|
||||||
|
sheet1[count_row + 2, i + 1] = statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)).to_s + "%"
|
||||||
|
end
|
||||||
|
sheet1[count_row + 3,0] = l(:label_poll_valid_commit)
|
||||||
|
sheet1[count_row + 3,1] = total_answer(poll_question.id)
|
||||||
|
count_row += 5
|
||||||
|
else
|
||||||
|
sheet1.row(count_row).default_format = blue
|
||||||
|
sheet1[count_row,0] = l(:label_poll_question_num,:num => poll_question.question_number)
|
||||||
|
sheet1[count_row,1] = poll_question.question_title
|
||||||
|
count_row += 1
|
||||||
|
poll_question.poll_votes.each do |poll_vote|
|
||||||
|
sheet1[count_row,0] = poll_vote.vote_text
|
||||||
|
count_row += 1
|
||||||
|
end
|
||||||
|
count_row += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
book.write xls_report
|
||||||
|
xls_report.string
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
<%= link_to(l(:button_delete), poll,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %>
|
<%= link_to(l(:button_delete), poll,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %>
|
||||||
|
|
||||||
|
<li><%= link_to "导出", export_poll_poll_path(poll.id,:format => "xls"), :class => "polls_de fr ml5"%></li>
|
||||||
|
|
||||||
<% if poll.polls_status == 1 %>
|
<% if poll.polls_status == 1 %>
|
||||||
<li><%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml5"%></li>
|
<li><%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml5"%></li>
|
||||||
<% else%>
|
<% else%>
|
||||||
|
|
|
@ -1936,6 +1936,7 @@ zh:
|
||||||
label_poll_description: 问卷描述
|
label_poll_description: 问卷描述
|
||||||
label_poll_options: 选项
|
label_poll_options: 选项
|
||||||
label_poll_subtotal: 小计
|
label_poll_subtotal: 小计
|
||||||
|
label_poll_question_num: "第%{num}题"
|
||||||
label_poll_proportion: 比例
|
label_poll_proportion: 比例
|
||||||
label_poll_valid_commit: 本题有效填写人次
|
label_poll_valid_commit: 本题有效填写人次
|
||||||
label_poll_result: 问卷调查_问卷统计
|
label_poll_result: 问卷调查_问卷统计
|
||||||
|
|
|
@ -70,6 +70,7 @@ RedmineApp::Application.routes.draw do
|
||||||
get 'republish_poll'
|
get 'republish_poll'
|
||||||
get 'poll_result'
|
get 'poll_result'
|
||||||
get 'close_poll'
|
get 'close_poll'
|
||||||
|
get 'export_poll'
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
delete 'delete_poll_question'
|
delete 'delete_poll_question'
|
||||||
|
|
Loading…
Reference in New Issue