IE下载xls乱码问题

This commit is contained in:
guange 2015-10-27 12:04:52 +08:00
parent 7c34927b3a
commit 9303dfd5ae
7 changed files with 14 additions and 17 deletions

View File

@ -290,14 +290,11 @@ class CoursesController < ApplicationController
def export_course_member_excel
@all_members = student_homework_score(0,0,0,"desc")
filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}";
# 如果是ie 需要转码
if(/trident/.match(request.env["HTTP_USER_AGENT"]) != nil)
filename= URI::encode(filename)
end
respond_to do |format|
format.xls {
send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present",
:filename => "#{filename}.xls")
:filename => filename_for_content_disposition("#{filename}.xls"))
}
end
end

View File

@ -42,8 +42,8 @@ class GanttsController < ApplicationController
respond_to do |format|
format.html { render :action => "show", :layout => 'base_projects' }#by young
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
format.pdf { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => filename_for_content_disposition("#{basename}.png")) } if @gantt.respond_to?('to_image')
format.pdf { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{basename}.pdf") ) }
end
end
end

View File

@ -33,7 +33,7 @@ class HomeworkAttachController < ApplicationController
format.js
format.xls {
send_data(homework_to_xls(@all_homework_list), :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}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_not_rated)}).xls")
:filename => filename_for_content_disposition("#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_not_rated)}).xls") )
}
end
end
@ -66,7 +66,7 @@ class HomeworkAttachController < ApplicationController
format.js
format.xls {
send_data(homework_to_xls(all_homework_list), :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}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_been_rated)}).xls")
:filename => filename_for_content_disposition("#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_been_rated)}).xls") )
}
end
end
@ -101,7 +101,7 @@ class HomeworkAttachController < ApplicationController
format.js
format.xls {
send_data(homework_to_xls(all_homework_list), :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}_#{@bid.name}#{l(:excel_homework_list)}.xls")
:filename => filename_for_content_disposition("#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}.xls") )
}
end
end

View File

@ -151,7 +151,7 @@ class IssuesController < ApplicationController
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
format.pdf {
pdf = issue_to_pdf(@issue, :journals => @journals)
send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
send_data(pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}-#{@issue.id}.pdf") )
}
end
end

View File

@ -413,7 +413,7 @@ class PollController < ApplicationController
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")
:filename => filename_for_content_disposition("#{@poll.polls_name}.xls") )
}
end
end

View File

@ -84,7 +84,7 @@ class StoresController < ApplicationController
respond_to do |format|
format.xls {
send_data(homework_to_xls(attachments), :type => "text/excel;charset=utf-8; header=present",
:filename => "#{l(:label_file_lost_list)}.xls")
:filename => filename_for_content_disposition("#{l(:label_file_lost_list)}.xls") )
}
end
end

View File

@ -82,14 +82,14 @@ class WikiController < ApplicationController
@content = @page.content_for_version(params[:version])
if User.current.allowed_to?(:export_wiki_pages, @project)
if params[:format] == 'pdf'
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => filename_for_content_disposition("#{@page.title}.pdf") )
return
elsif params[:format] == 'html'
export = render_to_string :action => 'export', :layout => false
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
send_data(export, :type => 'text/html', :filename => filename_for_content_disposition("#{@page.title}.html"))
return
elsif params[:format] == 'txt'
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
send_data(@content.text, :type => 'text/plain', :filename => filename_for_content_disposition("#{@page.title}.txt") )
return
end
end
@ -286,7 +286,7 @@ class WikiController < ApplicationController
send_data(export, :type => 'text/html', :filename => "wiki.html")
}
format.pdf {
send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf")
send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}.pdf") )
}
end
end