我创建了2个按钮,允许用户将PDF表下载为TXT或Excel。我的Rails应用程序生成相应的文件。除IE之外,一切正常。我在Win7上测试了IE11。
实例(请参阅底部的按钮):http://en.mycoursewalk.com/course_walk/distance_table/3575
HTML代码:
<a href="#" id="Export_Excel" title="Export to Excel" class="ui-btn ui-shadow ui-corner-all"><i class="fa fa-file-excel-o fa-lg"></i> Export to Excel</a>
<script>
var cw_id = <%= @coursewalk.id %>;
$(document).on("pageshow",function(event) {
$("#Export_Excel").click(function(event) {
export_table('xml');
});
});
function export_table(export_format) {
var table = $('#distance_table').tableToJSON();
window.open('/application/export_table/' + cw_id + '.' + export_format + '?table_type=distance_table&export_format=' + export_format + "&_json=" + encodeURIComponent(JSON.stringify(table)), "_self");
}
</script>
控制器:
def export_table
# Code here to create appropriate text or Excel file. Removed for clarity
formatted_data = ''
formatted_data << "test" + "\t" + "test2" + "\n"
i = Iconv.new('UTF-8','iso-8859-1')
formatted_data_utf8 = i.iconv(formatted_data)
send_data formatted_data_utf8, :filename => "test.txt", :type => "text/csv;charset=UTF-8", :disposition => "attachment"
end
在IE Developer Tools和Console中,IE显示&#34; Navigation Occurred&#34;单击“导出”按钮时出现关于DOCTYPE的投诉。单击DOCTYPE警告实际上会将TXT或Excel文件加载到控制台中。
我该如何解决这个问题?
答案 0 :(得分:0)
我通过使用rails模板修复此问题,如此Rail Cast:
中所述http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast